-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPyDict.cpp
101 lines (78 loc) · 1.49 KB
/
PyDict.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "StdAfx.h"
#undef _DEBUG
#include <Python.h>
#define _DEBUG
#include "PyArray.h"
#include "PyDict.h"
#include "Wraper.h"
CPyDict::CPyDict(void)
{
};
CPyDict::CPyDict(PyObject* pydict)
{
m_pos = 0;
m_pydict = pydict;
Py_INCREF(m_pydict);
};
CPyDict::~CPyDict(void)
{
Py_DECREF(m_pydict);
};
void CPyDict::my_free()
{
delete this;
};
int CPyDict::get_count()
{
return PyDict_Size(m_pydict);
};
bool CPyDict::get_item(char* name, CSimpleTypeVar* var)
{
PyObject* item = PyDict_GetItemString(m_pydict, name);
bool retval = false;
if(item)
{
retval = true;
wrap_python_var(item, var);
};
return retval;
};
char* CPyDict::get_key()
{
int pos = m_pos;
PyObject* pykey;
bool retval = PyDict_Next(m_pydict, &pos, &pykey, NULL);
return PyString_AS_STRING(pykey);
};
bool CPyDict::get_value(CSimpleTypeVar* var)
{
int pos = m_pos;
PyObject* pyval;
bool retval = PyDict_Next(m_pydict, &pos, NULL, &pyval);
wrap_python_var(pyval, var);
return retval;
};
bool CPyDict::get_valid()
{
int pos = m_pos;
return PyDict_Next(m_pydict, &pos, NULL, NULL);
};
void CPyDict::reset()
{
m_pos = 0;
};
bool CPyDict::next(char** name, CSimpleTypeVar* var)
{
PyObject* pykey;
PyObject* pyval;
bool retval = PyDict_Next(m_pydict, &m_pos, &pykey, &pyval);
if(retval)
{
wrap_python_var(pyval, var);
if(name)
{
*name = PyString_AS_STRING(pykey);
};
};
return retval;
};