Commit d4d7eedb authored by Julien Wintz's avatar Julien Wintz
Browse files

Merge branch 'develop' of github.com:d-tk/dtk into develop

parents 97d6b059 a0cda80f
......@@ -22,6 +22,8 @@
#include <dtkCore/dtkArray>
#include <dtkLog>
#include <QtCore>
// /////////////////////////////////////////////////////////////////
// dtkComposerNodeMetaContainerPrivate interface
// /////////////////////////////////////////////////////////////////
......@@ -62,6 +64,7 @@ void dtkComposerNodeMetaContainer::run(void)
if (!d->receiver_value.isEmpty()) {
int type = d->receiver_value.data().type();
QStringList *slist;
switch (type) {
case QMetaType::Int:
......@@ -95,6 +98,15 @@ void dtkComposerNodeMetaContainer::run(void)
var_container = dtkMetaType::variantFromValue(new dtkArray<double>(size, d->receiver_value.data<double>()));
break;
case QMetaType::QString:
slist = new QStringList;
slist->reserve(size);
for(int i = 0; i < size; ++i) {
slist->append(d->receiver_value.data<QString>());
};
var_container = dtkMetaType::variantFromValue(slist);
break;
default:
var_container = dtkMetaType::variantFromValue(new dtkArray<QVariant>(size, d->receiver_value.data()));
break;
......
......@@ -126,6 +126,16 @@ namespace Namespace {
$1 = PyInt_AsLong($input);
}
%typemap(directorout) qlonglong {
PyObject *o = static_cast<PyObject *>($1);
if (PyInt_Check(o)) {
$result = PyInt_AsLong(o);
} else {
qDebug("Long int is expected as input. Zero integer is returned.");
$result = 0;
}
}
%typemap(typecheck) qlonglong = long long;
%typemap(typecheck) const qlonglong& = long long;
%typemap(typecheck) QString = char *;
......@@ -137,7 +147,7 @@ namespace Namespace {
if (PyString_Check($input)) {
$1 = QString(PyString_AsString($input));
} else {
qDebug("QString expected");
qDebug("String is expected as input. Empty QString is returned.");
}
}
......@@ -146,7 +156,16 @@ namespace Namespace {
char *t = PyString_AsString($input);
$1 = new QString(t);
} else {
qDebug("QString expected");
qDebug("String is expected as input. Empty QString is returned.");
}
}
%typemap(directorout) QString {
PyObject *ps = static_cast<PyObject *>($1);
if (PyString_Check(ps)) {
$result = QString(PyString_AsString(ps));
} else {
qDebug("String is expected as input. Empty QString is returned.");
}
}
......@@ -158,7 +177,7 @@ namespace Namespace {
$1 << QString(PyString_AsString(PyList_GET_ITEM($input, i)));
}
} else {
qDebug("QStringList expected");
qDebug("PyList of strings is expected as input. Empty QStringList is returned.");
}
}
......@@ -172,7 +191,27 @@ namespace Namespace {
(*$1) << QString(t);
}
} else {
qDebug("QStringList expected");
qDebug("PyList of strings is expected as input. Empty QStringList is returned.");
}
}
%typemap(freearg) const QStringList& {
if ($1) {
delete $1;
}
}
%typemap(directorout) QStringList {
PyObject *list = static_cast<PyObject *>($1);
if (PyList_Check(list)) {
int i = 0;
int end = PyList_Size(list);
for(i;i<end; ++i) {
char *t = PyString_AsString(PyList_GET_ITEM(list, i));
$result << QString(t);
}
} else {
qDebug("PyList of integers is expected as input. Empty QList<long> is returned.");
}
}
......@@ -184,7 +223,7 @@ namespace Namespace {
$1 << PyInt_AsLong(PyList_GET_ITEM($input, i));
}
} else {
qDebug("QList<long> expected");
qDebug("PyList of integers is expected as input. Empty QList<long> is returned.");
}
}
......@@ -197,7 +236,7 @@ namespace Namespace {
($1)->append(PyInt_AsLong(PyList_GET_ITEM($input, i)));
}
} else {
qDebug("QList<long> expected");
qDebug("PyList of integers is expected as input. Empty QList<long> is returned.");
}
}
......@@ -205,7 +244,143 @@ namespace Namespace {
if ($1) {
delete $1;
}
}
}
%typemap(directorout) QList<long> {
PyObject *list = static_cast<PyObject *>($1);
if (PyList_Check(list)) {
int i = 0;
int end = PyList_Size(list);
for(i;i<end; ++i) {
PyObject *o = PyList_GET_ITEM(list, i);
$result << PyInt_AsLong(o);
}
} else {
qDebug("PyList of integers is expected as input. Empty QList<long> is returned.");
}
}
%typemap(in) QList<double> {
if (PyList_Check($input)) {
int i = 0;
int end = PyList_Size($input);
for(i;i!=end; ++i) {
$1 << PyFloat_AsDouble(PyList_GET_ITEM($input, i));
}
} else {
qDebug("PyList of double is expected as input. Empty QList<double> is returned.");
}
}
%typemap(in) const QList<double>& {
if (PyList_Check($input)) {
int i = 0;
int end = PyList_Size($input);
$1 = new QList<double>;
for(i;i!=end; ++i) {
($1)->append(PyFloat_AsDouble(PyList_GET_ITEM($input, i)));
}
} else {
qDebug("PyList of double floats is expected as input. Empty QList<double> is returned.");
}
}
%typemap(freearg) const QList<double>& {
if ($1) {
delete $1;
}
}
%typemap(directorout) QList<double> {
PyObject *list = static_cast<PyObject *>($1);
if (PyList_Check(list)) {
int i = 0;
int end = PyList_Size(list);
for(i;i<end; ++i) {
PyObject *o = PyList_GET_ITEM(list, i);
$result << PyFloat_AsDouble(o);
}
} else {
qDebug("PyList of double floats is expected as input. Empty QList<double> is returned.");
}
}
%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
......@@ -217,6 +392,14 @@ namespace Namespace {
$result = PyInt_FromLong($1);
}
%typemap(directorin) qlonglong {
$input = PyInt_FromLong($1);
}
%typemap(directorin) const qlonglong& {
$input = PyInt_FromLong($1);
}
%typemap(out) QString {
$result = PyString_FromString($1.toUtf8().constData());
}
......@@ -225,19 +408,37 @@ namespace Namespace {
$result = PyString_FromString($1.toUtf8().constData());
}
%typemap(directorin) QString {
$input = PyString_FromString($1.toUtf8().constData());
}
%typemap(directorin) const QString& {
$input = PyString_FromString($1.toUtf8().constData());
}
%define %QList_typemapsPtr(DATA_TYPE)
%typemap(out) QList<DATA_TYPE> {
$result = PyList_New($1.size());
int i = 0;
QList<DATA_TYPE>::iterator it = $1.begin();
QList<DATA_TYPE>::iterator end = $1.end();
for(;it!=end; ++it, ++i) {
auto it = $1.cbegin();
auto end = $1.cend();
for(int i = 0 ; it != end; ++it, ++i) {
PyObject* obj = SWIG_NewPointerObj((*it), $descriptor(DATA_TYPE), 0|0);
PyList_SET_ITEM($result, i, obj);
}
}
%typemap(directorin) QList<DATA_TYPE> {
PyObject *list = PyList_New($1.size());
auto it = $1.cbegin();
auto end = $1.cend();
for(int i = 0 ; it != end; ++it, ++i) {
PyObject* obj = SWIG_NewPointerObj((*it), $descriptor(DATA_TYPE), 0|0);
PyList_SET_ITEM(list, i, obj);
}
$input = list;
}
%enddef // %QList_typemapsPtr()
%QList_typemapsPtr(dtkCorePlugin *)
......@@ -246,51 +447,128 @@ namespace Namespace {
%typemap(out) QList<DATA_TYPE> {
$result = PyList_New($1.size());
int i = 0;
QList<DATA_TYPE>::iterator it = $1.begin();
QList<DATA_TYPE>::iterator end = $1.end();
for(;it!=end; ++it, ++i) {
auto it = $1.cbegin();
auto end = $1.cend();
for(int i = 0 ; it != end; ++it, ++i) {
DATA_TYPE *newItem = new DATA_TYPE(*it);
PyObject* obj = SWIG_NewPointerObj(newItem, $descriptor(DATA_TYPE*), 0|0);
PyList_SET_ITEM($result, i, obj);
}
}
%typemap(directorin) QList<DATA_TYPE> {
PyObject *list = PyList_New($1.size());
auto it = $1.cbegin();
auto end = $1.cend();
for(int i = 0 ; it != end; ++it, ++i) {
DATA_TYPE *newItem = new DATA_TYPE(*it);
PyObject* obj = SWIG_NewPointerObj(newItem, $descriptor(DATA_TYPE*), 0|0);
PyList_SET_ITEM(list, i, obj);
}
$input = list;
}
%enddef // %QList_typemaps()
%typemap(out) QStringList {
$result = PyList_New($1.size());
int i = 0;
QStringList::iterator it = $1.begin();
QStringList::iterator end = $1.end();
for(;it!=end; ++it, ++i) {
PyObject* st = PyString_FromString((*it).toUtf8().constData());
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);
}
}
%typemap(out) QList<QString> {
$result = PyList_New($1.size());
int i = 0;
QStringList::iterator it = $1.begin();
QStringList::iterator end = $1.end();
for(;it!=end; ++it, ++i) {
PyObject* st = PyString_FromString((*it).toUtf8().constData());
PyList_SET_ITEM($result, i, st);
%typemap(directorin) QStringList {
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);
}
$input = list;
}
%typemap(out) QList<long> {
$result = PyList_New($1.size());
int i = 0;
QList<long>::iterator it = $1.begin();
QList<long>::iterator end = $1.end();
for(;it!=end; ++it, ++i) {
PyObject* l = PyInt_FromLong(*it);
PyList_SET_ITEM($result, i, l);
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);
}
}
%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* v = PyInt_FromLong(*it);
PyList_SET_ITEM(list, i, v);
}
$input = list;
}
%typemap(out) QMap<long, QVariant> {
$result = PyDict_New();
PyObject *k;
PyObject *v;
auto it = $1.cbegin();
auto end = $1.cend();
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) QMap<long, QVariant> {
PyObject *map = PyDict_New();
PyObject *k;
PyObject *v;
auto it = $1.cbegin();
auto end = $1.cend();
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 = map;
}
// QPair
template <class T1, class T2> class QPair
{
public:
......
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