Blender  V2.93
BPy_UnaryFunction0DId.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BPy_UnaryFunction0DId.h"
22 
23 #include "../BPy_Convert.h"
24 #include "../Iterator/BPy_Interface0DIterator.h"
25 
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 using namespace Freestyle;
33 
35 
36 //-------------------MODULE INITIALIZATION--------------------------------
37 
39 {
40  if (module == nullptr) {
41  return -1;
42  }
43 
44  if (PyType_Ready(&UnaryFunction0DId_Type) < 0) {
45  return -1;
46  }
47  Py_INCREF(&UnaryFunction0DId_Type);
48  PyModule_AddObject(module, "UnaryFunction0DId", (PyObject *)&UnaryFunction0DId_Type);
49 
50  if (PyType_Ready(&ShapeIdF0D_Type) < 0) {
51  return -1;
52  }
53  Py_INCREF(&ShapeIdF0D_Type);
54  PyModule_AddObject(module, "ShapeIdF0D", (PyObject *)&ShapeIdF0D_Type);
55 
56  return 0;
57 }
58 
59 //------------------------INSTANCE METHODS ----------------------------------
60 
62  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DId`\n"
63  "\n"
64  "Base class for unary functions (functors) that work on\n"
65  ":class:`Interface0DIterator` and return an :class:`Id` object.\n"
66  "\n"
67  ".. method:: __init__()\n"
68  "\n"
69  " Default constructor.\n";
70 
71 static int UnaryFunction0DId___init__(BPy_UnaryFunction0DId *self, PyObject *args, PyObject *kwds)
72 {
73  static const char *kwlist[] = {nullptr};
74 
75  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
76  return -1;
77  }
78  self->uf0D_id = new UnaryFunction0D<Id>();
79  self->uf0D_id->py_uf0D = (PyObject *)self;
80  return 0;
81 }
82 
84 {
85  delete self->uf0D_id;
86  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
87 }
88 
90 {
91  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_id);
92 }
93 
95  PyObject *args,
96  PyObject *kwds)
97 {
98  static const char *kwlist[] = {"it", nullptr};
99  PyObject *obj;
100 
101  if (!PyArg_ParseTupleAndKeywords(
102  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
103  return nullptr;
104  }
105 
106  if (typeid(*(self->uf0D_id)) == typeid(UnaryFunction0D<Id>)) {
107  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
108  return nullptr;
109  }
110  if (self->uf0D_id->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
111  if (!PyErr_Occurred()) {
112  string class_name(Py_TYPE(self)->tp_name);
113  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
114  }
115  return nullptr;
116  }
117  return BPy_Id_from_Id(self->uf0D_id->result);
118 }
119 
120 /*-----------------------BPy_UnaryFunction0DId type definition ------------------------------*/
121 
122 PyTypeObject UnaryFunction0DId_Type = {
123  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DId", /* tp_name */
124  sizeof(BPy_UnaryFunction0DId), /* tp_basicsize */
125  0, /* tp_itemsize */
126  (destructor)UnaryFunction0DId___dealloc__, /* tp_dealloc */
127  0, /* tp_vectorcall_offset */
128  nullptr, /* tp_getattr */
129  nullptr, /* tp_setattr */
130  nullptr, /* tp_reserved */
131  (reprfunc)UnaryFunction0DId___repr__, /* tp_repr */
132  nullptr, /* tp_as_number */
133  nullptr, /* tp_as_sequence */
134  nullptr, /* tp_as_mapping */
135  nullptr, /* tp_hash */
136  (ternaryfunc)UnaryFunction0DId___call__, /* tp_call */
137  nullptr, /* tp_str */
138  nullptr, /* tp_getattro */
139  nullptr, /* tp_setattro */
140  nullptr, /* tp_as_buffer */
141  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
142  UnaryFunction0DId___doc__, /* tp_doc */
143  nullptr, /* tp_traverse */
144  nullptr, /* tp_clear */
145  nullptr, /* tp_richcompare */
146  0, /* tp_weaklistoffset */
147  nullptr, /* tp_iter */
148  nullptr, /* tp_iternext */
149  nullptr, /* tp_methods */
150  nullptr, /* tp_members */
151  nullptr, /* tp_getset */
152  &UnaryFunction0D_Type, /* tp_base */
153  nullptr, /* tp_dict */
154  nullptr, /* tp_descr_get */
155  nullptr, /* tp_descr_set */
156  0, /* tp_dictoffset */
157  (initproc)UnaryFunction0DId___init__, /* tp_init */
158  nullptr, /* tp_alloc */
159  nullptr, /* tp_new */
160 };
161 
163 
164 #ifdef __cplusplus
165 }
166 #endif
PyObject * BPy_Id_from_Id(Id &id)
PyTypeObject Interface0DIterator_Type
PyTypeObject ShapeIdF0D_Type
static void UnaryFunction0DId___dealloc__(BPy_UnaryFunction0DId *self)
static int UnaryFunction0DId___init__(BPy_UnaryFunction0DId *self, PyObject *args, PyObject *kwds)
static PyObject * UnaryFunction0DId___call__(BPy_UnaryFunction0DId *self, PyObject *args, PyObject *kwds)
static char UnaryFunction0DId___doc__[]
int UnaryFunction0DId_Init(PyObject *module)
PyTypeObject UnaryFunction0DId_Type
static PyObject * UnaryFunction0DId___repr__(BPy_UnaryFunction0DId *self)
PyTypeObject UnaryFunction0D_Type
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32