Debian Codegraph @

src/App/FeaturePythonPyImp.h

raw
1 /***************************************************************************
2 * Copyright (c) 2013 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 // clang-format off
24 #ifndef APP_FEATUREPYTHONPYIMP_H
25 #define APP_FEATUREPYTHONPYIMP_H
26
27 #include <Base/BaseClass.h>
28 #include <Base/Interpreter.h>
29 #include <Base/PyObjectBase.h>
30
31 #if defined(__clang__)
32 # pragma clang diagnostic push
33 # pragma clang diagnostic ignored "-Wmissing-field-initializers"
34 #elif defined(__GNUC__) || defined(__GNUG__)
35 # pragma GCC diagnostic push
36 # pragma GCC diagnostic ignored "-Wmissing-field-initializers"
37 #endif
38
39 #define PYTHON_TYPE_DEF(_class_, _subclass_) \
40 class _class_ : public _subclass_ \
41 { \
42 public: \
43 static PyTypeObject Type; \
44 public: \
45 _class_(Base::BaseClass *pcObject, PyTypeObject *T = &Type); \
46 virtual ~_class_(); \
47 };
48
49 #if PY_VERSION_HEX >= 0x030d0000
50 #define PYTHON_TYPE_SLOTS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
51 #elif PY_VERSION_HEX >= 0x030c0000
52 #define PYTHON_TYPE_SLOTS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
53 #else
54 #define PYTHON_TYPE_SLOTS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
55
56 #endif \
57
58 #define PYTHON_TYPE_IMP(_class_, _subclass_) \
59 PyTypeObject _class_::Type = { \
60 PyVarObject_HEAD_INIT(&PyType_Type, 0) \
61 ""#_class_"", \
62 sizeof(_class_), \
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
64 Py_TPFLAGS_BASETYPE|Py_TPFLAGS_DEFAULT, \
65 ""#_class_"", \
66 0, 0, 0, 0, 0, 0, 0, 0, 0, \
67 &_subclass_::Type, \
68 PYTHON_TYPE_SLOTS \
69 }; \
70 _class_::_class_(Base::BaseClass *pcObject, PyTypeObject *T) \
71 : _subclass_(reinterpret_cast<_subclass_::PointerType>(pcObject), T) \
72 { \
73 } \
74 _class_::~_class_() \
75 { \
76 }
77
78 namespace App
79 {
80
81 class Property;
82
83 /**
84 * @author Werner Mayer
85 */
86 template <class FeaturePyT>
87 class FeaturePythonPyT : public FeaturePyT
88 {
89 public:
90 static PyTypeObject Type;
91
92 public:
93 explicit FeaturePythonPyT(Base::BaseClass *pcObject, PyTypeObject *T = &Type);
94 ~FeaturePythonPyT() override;
95
96 /** @name callbacks and implementers for the python object methods */
97 //@{
98 static int __setattro(PyObject *PyObj, PyObject *attro, PyObject *value);
99 //@}
100 PyObject *_getattr(const char *attr) override;
101 int _setattr(const char *attr, PyObject *value) override;
102
103 protected:
104 PyObject * dict_methods;
105
106 private:
107 };
108
109 } //namespace App
110
111 #include "FeaturePythonPyImp.inl"
112
113 #if defined(__clang__)
114 # pragma clang diagnostic pop
115 #elif defined(__GNUC__) || defined(__GNUG__)
116 # pragma GCC diagnostic pop
117 #endif
118
119 #endif // APP_FEATUREPYTHONPYIMP_H
120 // clang-format on