Blender  V3.3
BPy_UnaryFunction1DVoid.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 
9 #include "../BPy_Convert.h"
10 #include "../BPy_IntegrationType.h"
11 #include "../BPy_Interface1D.h"
12 
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 using namespace Freestyle;
22 
24 
25 //-------------------MODULE INITIALIZATION--------------------------------
26 
28 {
29  if (module == nullptr) {
30  return -1;
31  }
32 
33  if (PyType_Ready(&UnaryFunction1DVoid_Type) < 0) {
34  return -1;
35  }
36  Py_INCREF(&UnaryFunction1DVoid_Type);
37  PyModule_AddObject(module, "UnaryFunction1DVoid", (PyObject *)&UnaryFunction1DVoid_Type);
38 
39  if (PyType_Ready(&ChainingTimeStampF1D_Type) < 0) {
40  return -1;
41  }
42  Py_INCREF(&ChainingTimeStampF1D_Type);
43  PyModule_AddObject(module, "ChainingTimeStampF1D", (PyObject *)&ChainingTimeStampF1D_Type);
44 
45  if (PyType_Ready(&IncrementChainingTimeStampF1D_Type) < 0) {
46  return -1;
47  }
49  PyModule_AddObject(
50  module, "IncrementChainingTimeStampF1D", (PyObject *)&IncrementChainingTimeStampF1D_Type);
51 
52  if (PyType_Ready(&TimeStampF1D_Type) < 0) {
53  return -1;
54  }
55  Py_INCREF(&TimeStampF1D_Type);
56  PyModule_AddObject(module, "TimeStampF1D", (PyObject *)&TimeStampF1D_Type);
57 
58  return 0;
59 }
60 
61 //------------------------INSTANCE METHODS ----------------------------------
62 
64  "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVoid`\n"
65  "\n"
66  "Base class for unary functions (functors) working on\n"
67  ":class:`Interface1D`.\n"
68  "\n"
69  ".. method:: __init__()\n"
70  " __init__(integration_type)\n"
71  "\n"
72  " Builds a unary 1D function using either a default constructor\n"
73  " or the integration method given as an argument.\n"
74  "\n"
75  " :arg integration_type: An integration method.\n"
76  " :type integration_type: :class:`IntegrationType`\n";
77 
79  PyObject *args,
80  PyObject *kwds)
81 {
82  static const char *kwlist[] = {"integration", nullptr};
83  PyObject *obj = nullptr;
84 
85  if (!PyArg_ParseTupleAndKeywords(
86  args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) {
87  return -1;
88  }
89 
90  if (!obj) {
91  self->uf1D_void = new UnaryFunction1D_void();
92  }
93  else {
95  }
96 
97  self->uf1D_void->py_uf1D = (PyObject *)self;
98 
99  return 0;
100 }
101 
103 {
104  delete self->uf1D_void;
105  UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
106 }
107 
109 {
110  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_void);
111 }
112 
114  PyObject *args,
115  PyObject *kwds)
116 {
117  static const char *kwlist[] = {"inter", nullptr};
118  PyObject *obj = nullptr;
119 
120  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
121  return nullptr;
122  }
123 
124  if (typeid(*(self->uf1D_void)) == typeid(UnaryFunction1D_void)) {
125  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
126  return nullptr;
127  }
128  if (self->uf1D_void->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
129  if (!PyErr_Occurred()) {
130  string class_name(Py_TYPE(self)->tp_name);
131  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
132  }
133  return nullptr;
134  }
135  Py_RETURN_NONE;
136 }
137 
138 /*----------------------UnaryFunction1DVoid get/setters ----------------------------*/
139 
140 PyDoc_STRVAR(integration_type_doc,
141  "The integration method.\n"
142  "\n"
143  ":type: :class:`IntegrationType`");
144 
145 static PyObject *integration_type_get(BPy_UnaryFunction1DVoid *self, void *UNUSED(closure))
146 {
147  return BPy_IntegrationType_from_IntegrationType(self->uf1D_void->getIntegrationType());
148 }
149 
151  PyObject *value,
152  void *UNUSED(closure))
153 {
154  if (!BPy_IntegrationType_Check(value)) {
155  PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
156  return -1;
157  }
158  self->uf1D_void->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
159  return 0;
160 }
161 
162 static PyGetSetDef BPy_UnaryFunction1DVoid_getseters[] = {
163  {"integration_type",
164  (getter)integration_type_get,
165  (setter)integration_type_set,
166  integration_type_doc,
167  nullptr},
168  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
169 };
170 
171 /*-----------------------BPy_UnaryFunction1DVoid type definition ------------------------------*/
172 
173 PyTypeObject UnaryFunction1DVoid_Type = {
174  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction1DVoid", /* tp_name */
175  sizeof(BPy_UnaryFunction1DVoid), /* tp_basicsize */
176  0, /* tp_itemsize */
177  (destructor)UnaryFunction1DVoid___dealloc__, /* tp_dealloc */
178  0, /* tp_vectorcall_offset */
179  nullptr, /* tp_getattr */
180  nullptr, /* tp_setattr */
181  nullptr, /* tp_reserved */
182  (reprfunc)UnaryFunction1DVoid___repr__, /* tp_repr */
183  nullptr, /* tp_as_number */
184  nullptr, /* tp_as_sequence */
185  nullptr, /* tp_as_mapping */
186  nullptr, /* tp_hash */
187  (ternaryfunc)UnaryFunction1DVoid___call__, /* tp_call */
188  nullptr, /* tp_str */
189  nullptr, /* tp_getattro */
190  nullptr, /* tp_setattro */
191  nullptr, /* tp_as_buffer */
192  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
193  UnaryFunction1DVoid___doc__, /* tp_doc */
194  nullptr, /* tp_traverse */
195  nullptr, /* tp_clear */
196  nullptr, /* tp_richcompare */
197  0, /* tp_weaklistoffset */
198  nullptr, /* tp_iter */
199  nullptr, /* tp_iternext */
200  nullptr, /* tp_methods */
201  nullptr, /* tp_members */
202  BPy_UnaryFunction1DVoid_getseters, /* tp_getset */
203  &UnaryFunction1D_Type, /* tp_base */
204  nullptr, /* tp_dict */
205  nullptr, /* tp_descr_get */
206  nullptr, /* tp_descr_set */
207  0, /* tp_dictoffset */
208  (initproc)UnaryFunction1DVoid___init__, /* tp_init */
209  nullptr, /* tp_alloc */
210  nullptr, /* tp_new */
211 };
212 
214 
215 #ifdef __cplusplus
216 }
217 #endif
#define UNUSED(x)
PyTypeObject ChainingTimeStampF1D_Type
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyTypeObject IncrementChainingTimeStampF1D_Type
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyTypeObject TimeStampF1D_Type
static char UnaryFunction1DVoid___doc__[]
static PyObject * UnaryFunction1DVoid___call__(BPy_UnaryFunction1DVoid *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(integration_type_doc, "The integration method.\n" "\n" ":type: :class:`IntegrationType`")
static PyObject * integration_type_get(BPy_UnaryFunction1DVoid *self, void *UNUSED(closure))
int UnaryFunction1DVoid_Init(PyObject *module)
static int integration_type_set(BPy_UnaryFunction1DVoid *self, PyObject *value, void *UNUSED(closure))
PyTypeObject UnaryFunction1DVoid_Type
static int UnaryFunction1DVoid___init__(BPy_UnaryFunction1DVoid *self, PyObject *args, PyObject *kwds)
static void UnaryFunction1DVoid___dealloc__(BPy_UnaryFunction1DVoid *self)
static PyObject * UnaryFunction1DVoid___repr__(BPy_UnaryFunction1DVoid *self)
static PyGetSetDef BPy_UnaryFunction1DVoid_getseters[]
PyTypeObject UnaryFunction1D_Type
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972