FreeCAD

Форк
0
/
templateClassPyExport.py 
1560 строк · 49.9 Кб
1
#! python
2
# -*- coding: utf-8 -*-
3
# (c) 2006 Juergen Riegel
4

5

6
from . import template
7
import os, sys
8
import generateBase.generateModel_Module
9
import generateBase.generateTools
10

11

12
class TemplateClassPyExport(template.ModelTemplate):
13
    def Generate(self):
14
        # self.ParentNamespace = "Base"
15
        # self.Namespace = "Base"
16
        encoding = sys.getfilesystemencoding()
17
        path = self.path
18
        exportName = self.export.Name
19
        dirname = self.dirname
20

21
        def escapeString(s, indent=4):
22
            """Escapes a string for use as literal in C++ code"""
23
            s = s.strip()  # This allows UserDocu-tags on their own lines without adding whitespace
24
            s = s.replace("\\", "\\\\")
25
            s = s.replace('"', '\\"')
26
            s = s.replace("\n", f'\\n"\n{" "*indent}"')
27
            return s
28

29
        print("TemplateClassPyExport", path + exportName)
30
        # Imp.cpp must not exist, neither in path nor in dirname
31
        if not os.path.exists(path + exportName + "Imp.cpp"):
32
            if not os.path.exists(dirname + exportName + "Imp.cpp"):
33
                file = open(path + exportName + "Imp.cpp", "wb")
34
                generateBase.generateTools.replace(self.TemplateImplement, locals(), file)
35
                file.close()
36
        with open(path + exportName + ".cpp", "wb") as file:
37
            generateBase.generateTools.replace(self.TemplateModule, locals(), file)
38
        with open(path + exportName + ".h", "wb") as file:
39
            generateBase.generateTools.replace(self.TemplateHeader, locals(), file)
40
            # file.write( generateBase.generateTools.replace(self.Template,locals()))
41

42
    TemplateHeader = """
43
// This file is generated by src/Tools/generateTemplates/templateClassPyExport.py out of the XML file
44
// Every change you make here gets lost in the next full rebuild!
45
#ifndef @self.export.Namespace.upper().replace("::", "_")@_@self.export.Name.upper()@_H
46
#define @self.export.Namespace.upper().replace("::", "_")@_@self.export.Name.upper()@_H
47

48
#include <@self.export.FatherInclude@>
49
#include <@self.export.Include@>
50
#include <string>
51

52
+ if(self.export.ForwardDeclarations != ""):
53
// Forward declarations
54
@self.export.ForwardDeclarations@
55
-
56

57
namespace @self.export.Namespace.replace("::"," { namespace ")@
58
{
59

60
//===========================================================================
61
// @self.export.Name@ - Python wrapper
62
//===========================================================================
63

64
/** The python export class for @self.export.Twin@
65
 */
66
class @self.export.Namespace.replace("::","_")@Export @self.export.Name@ : public @self.export.FatherNamespace@::@self.export.Father@
67
{
68
protected:
69
    ~@self.export.Name@() override;
70

71
public:
72
    static PyTypeObject   Type;
73
    static PyMethodDef    Methods[];
74
+ if (self.export.NumberProtocol):
75
    static PyNumberMethods Number[];
76
-
77
+ if (self.export.Sequence):
78
    static PySequenceMethods Sequence[];
79
    static PyMappingMethods Mapping[];
80
-
81
+ if (self.export.RichCompare):
82
    static PyObject * richCompare(PyObject *v, PyObject *w, int op);
83
-
84
+ if (self.export.DescriptorGetter):
85
    static PyObject* descriptorGetter(PyObject* self, PyObject* obj, PyObject* type);
86
-
87
+ if (self.export.DescriptorSetter):
88
    static int descriptorSetter(PyObject* self, PyObject* obj, PyObject* value);
89
-
90
    static PyGetSetDef    GetterSetter[];
91
    PyTypeObject *GetType() override {return &Type;}
92

93
public:
94
    @self.export.Name@(@self.export.TwinPointer@ *pcObject, PyTypeObject *T = &Type);
95
    static PyObject *PyMake(PyTypeObject *, PyObject *, PyObject *);
96
    int PyInit(PyObject* args, PyObject*k) override;
97

98
+ if (self.export.Initialization):
99
    int initialization();
100
    int finalization();
101
-
102

103
    using PointerType = @self.export.TwinPointer@*;
104

105
    PyObject *_repr() override;        // the representation
106
    std::string representation() const;
107

108
    /** @name callbacks and implementers for the python object methods */
109
    //@{
110
+ for i in self.export.Methode:
111
+ if i.Keyword:
112
    /// callback for the @i.Name@() method
113
    static PyObject * staticCallback_@i.Name@ (PyObject *self, PyObject *args, PyObject *kwd);
114
+ if i.Static:
115
    /// implementer for the @i.Name@() method
116
    static PyObject*  @i.Name@(PyObject *args, PyObject *kwd);
117
= elif i.Class:
118
    /// implementer for the @i.Name@() method
119
    static PyObject*  @i.Name@(PyObject *self, PyObject *args, PyObject *kwd);
120
= else:
121
    /// implementer for the @i.Name@() method
122
    PyObject*  @i.Name@(PyObject *args, PyObject *kwd);
123
-
124
= elif i.NoArgs:
125
    /// callback for the @i.Name@() method
126
    static PyObject * staticCallback_@i.Name@ (PyObject *self, PyObject *args);
127
+ if i.Static:
128
    /// implementer for the @i.Name@() method
129
    static PyObject*  @i.Name@();
130
= elif i.Class:
131
    /// implementer for the @i.Name@() method
132
    static PyObject*  @i.Name@(PyObject *self);
133
= else:
134
    /// implementer for the @i.Name@() method
135
    PyObject*  @i.Name@();
136
-
137
= else:
138
    /// callback for the @i.Name@() method
139
    static PyObject * staticCallback_@i.Name@ (PyObject *self, PyObject *args);
140
+ if i.Static:
141
    /// implementer for the @i.Name@() method
142
    static PyObject*  @i.Name@(PyObject *args);
143
= elif i.Class:
144
    /// implementer for the @i.Name@() method
145
    static PyObject*  @i.Name@(PyObject *self, PyObject *args);
146
= else:
147
    /// implementer for the @i.Name@() method
148
    PyObject*  @i.Name@(PyObject *args);
149
-
150
-
151
-
152
    //@}
153

154
+ if (self.export.NumberProtocol):
155
    /** @name callbacks and implementers for the python object number protocol */
156
    //@{
157
    /// callback for the number_add_handler
158
    static PyObject * number_add_handler (PyObject *self, PyObject *other);
159
    /// callback for the number_subtract_handler
160
    static PyObject * number_subtract_handler (PyObject *self, PyObject *other);
161
    /// callback for the number_multiply_handler
162
    static PyObject * number_multiply_handler (PyObject *self, PyObject *other);
163
    /// callback for the number_divide_handler
164
    static PyObject * number_divide_handler (PyObject *self, PyObject *other);
165
    /// callback for the number_remainder_handler
166
    static PyObject * number_remainder_handler (PyObject *self, PyObject *other);
167
    /// callback for the number_divmod_handler
168
    static PyObject * number_divmod_handler (PyObject *self, PyObject *other);
169
    /// callback for the number_power_handler
170
    static PyObject * number_power_handler (PyObject *self, PyObject *other, PyObject *modulo);
171
    /// callback for the number_negative_handler
172
    static PyObject * number_negative_handler (PyObject *self);
173
    /// callback for the number_positive_handler
174
    static PyObject * number_positive_handler (PyObject *self);
175
    /// callback for the number_absolute_handler
176
    static PyObject * number_absolute_handler (PyObject *self);
177
    /// callback for the number_nonzero_handler
178
    static int number_nonzero_handler (PyObject *self);
179
    /// callback for the number_invert_handler
180
    static PyObject * number_invert_handler (PyObject *self);
181
    /// callback for the number_lshift_handler
182
    static PyObject * number_lshift_handler (PyObject *self, PyObject *other);
183
    /// callback for the number_rshift_handler
184
    static PyObject * number_rshift_handler (PyObject *self, PyObject *other);
185
    /// callback for the number_and_handler
186
    static PyObject * number_and_handler (PyObject *self, PyObject *other);
187
    /// callback for the number_xor_handler
188
    static PyObject * number_xor_handler (PyObject *self, PyObject *other);
189
    /// callback for the number_or_handler
190
    static PyObject * number_or_handler (PyObject *self, PyObject *other);
191
    /// callback for the number_int_handler
192
    static PyObject * number_int_handler (PyObject *self);
193
    /// callback for the number_float_handler
194
    static PyObject * number_float_handler (PyObject *self);
195
    //@}
196
-
197
+ if (self.export.Sequence):
198
    /** @name callbacks and implementers for the python object sequence protocol */
199
    //@{
200
+ if (self.export.Sequence.sq_length):
201
    static Py_ssize_t sequence_length(PyObject *);
202
-
203
+ if (self.export.Sequence.sq_concat):
204
    static PyObject* sequence_concat(PyObject *, PyObject *);
205
-
206
+ if (self.export.Sequence.sq_repeat):
207
    static PyObject * sequence_repeat(PyObject *, Py_ssize_t);
208
-
209
+ if (self.export.Sequence.sq_item):
210
    static PyObject * sequence_item(PyObject *, Py_ssize_t);
211
-
212
+ if (self.export.Sequence.mp_subscript):
213
    static PyObject * mapping_subscript(PyObject *, PyObject *);
214
-
215
+ if (self.export.Sequence.sq_ass_item):
216
    static int sequence_ass_item(PyObject *, Py_ssize_t, PyObject *);
217
-
218
+ if (self.export.Sequence.mp_ass_subscript):
219
    static int mapping_ass_subscript(PyObject *, PyObject *, PyObject *);
220
-
221
+ if (self.export.Sequence.sq_contains):
222
    static int sequence_contains(PyObject *, PyObject *);
223
-
224
+ if (self.export.Sequence.sq_inplace_concat):
225
    static PyObject* sequence_inplace_concat(PyObject *, PyObject *);
226
-
227
+ if (self.export.Sequence.sq_inplace_repeat):
228
    static PyObject * sequence_inplace_repeat(PyObject *, Py_ssize_t);
229
-
230
    //@}
231
-
232

233
    /** @name callbacks and implementers for the python object attributes */
234
    //@{
235
+ for i in self.export.Attribute:
236
    ///getter callback for the @i.Name@ attribute
237
    static PyObject * staticCallback_get@i.Name@ (PyObject *self, void *closure);
238
    /// getter for the @i.Name@ attribute
239
    Py::@i.Parameter.Type@ get@i.Name@() const;
240
    /// setter callback for the @i.Name@ attribute
241
    static int staticCallback_set@i.Name@ (PyObject *self, PyObject *value, void *closure);
242
+ if (i.ReadOnly):
243
    // no setter method,  @i.Name@ is read only!
244
= else:
245
    /// setter for the @i.Name@ attribute
246
    void set@i.Name@(Py::@i.Parameter.Type@ arg);
247
-
248
-
249
    //@}
250

251
+ if(self.export.CustomAttributes is not None):
252
    /// getter method for special attributes (e.g. dynamic ones)
253
    PyObject *getCustomAttributes(const char* attr) const;
254
    /// setter for special attributes (e.g. dynamic ones)
255
    /// Output: Success=1, Failure=-1, Ignore=0
256
    int setCustomAttributes(const char* attr, PyObject *obj);
257
    PyObject *_getattr(const char *attr) override;              // __getattr__ function
258
    int _setattr(const char *attr, PyObject *value) override;   // __setattr__ function
259
-
260

261
    /// getter for the object handled by this class
262
    @self.export.TwinPointer@ *get@self.export.Twin@Ptr() const;
263

264
+ if(self.export.ClassDeclarations != ""):
265
    /** @name additional declarations and methods for the wrapper class */
266
    //@{
267
@self.export.ClassDeclarations@
268
    //@}
269
-
270
};
271

272
@"}"*len(self.export.Namespace.split("::"))@  //namespace @self.export.Namespace@
273

274
#endif  // @self.export.Namespace.upper().replace("::", "_")@_@self.export.Name.upper()@_H
275

276
"""
277

278
    TemplateModule = """
279
// This file is generated by src/Tools/generateTemplates/templateClassPyExport.py out of the .XML file
280
// Every change you make here gets lost in the next full rebuild!
281
// This File is normally built as an include in @self.export.Name@Imp.cpp! It's not intended to be in a project!
282

283
#include <boost/filesystem/path.hpp>
284
#include <boost/filesystem/operations.hpp>
285
#include <boost/filesystem/exception.hpp>
286
#include <Base/PyObjectBase.h>
287
#include <Base/Console.h>
288
#include <Base/Exception.h>
289
#include <CXX/Objects.hxx>
290

291
#if defined(__clang__)
292
# pragma clang diagnostic push
293
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
294
#endif
295

296
using Base::streq;
297
using namespace @self.export.Namespace@;
298

299
/// Type structure of @self.export.Name@
300
PyTypeObject @self.export.Name@::Type = {
301
    PyVarObject_HEAD_INIT(&PyType_Type,0)
302
+ if (self.export.PythonName):
303
    "@self.export.PythonName@",     /*tp_name*/
304
= else:
305
    "@self.export.Namespace@.@self.export.Twin@",     /*tp_name*/
306
-
307
    sizeof(@self.export.Name@),                       /*tp_basicsize*/
308
    0,                                                /*tp_itemsize*/
309
    /* methods */
310
    PyDestructor,                                     /*tp_dealloc*/
311
#if PY_VERSION_HEX >= 0x03080000
312
    0,                                                /*tp_vectorcall_offset*/
313
#else
314
    nullptr,                                          /*tp_print*/
315
#endif
316
    nullptr,                                          /*tp_getattr*/
317
    nullptr,                                          /*tp_setattr*/
318
    nullptr,                                          /*tp_compare*/
319
    __repr,                                           /*tp_repr*/
320
+ if (self.export.NumberProtocol):
321
    @self.export.Namespace@::@self.export.Name@::Number,      /*tp_as_number*/
322
= else:
323
    nullptr,                                          /*tp_as_number*/
324
-
325
+ if (self.export.Sequence):
326
    @self.export.Namespace@::@self.export.Name@::Sequence,      /*tp_as_sequence*/
327
    @self.export.Namespace@::@self.export.Name@::Mapping,       /*tp_as_mapping*/
328
= else:
329
    nullptr,                                          /*tp_as_sequence*/
330
    nullptr,                                          /*tp_as_mapping*/
331
-
332
    nullptr,                                          /*tp_hash*/
333
    nullptr,                                          /*tp_call */
334
    nullptr,                                          /*tp_str  */
335
    __getattro,                                       /*tp_getattro*/
336
    __setattro,                                       /*tp_setattro*/
337
    /* --- Functions to access object as input/output buffer ---------*/
338
    nullptr,                                          /* tp_as_buffer */
339
    /* --- Flags to define presence of optional/expanded features */
340
    Py_TPFLAGS_BASETYPE|Py_TPFLAGS_DEFAULT,        /*tp_flags */
341
    "@escapeString(self.export.Documentation.UserDocu, indent=4)@",           /*tp_doc */
342
    nullptr,                                          /*tp_traverse */
343
    nullptr,                                          /*tp_clear */
344
+ if (self.export.RichCompare):
345
    @self.export.Namespace@::@self.export.Name@::richCompare,      /*tp_richcompare*/
346
= else:
347
    nullptr,                                          /*tp_richcompare */
348
-
349
    0,                                                /*tp_weaklistoffset */
350
    nullptr,                                          /*tp_iter */
351
    nullptr,                                          /*tp_iternext */
352
    @self.export.Namespace@::@self.export.Name@::Methods,                     /*tp_methods */
353
    nullptr,                                          /*tp_members */
354
    @self.export.Namespace@::@self.export.Name@::GetterSetter,                     /*tp_getset */
355
    &@self.export.FatherNamespace@::@self.export.Father@::Type,                        /*tp_base */
356
    nullptr,                                          /*tp_dict */
357
+ if (self.export.DescriptorGetter):
358
    @self.export.Namespace@::@self.export.Name@::descriptorGetter,                       /*tp_descr_get */
359
= else:
360
    nullptr,                                          /*tp_descr_get */
361
-
362
+ if (self.export.DescriptorSetter):
363
    @self.export.Namespace@::@self.export.Name@::descriptorSetter,                       /*tp_descr_set */
364
= else:
365
    nullptr,                                          /*tp_descr_set */
366
-
367
    0,                                                /*tp_dictoffset */
368
    __PyInit,                                         /*tp_init */
369
    nullptr,                                          /*tp_alloc */
370
    @self.export.Namespace@::@self.export.Name@::PyMake,/*tp_new */
371
    nullptr,                                          /*tp_free   Low-level free-memory routine */
372
    nullptr,                                          /*tp_is_gc  For PyObject_IS_GC */
373
    nullptr,                                          /*tp_bases */
374
    nullptr,                                          /*tp_mro    method resolution order */
375
    nullptr,                                          /*tp_cache */
376
    nullptr,                                          /*tp_subclasses */
377
    nullptr,                                          /*tp_weaklist */
378
    nullptr,                                          /*tp_del */
379
    0,                                                /*tp_version_tag */
380
    nullptr                                           /*tp_finalize */
381
#if PY_VERSION_HEX >= 0x03090000
382
    ,nullptr                                          /*tp_vectorcall */
383
#if PY_VERSION_HEX >= 0x030c0000
384
    ,0                                                /*tp_watched */
385
#endif
386
#elif PY_VERSION_HEX >= 0x03080000
387
    ,nullptr                                          /*tp_vectorcall */
388
    /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
389
    ,nullptr                                          /*tp_print */
390
#endif
391
};
392

393
/// Methods structure of @self.export.Name@
394
PyMethodDef @self.export.Name@::Methods[] = {
395
+ for i in self.export.Methode:
396
    {"@i.Name@",
397
+ if i.Keyword:
398
+ if i.Class:
399
        reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
400
        METH_VARARGS|METH_KEYWORDS|METH_CLASS,
401
= elif i.Static:
402
        reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
403
        METH_VARARGS|METH_KEYWORDS|METH_STATIC,
404
= else:
405
        reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
406
        METH_VARARGS|METH_KEYWORDS,
407
-
408
= elif i.NoArgs:
409
+ if i.Class:
410
        reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
411
        METH_NOARGS|METH_CLASS,
412
= elif i.Static:
413
        reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
414
        METH_NOARGS|METH_STATIC,
415
= else:
416
        reinterpret_cast<PyCFunction>( staticCallback_@i.Name@ ),
417
        METH_NOARGS,
418
-
419
= elif i.Class:
420
        reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
421
        METH_VARARGS|METH_CLASS,
422
= elif i.Static:
423
        reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
424
        METH_VARARGS|METH_STATIC,
425
= else:
426
        reinterpret_cast<PyCFunction>( staticCallback_@i.Name@ ),
427
        METH_VARARGS,
428
-
429
        "@escapeString(i.Documentation.UserDocu, indent=8)@"
430
    },
431
-
432
    {nullptr, nullptr, 0, nullptr}		/* Sentinel */
433
};
434

435
+ if (self.export.NumberProtocol):
436
PyNumberMethods @self.export.Name@::Number[] = { {
437
    number_add_handler,
438
    number_subtract_handler,
439
    number_multiply_handler,
440
    number_remainder_handler,
441
    number_divmod_handler,
442
    number_power_handler,
443
    number_negative_handler,
444
    number_positive_handler,
445
    number_absolute_handler,
446
    number_nonzero_handler,
447
    number_invert_handler,
448
    number_lshift_handler,
449
    number_rshift_handler,
450
    number_and_handler,
451
    number_xor_handler,
452
    number_or_handler,
453
    number_int_handler,
454
    nullptr,
455
    number_float_handler,
456
    nullptr,    /*nb_inplace_add*/
457
    nullptr,    /*nb_inplace_subtract*/
458
    nullptr,    /*nb_inplace_multiply*/
459
    nullptr,    /*nb_inplace_remainder*/
460
    nullptr,    /*nb_inplace_power*/
461
    nullptr,    /*nb_inplace_lshift*/
462
    nullptr,    /*nb_inplace_rshift*/
463
    nullptr,    /*nb_inplace_and*/
464
    nullptr,    /*nb_inplace_xor*/
465
    nullptr,    /*nb_inplace_or*/
466
    nullptr,    /*nb_floor_divide*/
467
    number_divide_handler,    /*nb_true_divide*/
468
    nullptr,    /*nb_inplace_floor_divide*/
469
    nullptr,    /*nb_inplace_true_divide*/
470
    nullptr     /*nb_index*/
471
   ,nullptr     /*nb_matrix_multiply*/
472
   ,nullptr     /*nb_inplace_matrix_multiply*/
473
} };
474
-
475

476
+ if (self.export.Sequence):
477
PySequenceMethods @self.export.Name@::Sequence[] = { {
478
+ if (self.export.Sequence.sq_length):
479
    sequence_length,
480
= else:
481
    nullptr,
482
-
483
+ if (self.export.Sequence.sq_concat):
484
    sequence_concat,
485
= else:
486
    nullptr,
487
-
488
+ if (self.export.Sequence.sq_repeat):
489
    sequence_repeat,
490
= else:
491
    nullptr,
492
-
493
+ if (self.export.Sequence.sq_item):
494
    sequence_item,
495
= else:
496
    nullptr,
497
-
498
    nullptr,
499
+ if (self.export.Sequence.sq_ass_item):
500
    sequence_ass_item,
501
= else:
502
    nullptr,
503
-
504
    nullptr,
505
+ if (self.export.Sequence.sq_contains):
506
    sequence_contains,
507
= else:
508
    nullptr,
509
-
510
+ if (self.export.Sequence.sq_inplace_concat):
511
    sequence_inplace_concat,
512
= else:
513
    nullptr,
514
-
515
+ if (self.export.Sequence.sq_inplace_repeat):
516
    sequence_inplace_repeat,
517
= else:
518
    nullptr
519
-
520
} };
521

522
PyMappingMethods @self.export.Name@::Mapping[] = { {
523
+ if (self.export.Sequence.sq_length):
524
    sequence_length,
525
= else:
526
    nullptr,
527
-
528
+ if (self.export.Sequence.mp_subscript):
529
    mapping_subscript,
530
= else:
531
    nullptr,
532
-
533
+ if (self.export.Sequence.mp_ass_subscript):
534
    mapping_ass_subscript,
535
= else:
536
    nullptr,
537
-
538
} };
539
-
540

541
/// Attribute structure of @self.export.Name@
542
PyGetSetDef @self.export.Name@::GetterSetter[] = {
543
+ for i in self.export.Attribute:
544
    {"@i.Name@",
545
        (getter) staticCallback_get@i.Name@,
546
        (setter) staticCallback_set@i.Name@,
547
        "@escapeString(i.Documentation.UserDocu, indent=8)@",
548
        nullptr
549
    },
550
-
551
    {nullptr, nullptr, nullptr, nullptr, nullptr}		/* Sentinel */
552
};
553

554
+ for i in self.export.Methode:
555
// @i.Name@() callback and implementer
556
// PyObject*  @self.export.Name@::@i.Name@(PyObject *args){};
557
// has to be implemented in @self.export.Name@Imp.cpp
558
+ if i.Keyword:
559
PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject *args, PyObject * kwd)
560
= elif i.NoArgs:
561
PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject * Py_UNUSED(args))
562
= else:
563
PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject *args)
564
-
565
{
566
+ if not i.Static and not i.Class:
567
    // make sure that not a null pointer is passed
568
    if (!self) {
569
        PyErr_SetString(PyExc_TypeError, "descriptor '@i.Name@' of '@self.export.Namespace@.@self.export.Twin@' object needs an argument");
570
        return nullptr;
571
    }
572

573
    // test if twin object isn't already deleted
574
    if (!static_cast<PyObjectBase*>(self)->isValid()) {
575
        PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
576
        return nullptr;
577
    }
578

579
+   if (not i.Const):
580
    // test if object is set Const
581
    if (static_cast<PyObjectBase*>(self)->isConst()) {
582
        PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
583
        return nullptr;
584
    }
585
-
586

587
-
588
    try { // catches all exceptions coming up from c++ and generate a python exception
589
+ if i.Keyword:
590
+ if i.Static:
591
        (void)self;
592
        PyObject* ret = @self.export.Name@::@i.Name@(args, kwd);
593
= elif i.Class:
594
        PyObject* ret = @self.export.Name@::@i.Name@(self, args, kwd);
595
= else:
596
        PyObject* ret = static_cast<@self.export.Name@*>(self)->@i.Name@(args, kwd);
597
-
598
= elif i.NoArgs:
599
+ if i.Static:
600
        (void)self;
601
        PyObject* ret = @self.export.Name@::@i.Name@();
602
= elif i.Class:
603
        PyObject* ret = @self.export.Name@::@i.Name@(self);
604
= else:
605
        PyObject* ret = static_cast<@self.export.Name@*>(self)->@i.Name@();
606
-
607
= else:
608
+ if i.Static:
609
        (void)self;
610
        PyObject* ret = @self.export.Name@::@i.Name@(args);
611
= elif i.Class:
612
        PyObject* ret = @self.export.Name@::@i.Name@(self, args);
613
= else:
614
        PyObject* ret = static_cast<@self.export.Name@*>(self)->@i.Name@(args);
615
-
616
-
617
+ if not i.Static and not i.Class:
618
+   if (not i.Const):
619
        if (ret != nullptr)
620
            static_cast<@self.export.Name@*>(self)->startNotify();
621
-
622
-
623
        return ret;
624
    } // Please sync the following catch implementation with PY_CATCH
625
    catch(Base::Exception &e)
626
    {
627
        auto pye = e.getPyExceptionType();
628
        if(!pye)
629
            pye = Base::PyExc_FC_GeneralError;
630
        PyErr_SetObject(pye, e.getPyObject());
631
        return nullptr;
632
    }
633
    catch(const std::exception &e)
634
    {
635
        PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
636
        return nullptr;
637
    }
638
    catch(const Py::Exception&)
639
    {
640
        // The exception text is already set
641
        return nullptr;
642
    }
643
#ifndef DONT_CATCH_CXX_EXCEPTIONS
644
    catch(...)
645
    {
646
        PyErr_SetString(Base::PyExc_FC_GeneralError, "Unknown C++ exception");
647
        return nullptr;
648
    }
649
#endif
650
}
651

652
-
653
+ for i in self.export.Attribute:
654
// @i.Name@() callback and implementer
655
// PyObject*  @self.export.Name@::@i.Name@(PyObject *args){};
656
// has to be implemented in @self.export.Name@Imp.cpp
657
PyObject * @self.export.Name@::staticCallback_get@i.Name@ (PyObject *self, void * /*closure*/)
658
{
659
    if (!static_cast<PyObjectBase*>(self)->isValid()){
660
        PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
661
        return nullptr;
662
    }
663

664
    try {
665
        return Py::new_reference_to(static_cast<@self.export.Name@*>(self)->get@i.Name@());
666
    } catch (const Py::Exception&) {
667
        // The exception text is already set
668
        return nullptr;
669
    } catch (...) {
670
        PyErr_SetString(Base::PyExc_FC_GeneralError, "Unknown exception while reading attribute '@i.Name@' of object '@self.export.Twin@'");
671
        return nullptr;
672
    }
673
}
674

675
+ if (i.ReadOnly):
676
int @self.export.Name@::staticCallback_set@i.Name@ (PyObject *self, PyObject * /*value*/, void * /*closure*/)
677
{
678
    if (!static_cast<PyObjectBase*>(self)->isValid()){
679
        PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
680
        return -1;
681
    }
682

683
    PyErr_SetString(PyExc_AttributeError, "Attribute '@i.Name@' of object '@self.export.Twin@' is read-only");
684
    return -1;
685
}
686
= else:
687
int @self.export.Name@::staticCallback_set@i.Name@ (PyObject *self, PyObject *value, void * /*closure*/)
688
{
689
    if (!static_cast<PyObjectBase*>(self)->isValid()){
690
        PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
691
        return -1;
692
    }
693
    if (static_cast<PyObjectBase*>(self)->isConst()){
694
        PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
695
        return -1;
696
    }
697

698
    try {
699
+ if (i.Parameter.Type == "Float"):
700
        static_cast<@self.export.Name@*>(self)->set@i.Name@(Py::@i.Parameter.Type@(PyNumber_Float(value),true));
701
= else:
702
        static_cast<@self.export.Name@*>(self)->set@i.Name@(Py::@i.Parameter.Type@(value,false));
703
-
704
        return 0;
705
    } catch (const Py::Exception&) {
706
        // The exception text is already set
707
        return -1;
708
    } catch (...) {
709
        PyErr_SetString(Base::PyExc_FC_GeneralError, "Unknown exception while writing attribute '@i.Name@' of object '@self.export.Twin@'");
710
        return -1;
711
    }
712
}
713
-
714

715
-
716

717

718

719
//--------------------------------------------------------------------------
720
// Constructor
721
//--------------------------------------------------------------------------
722
@self.export.Name@::@self.export.Name@(@self.export.TwinPointer@ *pcObject, PyTypeObject *T)
723
    : @self.export.Father@(static_cast<@self.export.Father@::PointerType>(pcObject), T)
724
{
725
+ if (self.export.Reference):
726
    pcObject->ref();
727
-
728
+ if (self.export.Initialization):
729
    initialization();
730
-
731
+ if (self.export.DisableNotify):
732
    this->setShouldNotify(false);
733
-
734
}
735

736
+ if not (self.export.Constructor):
737
PyObject *@self.export.Name@::PyMake(PyTypeObject* /*type*/, PyObject* /*args*/, PyObject* /*kwds*/)
738
{
739
    // never create such objects with the constructor
740
    PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of '@self.export.Name@'.");
741

742
    return nullptr;
743
}
744

745
int @self.export.Name@::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
746
{
747
    return 0;
748
}
749
-
750

751
//--------------------------------------------------------------------------
752
// destructor
753
//--------------------------------------------------------------------------
754
@self.export.Name@::~@self.export.Name@()                                // Everything handled in parent
755
{
756
+ if (self.export.Reference):
757
    get@self.export.Twin@Ptr()->unref();
758
-
759
+ if (self.export.Delete):
760
    // delete the handled object when the PyObject dies
761
    @self.export.Name@::PointerType ptr = static_cast<@self.export.Name@::PointerType>(_pcTwinPointer);
762
    delete ptr;
763
-
764
+ if (self.export.Initialization):
765
    finalization();
766
-
767
}
768

769
//--------------------------------------------------------------------------
770
// @self.export.Name@ representation
771
//--------------------------------------------------------------------------
772
PyObject *@self.export.Name@::_repr()
773
{
774
    return Py_BuildValue("s", representation().c_str());
775
}
776

777
+ if(self.export.CustomAttributes is not None):
778
//--------------------------------------------------------------------------
779
// @self.export.Name@ Attributes
780
//--------------------------------------------------------------------------
781
PyObject *@self.export.Name@::_getattr(const char *attr)			// __getattr__ function: note only need to handle new state
782
{
783
    try {
784
        // getter method for special Attributes (e.g. dynamic ones)
785
        PyObject *r = getCustomAttributes(attr);
786
        if(r) return r;
787
    } // Please sync the following catch implementation with PY_CATCH
788
    catch(Base::Exception &e)
789
    {
790
        auto pye = e.getPyExceptionType();
791
        if(!pye)
792
            pye = Base::PyExc_FC_GeneralError;
793
        PyErr_SetObject(pye, e.getPyObject());
794
        return nullptr;
795
    }
796
    catch(const std::exception &e)
797
    {
798
        PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
799
        return nullptr;
800
    }
801
    catch(const Py::Exception&)
802
    {
803
        // The exception text is already set
804
        return nullptr;
805
    }
806
#ifndef DONT_CATCH_CXX_EXCEPTIONS
807
    catch(...)
808
    {
809
        PyErr_SetString(Base::PyExc_FC_GeneralError,"Unknown C++ exception");
810
        return nullptr;
811
    }
812
#endif
813

814
    PyMethodDef *ml = Methods;
815
    for (; ml->ml_name != nullptr; ml++) {
816
        if (attr[0] == ml->ml_name[0] &&
817
            strcmp(attr+1, ml->ml_name+1) == 0)
818
            return PyCFunction_New(ml, this);
819
    }
820

821
    PyErr_Clear();
822
    return @self.export.Father@::_getattr(attr);
823
}
824

825
int @self.export.Name@::_setattr(const char *attr, PyObject *value) // __setattr__ function: note only need to handle new state
826
{
827
    try {
828
        // setter for special Attributes (e.g. dynamic ones)
829
        int r = setCustomAttributes(attr, value);
830
        // r = 1: handled
831
        // r = -1: error
832
        // r = 0: ignore
833
        if (r == 1)
834
            return 0;
835
        else if (r == -1)
836
            return -1;
837
    } // Please sync the following catch implementation with PY_CATCH
838
    catch(Base::Exception &e)
839
    {
840
        auto pye = e.getPyExceptionType();
841
        if(!pye)
842
            pye = Base::PyExc_FC_GeneralError;
843
        PyErr_SetObject(pye, e.getPyObject());
844
        return -1;
845
    }
846
    catch(const std::exception &e)
847
    {
848
        PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
849
        return -1;
850
    }
851
    catch(const Py::Exception&)
852
    {
853
        // The exception text is already set
854
        return -1;
855
    }
856
#ifndef DONT_CATCH_CXX_EXCEPTIONS
857
    catch(...)
858
    {
859
        PyErr_SetString(Base::PyExc_FC_GeneralError, "Unknown C++ exception");
860
        return -1;
861
    }
862
#endif
863

864
    return @self.export.Father@::_setattr(attr, value);
865
}
866
-
867

868
@self.export.TwinPointer@ *@self.export.Name@::get@self.export.Twin@Ptr() const
869
{
870
    return static_cast<@self.export.TwinPointer@ *>(_pcTwinPointer);
871
}
872

873
#if defined(__clang__)
874
# pragma clang diagnostic pop
875
#endif
876

877
#if 0
878
/* From here on come the methods you have to implement, but NOT in this module. Implement in @self.export.Name@Imp.cpp! This prototypes
879
 * are just for convenience when you add a new method.
880
 */
881

882
+ if (self.export.Constructor):
883
PyObject *@self.export.Name@::PyMake(PyTypeObject* /*type*/, PyObject* /*args*/, PyObject* /*kwds*/)
884
{
885
    // create a new instance of @self.export.Name@ and the Twin object
886
    return new @self.export.Name@(new @self.export.TwinPointer@);
887
}
888

889
// constructor method
890
int @self.export.Name@::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
891
{
892
    return 0;
893
}
894
-
895

896
+ if (self.export.Initialization):
897
int @self.export.Name@::initialization()
898
{
899
    return 0;
900
}
901
int @self.export.Name@::finalization()
902
{
903
    return 0;
904
}
905
-
906

907
// returns a string which represents the object e.g. when printed in python
908
std::string @self.export.Name@::representation() const
909
{
910
    return {"<@self.export.Twin@ object>"};
911
}
912
+ for i in self.export.Methode:
913

914
+ if i.Keyword:
915
+ if i.Class:
916
PyObject* @self.export.Name@::@i.Name@(PyObject *self, PyObject *args, PyObject *kwds)
917
= else:
918
PyObject* @self.export.Name@::@i.Name@(PyObject *args, PyObject *kwds)
919
-
920
= elif i.NoArgs:
921
+ if i.Class:
922
PyObject* @self.export.Name@::@i.Name@(PyObject *self)
923
= else:
924
PyObject* @self.export.Name@::@i.Name@()
925
-
926
= else:
927
+ if i.Class:
928
PyObject* @self.export.Name@::@i.Name@(PyObject *self, PyObject *args)
929
= else:
930
PyObject* @self.export.Name@::@i.Name@(PyObject *args)
931
-
932
-
933
{
934
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
935
    return nullptr;
936
}
937
-
938

939
+ if (self.export.NumberProtocol):
940
PyObject* @self.export.Name@::number_add_handler(PyObject* /*self*/, PyObject* /*other*/)
941
{
942
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
943
    return nullptr;
944
}
945

946
PyObject* @self.export.Name@::number_subtract_handler(PyObject* /*self*/, PyObject* /*other*/)
947
{
948
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
949
    return nullptr;
950
}
951

952
PyObject* @self.export.Name@::number_multiply_handler(PyObject* /*self*/, PyObject* /*other*/)
953
{
954
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
955
    return nullptr;
956
}
957

958
PyObject * @self.export.Name@::number_divide_handler (PyObject* /*self*/, PyObject* /*other*/)
959
{
960
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
961
    return nullptr;
962
}
963

964
PyObject * @self.export.Name@::number_remainder_handler (PyObject* /*self*/, PyObject* /*other*/)
965
{
966
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
967
    return nullptr;
968
}
969

970
PyObject * @self.export.Name@::number_divmod_handler (PyObject* /*self*/, PyObject* /*other*/)
971
{
972
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
973
    return nullptr;
974
}
975

976
PyObject * @self.export.Name@::number_power_handler (PyObject* /*self*/, PyObject* /*other*/, PyObject* /*modulo*/)
977
{
978
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
979
    return nullptr;
980
}
981

982
PyObject * @self.export.Name@::number_negative_handler (PyObject* /*self*/)
983
{
984
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
985
    return nullptr;
986
}
987

988
PyObject * @self.export.Name@::number_positive_handler (PyObject* /*self*/)
989
{
990
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
991
    return nullptr;
992
}
993

994
PyObject * @self.export.Name@::number_absolute_handler (PyObject* /*self*/)
995
{
996
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
997
    return nullptr;
998
}
999

1000
int @self.export.Name@::number_nonzero_handler (PyObject* /*self*/)
1001
{
1002
    return 1;
1003
}
1004

1005
PyObject * @self.export.Name@::number_invert_handler (PyObject* /*self*/)
1006
{
1007
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1008
    return nullptr;
1009
}
1010

1011
PyObject * @self.export.Name@::number_lshift_handler (PyObject* /*self*/, PyObject* /*other*/)
1012
{
1013
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1014
    return nullptr;
1015
}
1016

1017
PyObject * @self.export.Name@::number_rshift_handler (PyObject* /*self*/, PyObject* /*other*/)
1018
{
1019
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1020
    return nullptr;
1021
}
1022

1023
PyObject * @self.export.Name@::number_and_handler (PyObject* /*self*/, PyObject* /*other*/)
1024
{
1025
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1026
    return nullptr;
1027
}
1028

1029
PyObject * @self.export.Name@::number_xor_handler (PyObject* /*self*/, PyObject* /*other*/)
1030
{
1031
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1032
    return nullptr;
1033
}
1034

1035
PyObject * @self.export.Name@::number_or_handler (PyObject* /*self*/, PyObject* /*other*/)
1036
{
1037
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1038
    return nullptr;
1039
}
1040

1041
int @self.export.Name@::number_coerce_handler (PyObject** /*self*/, PyObject** /*other*/)
1042
{
1043
    return 1;
1044
}
1045

1046
PyObject * @self.export.Name@::number_int_handler (PyObject* /*self*/)
1047
{
1048
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1049
    return nullptr;
1050
}
1051

1052
PyObject * @self.export.Name@::number_long_handler (PyObject* /*self*/)
1053
{
1054
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1055
    return nullptr;
1056
}
1057

1058
PyObject * @self.export.Name@::number_float_handler (PyObject* /*self*/)
1059
{
1060
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1061
    return nullptr;
1062
}
1063

1064
PyObject * @self.export.Name@::number_oct_handler (PyObject* /*self*/)
1065
{
1066
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1067
    return nullptr;
1068
}
1069

1070
PyObject * @self.export.Name@::number_hex_handler (PyObject* /*self*/)
1071
{
1072
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1073
    return nullptr;
1074
}
1075
-
1076
+ if (self.export.Sequence):
1077
+ if (self.export.Sequence.sq_length):
1078

1079
Py_ssize_t @self.export.Name@::sequence_length(PyObject *)
1080
{
1081
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1082
    return -1;
1083
}
1084
-
1085
+ if (self.export.Sequence.sq_concat):
1086

1087
PyObject* @self.export.Name@::sequence_concat(PyObject *, PyObject *)
1088
{
1089
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1090
    return nullptr;
1091
}
1092
-
1093
+ if (self.export.Sequence.sq_repeat):
1094

1095
PyObject * @self.export.Name@::sequence_repeat(PyObject *, Py_ssize_t)
1096
{
1097
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1098
    return nullptr;
1099
}
1100
-
1101
+ if (self.export.Sequence.sq_item):
1102

1103
PyObject * @self.export.Name@::sequence_item(PyObject *, Py_ssize_t)
1104
{
1105
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1106
    return nullptr;
1107
}
1108
-
1109
+ if (self.export.Sequence.mp_subscript):
1110

1111
PyObject * @self.export.Name@::mapping_subscript(PyObject *, PyObject *)
1112
{
1113
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1114
    return nullptr;
1115
}
1116
-
1117
+ if (self.export.Sequence.sq_ass_item):
1118

1119
int @self.export.Name@::sequence_ass_item(PyObject *, Py_ssize_t, PyObject *)
1120
{
1121
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1122
    return -1;
1123
}
1124
-
1125
+ if (self.export.Sequence.mp_ass_subscript):
1126

1127
int @self.export.Name@::mapping_ass_subscript(PyObject *, PyObject *, PyObject *)
1128
{
1129
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1130
    return -1;
1131
}
1132
-
1133
+ if (self.export.Sequence.sq_contains):
1134

1135
int @self.export.Name@::sequence_contains(PyObject *, PyObject *)
1136
{
1137
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1138
    return -1;
1139
}
1140
-
1141
+ if (self.export.Sequence.sq_inplace_concat):
1142

1143
PyObject* @self.export.Name@::sequence_inplace_concat(PyObject *, PyObject *)
1144
{
1145
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1146
    return nullptr;
1147
}
1148
-
1149
+ if (self.export.Sequence.sq_inplace_repeat):
1150

1151
PyObject * @self.export.Name@::sequence_inplace_repeat(PyObject *, Py_ssize_t)
1152
{
1153
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1154
    return nullptr;
1155
}
1156
-
1157
-
1158

1159
+ if (self.export.RichCompare):
1160
PyObject* @self.export.Name@::richCompare(PyObject *v, PyObject *w, int op)
1161
{
1162
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1163
    return nullptr;
1164
}
1165
-
1166
+ for i in self.export.Attribute:
1167

1168
Py::@i.Parameter.Type@ @self.export.Name@::get@i.Name@() const
1169
{
1170
    //return Py::@i.Parameter.Type@();
1171
    throw Py::AttributeError("Not yet implemented");
1172
}
1173
+ if (i.ReadOnly):
1174
= else:
1175

1176
void  @self.export.Name@::set@i.Name@(Py::@i.Parameter.Type@ arg)
1177
{
1178
    throw Py::AttributeError("Not yet implemented");
1179
}
1180
-
1181
-
1182
+ if(self.export.CustomAttributes is not None):
1183

1184
PyObject *@self.export.Name@::getCustomAttributes(const char* /*attr*/) const
1185
{
1186
    return nullptr;
1187
}
1188

1189
int @self.export.Name@::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
1190
{
1191
    return 0;
1192
}
1193
-
1194

1195
+ if (self.export.DescriptorGetter):
1196
PyObject* @self.export.Name@::descriptorGetter(PyObject* self, PyObject* obj, PyObject* type)
1197
{
1198
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1199
    return nullptr;
1200
}
1201
-
1202

1203
+ if (self.export.DescriptorSetter):
1204
int @self.export.Name@::descriptorSetter(PyObject* self, PyObject* obj, PyObject* value)
1205
{
1206
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1207
    return -1;
1208
}
1209
-
1210
#endif
1211

1212

1213
"""
1214

1215
    # Here's the template for the user part of the implementation. This does NOT get overridden if it already exists.
1216
    TemplateImplement = """
1217
#include "PreCompiled.h"
1218

1219
#include "@self.export.Include@"
1220

1221
// inclusion of the generated files (generated out of @self.export.Name@.xml)
1222
#include "@self.export.Name@.h"
1223
#include "@self.export.Name@.cpp"
1224

1225
using namespace @self.export.Namespace@;
1226

1227
// returns a string which represents the object e.g. when printed in python
1228
std::string @self.export.Name@::representation() const
1229
{
1230
    return {"<@self.export.Twin@ object>"};
1231
}
1232

1233
+ if (self.export.Constructor):
1234
PyObject *@self.export.Name@::PyMake(PyTypeObject* /*type*/, PyObject* /*args*/, PyObject* /*kwds*/)
1235
{
1236
    // create a new instance of @self.export.Name@ and the Twin object
1237
    return new @self.export.Name@(new @self.export.TwinPointer@);
1238
}
1239

1240
// constructor method
1241
int @self.export.Name@::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
1242
{
1243
    return 0;
1244
}
1245
-
1246
+ if (self.export.Initialization):
1247
int @self.export.Name@::initialization()
1248
{
1249
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1250
    return 0;
1251
}
1252
int @self.export.Name@::finalization()
1253
{
1254
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1255
    return 0;
1256
}
1257
-
1258

1259
+ for i in self.export.Methode:
1260

1261
+ if i.Keyword:
1262
+ if i.Class:
1263
PyObject* @self.export.Name@::@i.Name@(PyObject * /*self*/, PyObject * /*args*/, PyObject * /*kwds*/)
1264
= else:
1265
PyObject* @self.export.Name@::@i.Name@(PyObject * /*args*/, PyObject * /*kwds*/)
1266
-
1267
= elif i.NoArgs:
1268
+ if i.Class:
1269
PyObject* @self.export.Name@::@i.Name@(PyObject * /*self*/)
1270
= else:
1271
PyObject* @self.export.Name@::@i.Name@()
1272
-
1273
= else:
1274
+ if i.Class:
1275
PyObject* @self.export.Name@::@i.Name@(PyObject * /*self*/, PyObject * /*args*/)
1276
= else:
1277
PyObject* @self.export.Name@::@i.Name@(PyObject * /*args*/)
1278
-
1279
-
1280
{
1281
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1282
    return nullptr;
1283
}
1284
-
1285

1286
+ if (self.export.NumberProtocol):
1287
PyObject* @self.export.Name@::number_add_handler(PyObject *self, PyObject *other)
1288
{
1289
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1290
    return nullptr;
1291
}
1292

1293
PyObject* @self.export.Name@::number_subtract_handler(PyObject *self, PyObject *other)
1294
{
1295
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1296
    return nullptr;
1297
}
1298

1299
PyObject* @self.export.Name@::number_multiply_handler(PyObject *self, PyObject *other)
1300
{
1301
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1302
    return nullptr;
1303
}
1304

1305
PyObject * @self.export.Name@::number_divide_handler (PyObject *self, PyObject *other)
1306
{
1307
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1308
    return nullptr;
1309
}
1310

1311
PyObject * @self.export.Name@::number_remainder_handler (PyObject *self, PyObject *other)
1312
{
1313
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1314
    return nullptr;
1315
}
1316

1317
PyObject * @self.export.Name@::number_divmod_handler (PyObject *self, PyObject *other)
1318
{
1319
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1320
    return nullptr;
1321
}
1322

1323
PyObject * @self.export.Name@::number_power_handler (PyObject *self, PyObject *other, PyObject *modulo)
1324
{
1325
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1326
    return nullptr;
1327
}
1328

1329
PyObject * @self.export.Name@::number_negative_handler (PyObject *self)
1330
{
1331
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1332
    return nullptr;
1333
}
1334

1335
PyObject * @self.export.Name@::number_positive_handler (PyObject *self)
1336
{
1337
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1338
    return nullptr;
1339
}
1340

1341
PyObject * @self.export.Name@::number_absolute_handler (PyObject *self)
1342
{
1343
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1344
    return nullptr;
1345
}
1346

1347
int @self.export.Name@::number_nonzero_handler (PyObject *self)
1348
{
1349
    return 1;
1350
}
1351

1352
PyObject * @self.export.Name@::number_invert_handler (PyObject *self)
1353
{
1354
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1355
    return nullptr;
1356
}
1357

1358
PyObject * @self.export.Name@::number_lshift_handler (PyObject *self, PyObject *other)
1359
{
1360
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1361
    return nullptr;
1362
}
1363

1364
PyObject * @self.export.Name@::number_rshift_handler (PyObject *self, PyObject *other)
1365
{
1366
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1367
    return nullptr;
1368
}
1369

1370
PyObject * @self.export.Name@::number_and_handler (PyObject *self, PyObject *other)
1371
{
1372
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1373
    return nullptr;
1374
}
1375

1376
PyObject * @self.export.Name@::number_xor_handler (PyObject *self, PyObject *other)
1377
{
1378
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1379
    return nullptr;
1380
}
1381

1382
PyObject * @self.export.Name@::number_or_handler (PyObject *self, PyObject *other)
1383
{
1384
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1385
    return nullptr;
1386
}
1387

1388
int @self.export.Name@::number_coerce_handler (PyObject **self, PyObject **other)
1389
{
1390
    return 1;
1391
}
1392

1393
PyObject * @self.export.Name@::number_int_handler (PyObject *self)
1394
{
1395
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1396
    return nullptr;
1397
}
1398

1399
PyObject * @self.export.Name@::number_long_handler (PyObject *self)
1400
{
1401
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1402
    return nullptr;
1403
}
1404

1405
PyObject * @self.export.Name@::number_float_handler (PyObject *self)
1406
{
1407
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1408
    return nullptr;
1409
}
1410

1411
PyObject * @self.export.Name@::number_oct_handler (PyObject *self)
1412
{
1413
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1414
    return nullptr;
1415
}
1416

1417
PyObject * @self.export.Name@::number_hex_handler (PyObject *self)
1418
{
1419
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1420
    return nullptr;
1421
}
1422
-
1423

1424
+ if (self.export.Sequence):
1425
+ if (self.export.Sequence.sq_length):
1426

1427
Py_ssize_t @self.export.Name@::sequence_length(PyObject *)
1428
{
1429
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1430
    return -1;
1431
}
1432
-
1433
+ if (self.export.Sequence.sq_concat):
1434

1435
PyObject* @self.export.Name@::sequence_concat(PyObject *, PyObject *)
1436
{
1437
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1438
    return nullptr;
1439
}
1440
-
1441
+ if (self.export.Sequence.sq_repeat):
1442

1443
PyObject * @self.export.Name@::sequence_repeat(PyObject *, Py_ssize_t)
1444
{
1445
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1446
    return nullptr;
1447
}
1448
-
1449
+ if (self.export.Sequence.sq_item):
1450

1451
PyObject * @self.export.Name@::sequence_item(PyObject *, Py_ssize_t)
1452
{
1453
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1454
    return nullptr;
1455
}
1456
-
1457
+ if (self.export.Sequence.mp_subscript):
1458

1459
PyObject * @self.export.Name@::mapping_subscript(PyObject *, PyObject *)
1460
{
1461
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1462
    return nullptr;
1463
}
1464
-
1465
+ if (self.export.Sequence.sq_ass_item):
1466

1467
int @self.export.Name@::sequence_ass_item(PyObject *, Py_ssize_t, PyObject *)
1468
{
1469
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1470
    return -1;
1471
}
1472
-
1473
+ if (self.export.Sequence.mp_ass_subscript):
1474

1475
int @self.export.Name@::mapping_ass_subscript(PyObject *, PyObject *, PyObject *)
1476
{
1477
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1478
    return -1;
1479
}
1480
-
1481
+ if (self.export.Sequence.sq_contains):
1482

1483
int @self.export.Name@::sequence_contains(PyObject *, PyObject *)
1484
{
1485
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1486
    return -1;
1487
}
1488
-
1489
+ if (self.export.Sequence.sq_inplace_concat):
1490

1491
PyObject* @self.export.Name@::sequence_inplace_concat(PyObject *, PyObject *)
1492
{
1493
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1494
    return nullptr;
1495
}
1496
-
1497
+ if (self.export.Sequence.sq_inplace_repeat):
1498

1499
PyObject * @self.export.Name@::sequence_inplace_repeat(PyObject *, Py_ssize_t)
1500
{
1501
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1502
    return nullptr;
1503
}
1504
-
1505
-
1506

1507
+ if (self.export.RichCompare):
1508
PyObject* @self.export.Name@::richCompare(PyObject *v, PyObject *w, int op)
1509
{
1510
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1511
    return nullptr;
1512
}
1513
-
1514

1515
+ for i in self.export.Attribute:
1516

1517
Py::@i.Parameter.Type@ @self.export.Name@::get@i.Name@() const
1518
{
1519
    //return Py::@i.Parameter.Type@();
1520
    throw Py::AttributeError("Not yet implemented");
1521
}
1522
+ if (i.ReadOnly):
1523
= else:
1524

1525
void @self.export.Name@::set@i.Name@(Py::@i.Parameter.Type@ /*arg*/)
1526
{
1527
    throw Py::AttributeError("Not yet implemented");
1528
}
1529
-
1530
-
1531
+ if(self.export.CustomAttributes is not None):
1532

1533
PyObject *@self.export.Name@::getCustomAttributes(const char* /*attr*/) const
1534
{
1535
    return nullptr;
1536
}
1537

1538
int @self.export.Name@::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
1539
{
1540
    return 0;
1541
}
1542
-
1543

1544
+ if (self.export.DescriptorGetter):
1545
PyObject* @self.export.Name@::descriptorGetter(PyObject* self, PyObject* obj, PyObject* type)
1546
{
1547
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1548
    return nullptr;
1549
}
1550
-
1551

1552
+ if (self.export.DescriptorSetter):
1553
int @self.export.Name@::descriptorSetter(PyObject* self, PyObject* obj, PyObject* value)
1554
{
1555
    PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1556
    return -1;
1557
}
1558
-
1559

1560
"""
1561

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.