added converters for QHash container
This commit is contained in:
parent
a52c12000e
commit
342b03d340
2 changed files with 44 additions and 1 deletions
40
PySide/QtCore/qhash_conversions.h
Normal file
40
PySide/QtCore/qhash_conversions.h
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
template <typename qhash>
|
||||||
|
struct Converter_qhash
|
||||||
|
{
|
||||||
|
static PyObject* toPython(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> > {};
|
||||||
|
|
@ -354,7 +354,10 @@
|
||||||
<container-type name="QQueue" type="queue"/>
|
<container-type name="QQueue" type="queue"/>
|
||||||
<rejection class="QQueue" function-name="head"/>
|
<rejection class="QQueue" function-name="head"/>
|
||||||
|
|
||||||
<container-type name="QHash" type="hash"/>
|
<container-type name="QHash" type="hash">
|
||||||
|
<conversion-rule file="qhash_conversions.h"/>
|
||||||
|
<include file-name="QHash" location="global"/>
|
||||||
|
</container-type>
|
||||||
<container-type name="QLinkedList" type="linked-list"/>
|
<container-type name="QLinkedList" type="linked-list"/>
|
||||||
<container-type name="QMap" type="map">
|
<container-type name="QMap" type="map">
|
||||||
<conversion-rule file="qmap_conversions.h"/>
|
<conversion-rule file="qmap_conversions.h"/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue