blob: 881704469a82734ee1aacdd23481465f51fca211 (
plain)
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
|
namespace Shiboken {
template <typename qhash>
struct Converter_qhash
{
static bool isConvertible(PyObject* pyobj) {
return PyDict_Check(pyobj);
}
static PyObject* toPython(const qhash& hash)
{
PyObject* result = PyDict_New();
QHashIterator<typename qhash::key_type, typename qhash::mapped_type> it(hash);
while (it.hasNext()) {
it.next();
PyDict_SetItem(result,
Converter<typename qhash::key_type>::toPython(it.key()),
Converter<typename qhash::mapped_type>::toPython(it.value()));
}
return result;
}
static qhash toCpp(PyObject* pyobj)
{
qhash result;
PyObject* key;
PyObject* value;
Py_ssize_t pos = 0;
Py_INCREF(pyobj);
while (PyDict_Next(pyobj, &pos, &key, &value)) {
result.insert(Converter<typename qhash::key_type>::toCpp(key),
Converter<typename qhash::mapped_type>::toCpp(value));
}
Py_DECREF(pyobj);
return result;
}
};
template<typename KT, typename VT>
struct Converter<QHash<KT, VT> > : Converter_qhash<QHash<KT, VT> > {};
}
|