Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit a0cda80f authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Add QMap typemaps.

parent d8590b83
......@@ -305,6 +305,83 @@ namespace Namespace {
}
}
%typemap(in) QMap<long, QVariant> {
if (PyDict_Check($input)) {
PyObject *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next($input, &pos, &key, &value)) {
long k = PyInt_AS_LONG(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 {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$1.insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<long, QVariant> is returned.");
}
}
%typemap(in) const QMap<long, QVariant>& {
if (PyDict_Check($input)) {
$1 = new QMap<long, QVariant>;
PyObject *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next($input, &pos, &key, &value)) {
long k = PyInt_AS_LONG(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 {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$1->insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<long, QVariant> is returned.");
}
}
%typemap(freearg) const QMap<long, QVariant>& {
if ($1) {
delete $1;
}
}
%typemap(directorout) QMap<long, 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)) {
long k = PyInt_AS_LONG(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 {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$result.insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<long, QVariant> is returned.");
}
}
// C++ -> Python
%typemap(out) qlonglong {
......@@ -414,46 +491,80 @@ namespace Namespace {
$input = list;
}
%typemap(out) QList<QString> {
%typemap(out) QList<long> {
$result = PyList_New($1.size());
auto it = $1.cbegin();
auto end = $1.cend();
for(int i = 0; it != end; ++it, ++i) {
PyObject *st = PyString_FromString((*it).toUtf8().constData());
PyList_SET_ITEM($result, i, st);
PyObject* v = PyInt_FromLong(*it);
PyList_SET_ITEM($result, i, v);
}
}
%typemap(directorin) QList<QString> {
%typemap(directorin) QList<long> {
PyObject *list = PyList_New($1.size());
auto it = $1.cbegin();
auto end = $1.cend();
for(int i = 0; it != end; ++it, ++i) {
PyObject *st = PyString_FromString((*it).toUtf8().constData());
PyList_SET_ITEM(list, i, st);
PyObject* v = PyInt_FromLong(*it);
PyList_SET_ITEM(list, i, v);
}
$input = list;
}
%typemap(out) QList<long> {
$result = PyList_New($1.size());
%typemap(out) QMap<long, QVariant> {
$result = PyDict_New();
PyObject *k;
PyObject *v;
auto it = $1.cbegin();
auto end = $1.cend();
for(int i = 0; it != end; ++it, ++i) {
PyObject* v = PyInt_FromLong(*it);
PyList_SET_ITEM($result, i, v);
for(; it != end; ++it) {
k = PyInt_FromLong(it.key());
QVariant val = it.value();
int type = val.type();
if (type == QMetaType::Int ||
type == QMetaType::Uint ||
type == QMetaType::Long ||
type == QMetaType::ULong ||
type == QMetaType::LongLong ||
type == QMetaType::ULongLong) {
v = PyInt_FromLong(val.value<long>());
} else if (type == QMetaType::Float ||
type == QMetaType::Double) {
v = PyFloat_AsDouble(val.value<double>());
} else if (type == QMetatype::QString) {
v = PyString_FromString(qPrintable(val.value<QString>()))
}
PyDict_SET_ITEM($result, k, v);
}
}
%typemap(directorin) QList<long> {
PyObject *list = PyList_New($1.size());
%typemap(directorin) QMap<long, QVariant> {
PyObject *map = PyDict_New();
PyObject *k;
PyObject *v;
auto it = $1.cbegin();
auto end = $1.cend();
for(int i = 0; it != end; ++it, ++i) {
PyObject* v = PyInt_FromLong(*it);
PyList_SET_ITEM(list, i, v);
for(; it != end; ++it) {
k = PyInt_FromLong(it.key());
QVariant val = it.value();
int type = val.type();
if (type == QMetaType::Int ||
type == QMetaType::Uint ||
type == QMetaType::Long ||
type == QMetaType::ULong ||
type == QMetaType::LongLong ||
type == QMetaType::ULongLong) {
v = PyInt_FromLong(val.value<long>());
} else if (type == QMetaType::Float ||
type == QMetaType::Double) {
v = PyFloat_AsDouble(val.value<double>());
} else if (type == QMetatype::QString) {
v = PyString_FromString(qPrintable(val.value<QString>()))
}
PyDict_SET_ITEM(map, k, v);
}
$input = list;
$input = map;
}
// QPair
......
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