dtk_base.i 34.4 KB
Newer Older
1 2 3
// Version: $Id$
//
//
4

5 6 7
// Commentary:
//
//
8

9 10 11
// Change Log:
//
//
12

13
// Code:
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

#pragma once

%include "carrays.i"

%array_class(double, doubleArray);

%{

#include <QtDebug>
#include <QtCore>

#include <string>

%}

// /////////////////////////////////////////////////////////////////
// Preprocessing setup
// /////////////////////////////////////////////////////////////////

34
#pragma SWIG nowarn=302, 389, 401, 509, 801, 472, 473, 476, 362, 503, 514, 516, 842, 845
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

// /////////////////////////////////////////////////////////////////
// Macro undefinition
// /////////////////////////////////////////////////////////////////

#undef Q_OBJECT
#undef signals
#undef slots

#define Q_OBJECT
#define signals public
#define slots

#undef  Q_PROPERTY(Type type MODE mode)
#define Q_PROPERTY(Type type MODE mode)

#undef  Q_DECLARE_INTERFACE(IFace, IId)
#define Q_DECLARE_INTERFACE(IFace, IId)

#undef  Q_DECLARE_METATYPE(Type type)
#define Q_DECLARE_METATYPE(Type type)

#undef  DTK_DEPRECATED
#define DTK_DEPRECATED

#undef  DTK_DECLARE_PLUGIN(type, Export)
61
%define DTK_DECLARE_PLUGIN(type, Export)
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
62 63 64
    class  type##Plugin : public dtkCorePluginBase {
};
%enddef
65 66 67

#undef  DTK_DECLARE_PLUGIN_FACTORY(type, Export)
%define DTK_DECLARE_PLUGIN_FACTORY(type, Export)
68 69 70 71 72 73 74 75
%extend QVariant {
    void setValue(type *value) {
        $self->setValue(dtkMetaType::variantFromValue(value));
    }
    type* to##type() const {
        return $self->value<type *>();
    }
 }
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
76
%template(type##PluginFactorySwigTemplate) dtkCorePluginFactory<type>;
77 78 79 80 81
class Export type##PluginFactory : public dtkCorePluginFactory<type> {};
%enddef

#undef  DTK_DECLARE_PLUGIN_MANAGER(type, Export)
%define DTK_DECLARE_PLUGIN_MANAGER(type, Export)
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
82
%template(type##PluginManagerSwigTemplate) dtkCorePluginManager<type##Plugin>;
83 84 85
class Export type##PluginManager : public dtkCorePluginManager<type##Plugin> {};
%enddef

86
#undef  DTK_DECLARE_CONCEPT(type, Export, Namespace)
87 88 89 90 91 92 93 94 95 96 97 98
%define DTK_DECLARE_CONCEPT(type, Export, Namespace)
%rename(Namespace##_pluginFactory) Namespace::pluginFactory;
%rename(Namespace##_pluginManager) Namespace::pluginManager;
namespace Namespace {
     Export type##PluginFactory& pluginFactory();
     Export type##PluginManager& pluginManager();
}
%enddef

#undef  DTK_DECLARE_OBJECT(Type type)
#define DTK_DECLARE_OBJECT(Type type)

99
#undef  Q_DECL_DEPRECATED_X(msg)
100 101
#define Q_DECL_DEPRECATED_X(msg)

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
// /////////////////////////////////////////////////////////////////
// Ignore rules for operators
// /////////////////////////////////////////////////////////////////

%ignore operator>>;
%ignore operator<<;
%ignore operator==;
%ignore operator[];
%ignore operator!=;
%ignore operator*=;
%ignore operator/=;
%ignore operator bool;
%ignore operator int;
%ignore operator float;
%ignore operator double;
%ignore operator double *;

// /////////////////////////////////////////////////////////////////
// Typemaps
// /////////////////////////////////////////////////////////////////

#ifdef SWIGPYTHON

%typecheck(SWIG_TYPECHECK_STRING) char * {
    $1 = PyString_Check($input) ? 1 : 0;
}

129
// Python -> C++
130

131 132 133
// qlonglong

%typemap(in) qlonglong {
134 135 136
   $1 = PyInt_AsLong($input);
}

137 138 139 140
%typemap(in) const qlonglong& {
   $1 = PyInt_AsLong($input);
}

141 142 143 144 145 146 147 148 149 150
%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;
    }
}

151 152
%typemap(typecheck)            qlonglong   = long long;
%typemap(typecheck)      const qlonglong&  = long long;
153 154
%typemap(typecheck)       QString  = char *;
%typemap(typecheck) const QString& = char *;
155 156 157 158
%typemap(typecheck)       QString  = const char *;
%typemap(typecheck) const QString& = const char *;


159 160 161 162 163 164
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, noblock=1) QStringList {
    $1 = PyList_Check($input) ? 1 : 0;
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, noblock=1) const QStringList& {
    $1 = PyList_Check($input) ? 1 : 0;
}
165 166 167

// Python -> C++

168 169
// QString

170 171 172 173
%typemap(in) QString {
    if (PyString_Check($input)) {
        $1 = QString(PyString_AsString($input));
    } else {
174
        qDebug("String is expected as input. Empty QString is returned.");
175 176 177 178 179 180 181 182
    }
}

%typemap(in) const QString& {
    if (PyString_Check($input)) {
        char *t = PyString_AsString($input);
        $1 = new QString(t);
    } else {
183
        qDebug("String is expected as input. Empty QString is returned.");
184 185 186
    }
}

187 188 189 190 191 192
%typemap(freearg) const QString& {
    if ($1) {
        delete $1;
    }
}

193 194 195 196 197 198 199 200 201
%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.");
    }
}

202
// QStringList
203

204 205 206
%typemap(in) QStringList {
    if (PyList_Check($input)) {
        int end = PyList_Size($input);
207
        for(int i = 0; i!=end; ++i) {
208 209 210
            $1 << QString(PyString_AsString(PyList_GET_ITEM($input, i)));
        }
    } else {
211
        qDebug("PyList of strings is expected as input. Empty QStringList is returned.");
212 213 214 215 216 217 218
    }
}

%typemap(in) const QStringList& {
    if (PyList_Check($input)) {
        int end = PyList_Size($input);
        $1 = new QStringList;
219
        for(int i = 0 ;i!=end; ++i) {
220 221 222 223
            char *t = PyString_AsString(PyList_GET_ITEM($input, i));
            (*$1) << QString(t);
        }
    } else {
224 225 226 227 228 229 230
        qDebug("PyList of strings is expected as input. Empty QStringList is returned.");
    }
}

%typemap(freearg) const QStringList& {
    if ($1) {
        delete $1;
231 232 233
    }
}

234 235 236 237
%typemap(directorout) QStringList {
    PyObject *list = static_cast<PyObject *>($1);
    if (PyList_Check(list)) {
        int end = PyList_Size(list);
238
        for(int i = 0; i<end; ++i) {
239 240 241 242 243 244 245 246
            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.");
    }
}

247 248
// QList<long>

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
249 250 251
%typemap(in) QList<long> {
    if (PyList_Check($input)) {
        int end = PyList_Size($input);
252
        for(int i = 0; i!=end; ++i) {
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
253 254 255
            $1 << PyInt_AsLong(PyList_GET_ITEM($input, i));
        }
    } else {
256
        qDebug("PyList of integers is expected as input. Empty QList<long> is returned.");
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
257 258 259 260 261 262 263
    }
}

%typemap(in) const QList<long>& {
    if (PyList_Check($input)) {
        int end = PyList_Size($input);
        $1 = new QList<long>;
264
        for(int i = 0; i!=end; ++i) {
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
265 266 267
            ($1)->append(PyInt_AsLong(PyList_GET_ITEM($input, i)));
        }
    } else {
268
        qDebug("PyList of integers is expected as input. Empty QList<long> is returned.");
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
269 270 271 272 273 274 275
    }
}

%typemap(freearg) const QList<long>& {
    if ($1) {
        delete $1;
    }
276
}
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
277

278 279 280 281
%typemap(directorout) QList<long> {
    PyObject *list = static_cast<PyObject *>($1);
    if (PyList_Check(list)) {
        int end = PyList_Size(list);
282
        for(int i = 0; i<end; ++i) {
283 284 285 286 287 288 289 290
            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.");
    }
}

291 292
// QList<double>

293 294 295
%typemap(in) QList<double> {
    if (PyList_Check($input)) {
        int end = PyList_Size($input);
296
        for(int i = 0; i!=end; ++i) {
297 298 299 300 301 302 303 304 305 306 307
            $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 end = PyList_Size($input);
        $1 = new QList<double>;
308
        for(int i = 0; i!=end; ++i) {
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
            ($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 end = PyList_Size(list);
326
        for(int i = 0; i<end; ++i) {
327 328 329 330 331 332 333 334
            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.");
    }
}

335 336
// QMap<long, QVariant>

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
337 338 339 340 341 342 343 344 345
%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)));
346 347 348
            } else if (PyBool_Check(value)) {
                bool b = (value == Py_True);
                v = QVariant::fromValue(b);
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
            } 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)));
373 374 375
            } else if (PyBool_Check(value)) {
                bool b = (value == Py_True);
                v = QVariant::fromValue(b);
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
            } 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)));
406 407 408
            } else if (PyBool_Check(value)) {
                bool b = (value == Py_True);
                v = QVariant::fromValue(b);
409
            } else if (PyInt_Check(value) || PyLong_Check(value)) {
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
410 411 412 413 414 415 416 417 418 419 420 421 422
                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.");
    }
}

423
// QMap<QString, QVariant>
424

Pierre's avatar
Pierre committed
425 426 427 428 429 430 431 432 433
%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)));
434 435 436
            } else if (PyBool_Check(value)) {
                bool b = (value == Py_True);
                v = QVariant::fromValue(b);
Pierre's avatar
Pierre committed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
            } 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<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)));
461 462 463
            } else if (PyBool_Check(value)) {
                bool b = (value == Py_True);
                v = QVariant::fromValue(b);
Pierre's avatar
Pierre committed
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
            } 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<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)));
494 495 496
            } else if (PyBool_Check(value)) {
                bool b = (value == Py_True);
                v = QVariant::fromValue(b);
Pierre's avatar
Pierre committed
497 498 499 500 501 502 503 504 505 506 507 508 509 510
            } 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 {
                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.");
    }
}

511 512
// C++ -> Python

513 514
// qlonglong

515 516 517
%typemap(out) qlonglong {
   $result = PyInt_FromLong($1);
}
518

519 520 521 522
%typemap(out) const qlonglong& {
   $result = PyInt_FromLong($1);
}

523 524 525 526 527 528 529 530
%typemap(directorin) qlonglong {
    $input = PyInt_FromLong($1);
}

%typemap(directorin) const qlonglong& {
    $input = PyInt_FromLong($1);
}

531 532
// QString

533 534 535 536 537 538 539 540
%typemap(out) QString {
    $result = PyString_FromString($1.toUtf8().constData());
}

%typemap(out) const QString& {
    $result = PyString_FromString($1.toUtf8().constData());
}

541 542 543 544 545 546 547 548
%typemap(directorin) QString {
    $input = PyString_FromString($1.toUtf8().constData());
}

%typemap(directorin) const QString& {
    $input = PyString_FromString($1.toUtf8().constData());
}

549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
// QVariant

%typemap(out) QVariant {
    QVariant val = $1;
    PyObject *v;
    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_FromDouble(val.value<double>());
    } else if (type == QMetaType::QString) {
        v = PyString_FromString(qPrintable(val.value<QString>()));
    } else if (type == QMetaType::Bool) {
        bool b = val.value<bool>();
        v = b ? Py_True : Py_False;
    }

    $result = v;
 }

%typemap(out) const QVariant& {
    QVariant val = *($1);
    PyObject *v;
    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_FromDouble(val.value<double>());
    } else if (type == QMetaType::QString) {
        v = PyString_FromString(qPrintable(val.value<QString>()));
    } else if (type == QMetaType::Bool) {
        bool b = val.value<bool>();
        v = b ? Py_True : Py_False;
    }
    $result = v;
}

%typemap(directorin) QVariant {
    QVariant val = $1;
    PyObject *v;
    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_FromDouble(val.value<double>());
    } else if (type == QMetaType::QString) {
        v = PyString_FromString(qPrintable(val.value<QString>()));
    } else if (type == QMetaType::Bool) {
        bool b = val.value<bool>();
        v = b ? Py_True : Py_False;
    }
    $input = v;
}

%typemap(directorin) const QVariant& {
    QVariant val = $1;
    PyObject *v;
    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_FromDouble(val.value<double>());
    } else if (type == QMetaType::QString) {
        v = PyString_FromString(qPrintable(val.value<QString>()));
    } else if (type == QMetaType::Bool) {
        bool b = val.value<bool>();
        v = b ? Py_True : Py_False;
    }
    $input = v;
}

// QList<DATA_TYPE>

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
646
%define %QList_typemapsPtr(DATA_TYPE)
647 648 649

%typemap(out) QList<DATA_TYPE> {
    $result = PyList_New($1.size());
650 651 652
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(int i = 0 ; it != end; ++it, ++i)  {
653 654 655 656 657
        PyObject* obj = SWIG_NewPointerObj((*it), $descriptor(DATA_TYPE), 0|0);
        PyList_SET_ITEM($result, i, obj);
    }
}

658 659 660 661 662 663 664 665 666 667 668
%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;
}

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
669
%enddef // %QList_typemapsPtr()
670 671 672

%QList_typemapsPtr(dtkCorePlugin *)

673
%define %QList_typemaps(DATA_TYPE)
674 675 676

%typemap(out) QList<DATA_TYPE> {
    $result = PyList_New($1.size());
677 678 679
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(int i = 0 ; it != end; ++it, ++i)  {
680 681 682 683 684 685
        DATA_TYPE *newItem = new DATA_TYPE(*it);
        PyObject* obj = SWIG_NewPointerObj(newItem, $descriptor(DATA_TYPE*), 0|0);
        PyList_SET_ITEM($result, i, obj);
    }
}

686 687 688 689 690 691 692 693 694 695 696 697
%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;
}

698
%enddef // %QList_typemaps()
699

700 701
// QStringList

702 703
%typemap(out) QStringList {
    $result = PyList_New($1.size());
704 705 706 707
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(int i = 0; it != end; ++it, ++i) {
        PyObject *st = PyString_FromString((*it).toUtf8().constData());
708 709 710 711
        PyList_SET_ITEM($result, i, st);
    }
}

712 713 714 715 716 717 718 719 720 721
%typemap(out) const QStringList& {
    $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);
    }
}

722 723 724 725 726 727 728 729 730 731 732
%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;
}

733 734 735 736 737 738 739 740 741 742 743 744 745
%typemap(directorin) const 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;
}

// QList<long>

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
746
%typemap(out) QList<long> {
747
    $result = PyList_New($1.size());
748 749 750
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(int i = 0; it != end; ++it, ++i) {
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
751 752
        PyObject* v = PyInt_FromLong(*it);
        PyList_SET_ITEM($result, i, v);
753 754 755
    }
}

756 757 758 759 760 761 762 763 764 765
%typemap(out) const QList<long>& {
    $result = 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($result, i, v);
    }
}

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
766
%typemap(directorin) QList<long> {
767 768 769 770
    PyObject *list = PyList_New($1.size());
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(int i = 0; it != end; ++it, ++i) {
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
771 772
        PyObject* v = PyInt_FromLong(*it);
        PyList_SET_ITEM(list, i, v);
773 774 775 776
    }
    $input = list;
}

777 778 779 780 781 782 783 784 785 786 787 788 789
%typemap(directorin) const 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;
}

// QMap<long, QVariant>

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
790 791 792 793
%typemap(out) QMap<long, QVariant> {
    $result = PyDict_New();
    PyObject *k;
    PyObject *v;
794 795
    auto it  = $1.cbegin();
    auto end = $1.cend();
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
796 797 798 799 800
    for(; it != end; ++it) {
        k = PyInt_FromLong(it.key());
        QVariant val = it.value();
        int type = val.type();
        if (type == QMetaType::Int ||
801
            type == QMetaType::UInt ||
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
802 803 804 805 806 807 808
            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) {
809 810
            v = PyFloat_FromDouble(val.value<double>());
        } else if (type == QMetaType::QString) {
811
            v = PyString_FromString(qPrintable(val.value<QString>()));
812
        } else if (type == QMetaType::Bool) {
813 814
            bool b = val.value<bool>();
            v = b ? Py_True : Py_False;
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
815
        }
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
        PyDict_SetItem($result, k, v);
    }
}

%typemap(out) const 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_FromDouble(val.value<double>());
        } else if (type == QMetaType::QString) {
            v = PyString_FromString(qPrintable(val.value<QString>()));
        } else if (type == QMetaType::Bool) {
            bool b = val.value<bool>();
            v = b ? Py_True : Py_False;
        }
        PyDict_SetItem($result, k, v);
847 848 849
    }
}

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
850 851 852 853
%typemap(directorin) QMap<long, QVariant> {
    PyObject *map = PyDict_New();
    PyObject *k;
    PyObject *v;
854 855
    auto it  = $1.cbegin();
    auto end = $1.cend();
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
856 857 858 859 860
    for(; it != end; ++it) {
        k = PyInt_FromLong(it.key());
        QVariant val = it.value();
        int type = val.type();
        if (type == QMetaType::Int ||
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
            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_FromDouble(val.value<double>());
        } else if (type == QMetaType::QString) {
            v = PyString_FromString(qPrintable(val.value<QString>()));
        } else if (type == QMetaType::Bool) {
            bool b = val.value<bool>();
            v = b ? Py_True : Py_False;
        }
        PyDict_SetItem(map, k, v);
    }
    $input = map;
}

%typemap(directorin) const 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_FromDouble(val.value<double>());
        } else if (type == QMetaType::QString) {
            v = PyString_FromString(qPrintable(val.value<QString>()));
        } else if (type == QMetaType::Bool) {
            bool b = val.value<bool>();
            v = b ? Py_True : Py_False;
        }
        PyDict_SetItem(map, k, v);
    }
    $input = map;
}

// QMap<QString, QVariant>

