Commit 987fc24f authored by Pierre's avatar Pierre

Add wrapper

parent 9ef3a2a3
......@@ -552,6 +552,148 @@ namespace Namespace {
}
}
%typemap(in) QMap<QString, QVariant> {
if (PyDict_Check($input)) {
PyObect *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next($input, &pos, &key, &value)) {
QString k = QString(PyString_AsString(key));
if (PyString_Check(value)) {
v = QVariant::fromValue(QString(PyString_AsString(value)));
} else if (PyLong_Check(value)) {
v = QVariant::fromValue(PyInt_AsLong(value));
} else if (PyFloat_Check(value)) {
v = QVariant::fromValue(PyFloat_AsDouble(value));
} else if (PyBool_Check(value)) {
bool b = (value == Py_True);
v = QVariant::fromValue(b);
} else {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$1.insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<QString, QVariant> is returned.");
}
}
%typemap(in) const QMap<QString, QVariant>& {
if (PyDict_Check($input)) {
$1 = new QMap<QString, QVariant>;
PyObject *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next($input, &pos, &key, &value)) {
QString k = QString(PyString_AsString(key));
if (PyString_Check(value)) {
v = QVariant::fromValue(QString(PyString_AsString(value)));
} else if (PyLong_Check(value)) {
v = QVariant::fromValue(PyInt_AsLong(value));
} else if (PyFloat_Check(value)) {
v = QVariant::fromValue(PyFloat_AsDouble(value));
} else if (PyBool_Check(value)) {
bool b = (value == Py_True);
v = QVariant::fromValue(b);
} else {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$1->insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<QString, QVariant> is returned.");
}
}
%typemap(freearg) const QMap<QString, QVariant>& {
if ($1) {
delete $1;
}
}
%typemap(directorout) QMap<QString, QVariant> {
PyObject *dict = static_cast<PyObject *>($1);
if (PyDict_Check(dict)) {
PyObject *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next(dict, &pos, &key, &value)) {
QString k = QString(PyString_AsString(key));
if (PyString_Check(value)) {
v = QVariant::fromValue(QString(PyString_AsString(value)));
} else if (PyInt_Check(value) || PyLong_Check(value)) {
v = QVariant::fromValue(PyInt_AsLong(value));
} else if (PyFloat_Check(value)) {
v = QVariant::fromValue(PyFloat_AsDouble(value));
} else if (PyBool_Check(value)) {
bool b = (value == Py_True);
v = QVariant::fromValue(b);
} else {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$result.insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<QString, QVariant> is returned.");
}
}
%typemap(directorout) const QMap<QString, QVariant>& {
PyObject *dict = static_cast<PyObject *>($1);
if (PyDict_Check(dict)) {
$result = new QMap<QString, QVariant>();
PyObject *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next(dict, &pos, &key, &value)) {
QString k = QString(PyString_AsString(key));
if (PyString_Check(value)) {
v = QVariant::fromValue(QString(PyString_AsString(value)));
} else if (PyInt_Check(value) || PyLong_Check(value)) {
v = QVariant::fromValue(PyInt_AsLong(value));
} else if (PyFloat_Check(value)) {
v = QVariant::fromValue(PyFloat_AsDouble(value));
} else if (PyBool_Check(value)) {
bool b = (value == Py_True);
v = QVariant::fromValue(b);
} else {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$result->insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<QString, QVariant> is returned.");
}
}
%typemap(directorout) QMap<QString, QVariant>& {
PyObject *dict = static_cast<PyObject *>($1);
if (PyDict_Check(dict)) {
$result = new QMap<QString, QVariant>();
PyObject *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next(dict, &pos, &key, &value)) {
QString k = QString(PyString_AsString(key));
if (PyString_Check(value)) {
v = QVariant::fromValue(QString(PyString_AsString(value)));
} else if (PyInt_Check(value) || PyLong_Check(value)) {
v = QVariant::fromValue(PyInt_AsLong(value));
} else if (PyFloat_Check(value)) {
v = QVariant::fromValue(PyFloat_AsDouble(value));
} else if (PyBool_Check(value)) {
bool b = (value == Py_True);
v = QVariant::fromValue(b);
} else {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$result->insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<QString, QVariant> is returned.");
}
}
// C++ -> Python
%typemap(out) qlonglong {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment