dtk_base.i 10.9 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, 476, 362, 503, 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)
NICLAUSSE Nicolas's avatar
NICLAUSSE Nicolas committed
68
%template(type##PluginFactorySwigTemplate) dtkCorePluginFactory<type>;
69
70
71
72
73
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
74
%template(type##PluginManagerSwigTemplate) dtkCorePluginManager<type##Plugin>;
75
76
77
class Export type##PluginManager : public dtkCorePluginManager<type##Plugin> {};
%enddef

78
#undef  DTK_DECLARE_CONCEPT(type, Export, Namespace)
79
80
81
82
83
84
85
86
87
88
89
90
%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)

91
#undef  Q_DECL_DEPRECATED_X(msg)
92
93
#define Q_DECL_DEPRECATED_X(msg)

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// /////////////////////////////////////////////////////////////////
// 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;
}

121
122
123
%typemap(in) qlonglong {
   $1 = PyInt_AsLong($input);
}
124

125
126
127
128
129
130
%typemap(in) const qlonglong& {
   $1 = PyInt_AsLong($input);
}

%typemap(typecheck)            qlonglong   = long long;
%typemap(typecheck)      const qlonglong&  = long long;
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
%typemap(typecheck)       QString  = char *;
%typemap(typecheck) const QString& = char *;

// Python -> C++

%typemap(in) QString {
    if (PyString_Check($input)) {
        $1 = QString(PyString_AsString($input));
    } else {
        qDebug("QString expected");
    }
}

%typemap(in) const QString& {
    if (PyString_Check($input)) {
        char *t = PyString_AsString($input);
        $1 = new QString(t);
    } else {
        qDebug("QString expected");
    }
}

%typemap(in) QStringList {
    if (PyList_Check($input)) {
        int i = 0;
        int end = PyList_Size($input);
        for(i;i!=end; ++i) {
            $1 << QString(PyString_AsString(PyList_GET_ITEM($input, i)));
        }
    } else {
        qDebug("QStringList expected");
    }
}

%typemap(in) const QStringList& {
    if (PyList_Check($input)) {
        int i = 0;
        int end = PyList_Size($input);
        $1 = new QStringList;
        for(i;i!=end; ++i) {
            char *t = PyString_AsString(PyList_GET_ITEM($input, i));
            (*$1) << QString(t);
        }
    } else {
        qDebug("QStringList expected");
    }
}

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
%typemap(in) QList<long> {
    if (PyList_Check($input)) {
        int i = 0;
        int end = PyList_Size($input);
        for(i;i!=end; ++i) {
            $1 << PyInt_AsLong(PyList_GET_ITEM($input, i));
        }
    } else {
        qDebug("QList<long> expected");
    }
}

%typemap(in) const QList<long>& {
    if (PyList_Check($input)) {
        int i = 0;
        int end = PyList_Size($input);
        $1 = new QList<long>;
        for(i;i!=end; ++i) {
            ($1)->append(PyInt_AsLong(PyList_GET_ITEM($input, i)));
        }
    } else {
        qDebug("QList<long> expected");
    }
}

%typemap(freearg) const QList<long>& {
    if ($1) {
        delete $1;
    }
 }

210
211
// C++ -> Python

212
213
214
%typemap(out) qlonglong {
   $result = PyInt_FromLong($1);
}
215

216
217
218
219
%typemap(out) const qlonglong& {
   $result = PyInt_FromLong($1);
}

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
%typemap(out) QString {
    $result = PyString_FromString($1.toUtf8().constData());
}

%typemap(out) const QString& {
    $result = 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)  {
        PyObject* obj = SWIG_NewPointerObj((*it), $descriptor(DATA_TYPE), 0|0);
        PyList_SET_ITEM($result, i, obj);
    }
}

%enddef // %QList_typemapsPtr()

%QList_typemapsPtr(dtkCorePlugin *)

%define %QList_typemaps(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)  {
        DATA_TYPE *newItem = new DATA_TYPE(*it);
        PyObject* obj = SWIG_NewPointerObj(newItem, $descriptor(DATA_TYPE*), 0|0);
        PyList_SET_ITEM($result, i, obj);
    }
}

%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());
        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);
    }
}

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
283
284
285
286
287
288
289
290
291
292
293
%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);
    }
}

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
template <class T1, class T2> class QPair
{
public:
    T1 first;
    T2 second;
};

%define %QPair_typemaps(DATA_TYPE_1, DATA_TYPE_2)

%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);
}

%enddef // %QPair_typemaps()

%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

467
468
//
// dtk_base.i ends here