%typemap(out) QMap<QString, QVariant> {
    $result = PyDict_New();
    PyObject *k;
    PyObject *v;
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(; it != end; ++it) {
        k = PyString_FromString(qPrintable(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_FromDouble(val.value<double>());
        } else if (type == QMetaType::QString) {
            v = PyString_FromString(qPrintable(val.value<QString>()));
        } else if (type == QMetaType::Bool) {
            bool b = val.value<bool>();
            v = b ? Py_True : Py_False;
        }
        PyDict_SetItem($result, k, v);
    }
}

%typemap(out) const QMap<QString, QVariant>& {
    $result = PyDict_New();
    PyObject *k;
    PyObject *v;
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(; it != end; ++it) {
        k = PyString_FromString(qPrintable(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_FromDouble(val.value<double>());
        } else if (type == QMetaType::QString) {
            v = PyString_FromString(qPrintable(val.value<QString>()));
        } else if (type == QMetaType::Bool) {
            bool b = val.value<bool>();
            v = b ? Py_True : Py_False;
        }
        PyDict_SetItem($result, k, v);
    }
}

%typemap(directorin) QMap<QString, QVariant> {
    PyObject *map = PyDict_New();
    PyObject *k;
    PyObject *v;
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(; it != end; ++it) {
        k = PyString_FromString(qPrintable(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_FromDouble(val.value<double>());
        } else if (type == QMetaType::QString) {
            v = PyString_FromString(qPrintable(val.value<QString>()));
        } else if (type == QMetaType::Bool) {
            bool b = val.value<bool>();
            v = b ? Py_True : Py_False;
        }
        PyDict_SetItem(map, k, v);
    }
    $input = map;
}

%typemap(directorin) const QMap<QString, QVariant>& {
    PyObject *map = PyDict_New();
    PyObject *k;
    PyObject *v;
    auto it  = $1.cbegin();
    auto end = $1.cend();
    for(; it != end; ++it) {
        k = PyString_FromString(qPrintable(it.key()));
        QVariant val = it.value();
        int type = val.type();
        if (type == QMetaType::Int ||
            type == QMetaType::UInt ||
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
1017 1018 1019 1020 1021 1022 1023
            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) {
1024 1025
            v = PyFloat_FromDouble(val.value<double>());
        } else if (type == QMetaType::QString) {
1026
            v = PyString_FromString(qPrintable(val.value<QString>()));
1027
        } else if (type == QMetaType::Bool) {
1028 1029
            bool b = val.value<bool>();
            v = b ? Py_True : Py_False;
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
1030
        }
1031
        PyDict_SetItem(map, k, v);
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
1032
    }
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
1033
    $input = map;
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
1034 1035
}

1036 1037
// QPair

1038 1039 1040 1041 1042 1043 1044
template <class T1, class T2> class QPair
{
public:
    T1 first;
    T2 second;
};

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
1045
%define %QPair_typemaps(DATA_TYPE_1, DATA_TYPE_2)
1046 1047 1048 1049 1050 1051 1052 1053 1054

%typemap(out) QPair<DATA_TYPE_1, DATA_TYPE_2> {
    $result = PyTuple_New(2);
    PyObject* obj1 = SWIG_NewPointerObj(*$1.first, $descriptor(DATA_TYPE_1), 0|0);
    PyObject* obj2 = SWIG_NewPointerObj(*$1.second, $descriptor(DATA_TYPE_2), 0|0);
    PyTuple_SET_ITEM($result, 0, obj1);
    PyTuple_SET_ITEM($result, 1, obj2);
}

NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
1055
%enddef // %QPair_typemaps()
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210

%template(QPairStrStrList) QPair<QString, QStringList>;

%QPair_typemaps(QString, QStringList)

#elif SWIGTCL

// Tcl -> C++

%typemap(in) QString {
    $1 = QString(Tcl_GetString($input));
}

%typemap(in) const QString& {
    char *t = Tcl_GetString($input);
    $1 = new QString(t);
}

// C++ -> Tcl

%typemap(out) QString {
    Tcl_SetStringObj($result, $1.toUtf8().constData(), $1.size());
}

%typemap(out) const QString& {
    Tcl_SetStringObj($result, $1.toUtf8().constData(), $1.size());
}

#elif SWIGCSHARP

// /////////////////////////////////////////////////////////////////
// C#
// /////////////////////////////////////////////////////////////////

%typemap(ctype) QString "char *"
%typemap(imtype) QString "string"
%typemap(cstype) QString "string"
%typemap(csdirectorin) QString "$iminput"
%typemap(csdirectorout) QString "$cscall"

%typemap(in, canthrow=1) QString {
    if (!$input) {
        SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
        return $null;
    }

    $1 = QString($input);
}

%typemap(out) QString {
    $result = SWIG_csharp_string_callback($1.toUtf8().constData());
}

%typemap(directorout, canthrow=1) QString {
    if (!$input) {
        SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
        return $null;
    }

    $result = string($input);
}

%typemap(directorin) QString {
    $input = SWIG_csharp_string_callback($1.toUtf8().constData());
}

%typemap(csin) QString "$csinput"

%typemap(csout, excode=SWIGEXCODE) QString {
    string ret = $imcall;$excode;
    return ret;
}

%typemap(csvarin, excode=SWIGEXCODE2) QString {
    set {
      $imcall;$excode
    }
}

%typemap(csvarout, excode=SWIGEXCODE2) QString {
    get {
      string ret = $imcall;$excode
      return ret;
    }
}

%typemap(typecheck) QString = char *;

%typemap(throws, canthrow=1) QString {
    SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.c_str());
    return $null;
}

%typemap(ctype) const QString & "char *"
%typemap(imtype) const QString & "string"
%typemap(cstype) const QString & "string"
%typemap(csdirectorin) const QString & "$iminput"
%typemap(csdirectorout) const QString & "$cscall"

%typemap(in, canthrow=1) const QString & {
    if (!$input) {
        SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
        return $null;
    }
    QString $1_str($input);
    $1 = &$1_str;
}

%typemap(out) const QString & {
    $result = SWIG_csharp_string_callback($1->toUtf8().constData());
}

%typemap(csin) const QString & "$csinput"

%typemap(csout, excode=SWIGEXCODE) const QString & {
    string ret = $imcall;$excode
    return ret;
}

%typemap(directorout, canthrow=1, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const QString & {
    if (!$input) {
        SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0);
        return $null;
   }
   static string $1_str;
   $1_str = $input;
   $result = &$1_str;
}

%typemap(directorin) const QString & {
    $input = SWIG_csharp_string_callback($1.toUtf8().constData());
}

%typemap(csvarin, excode=SWIGEXCODE2) const QString & {
    set {
      $imcall;$excode
    }
}

%typemap(csvarout, excode=SWIGEXCODE2) const QString & {
    get {
        string ret = $imcall;$excode;
        return ret;
    }
}

%typemap(typecheck) const QString & = char *;

%typemap(throws, canthrow=1) const QString & {
    SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.c_str());
    return $null;
}

#endif

1211 1212
//
// dtk_base.i ends here