Blender  V2.93
BPy_UnaryFunction0DUnsigned.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 
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(&UnaryFunction0DUnsigned_Type) < 0) {
45  return -1;
46  }
47  Py_INCREF(&UnaryFunction0DUnsigned_Type);
48  PyModule_AddObject(module, "UnaryFunction0DUnsigned", (PyObject *)&UnaryFunction0DUnsigned_Type);
49 
50  if (PyType_Ready(&QuantitativeInvisibilityF0D_Type) < 0) {
51  return -1;
52  }
54  PyModule_AddObject(
55  module, "QuantitativeInvisibilityF0D", (PyObject *)&QuantitativeInvisibilityF0D_Type);
56 
57  return 0;
58 }
59 
60 //------------------------INSTANCE METHODS ----------------------------------
61 
63  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DUnsigned`\n"
64  "\n"
65  "Base class for unary functions (functors) that work on\n"
66  ":class:`Interface0DIterator` and return an int value.\n"
67  "\n"
68  ".. method:: __init__()\n"
69  "\n"
70  " Default constructor.\n";
71 
73  PyObject *args,
74  PyObject *kwds)
75 {
76  static const char *kwlist[] = {nullptr};
77 
78  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
79  return -1;
80  }
81  self->uf0D_unsigned = new UnaryFunction0D<unsigned int>();
82  self->uf0D_unsigned->py_uf0D = (PyObject *)self;
83  return 0;
84 }
85 
87 {
88  delete self->uf0D_unsigned;
89  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
90 }
91 
93 {
94  return PyUnicode_FromFormat(
95  "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_unsigned);
96 }
97 
99  PyObject *args,
100  PyObject *kwds)
101 {
102  static const char *kwlist[] = {"it", nullptr};
103  PyObject *obj;
104 
105  if (!PyArg_ParseTupleAndKeywords(
106  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
107  return nullptr;
108  }
109 
110  if (typeid(*(self->uf0D_unsigned)) == typeid(UnaryFunction0D<unsigned int>)) {
111  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
112  return nullptr;
113  }
114  if (self->uf0D_unsigned->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
115  if (!PyErr_Occurred()) {
116  string class_name(Py_TYPE(self)->tp_name);
117  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
118  }
119  return nullptr;
120  }
121  return PyLong_FromLong(self->uf0D_unsigned->result);
122 }
123 
124 /*-----------------------BPy_UnaryFunction0DUnsigned type definition ----------------------------*/
125 
127  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DUnsigned", /* tp_name */
128  sizeof(BPy_UnaryFunction0DUnsigned), /* tp_basicsize */
129  0, /* tp_itemsize */
130  (destructor)UnaryFunction0DUnsigned___dealloc__, /* tp_dealloc */
131  0, /* tp_vectorcall_offset */
132  nullptr, /* tp_getattr */
133  nullptr, /* tp_setattr */
134  nullptr, /* tp_reserved */
135  (reprfunc)UnaryFunction0DUnsigned___repr__, /* tp_repr */
136  nullptr, /* tp_as_number */
137  nullptr, /* tp_as_sequence */
138  nullptr, /* tp_as_mapping */
139  nullptr, /* tp_hash */
140  (ternaryfunc)UnaryFunction0DUnsigned___call__, /* tp_call */
141  nullptr, /* tp_str */
142  nullptr, /* tp_getattro */
143  nullptr, /* tp_setattro */
144  nullptr, /* tp_as_buffer */
145  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
146  UnaryFunction0DUnsigned___doc__, /* tp_doc */
147  nullptr, /* tp_traverse */
148  nullptr, /* tp_clear */
149  nullptr, /* tp_richcompare */
150  0, /* tp_weaklistoffset */
151  nullptr, /* tp_iter */
152  nullptr, /* tp_iternext */
153  nullptr, /* tp_methods */
154  nullptr, /* tp_members */
155  nullptr, /* tp_getset */
156  &UnaryFunction0D_Type, /* tp_base */
157  nullptr, /* tp_dict */
158  nullptr, /* tp_descr_get */
159  nullptr, /* tp_descr_set */
160  0, /* tp_dictoffset */
161  (initproc)UnaryFunction0DUnsigned___init__, /* tp_init */
162  nullptr, /* tp_alloc */
163  nullptr, /* tp_new */
164 };
165 
167 
168 #ifdef __cplusplus
169 }
170 #endif
PyTypeObject Interface0DIterator_Type
PyTypeObject QuantitativeInvisibilityF0D_Type
static PyObject * UnaryFunction0DUnsigned___call__(BPy_UnaryFunction0DUnsigned *self, PyObject *args, PyObject *kwds)
static void UnaryFunction0DUnsigned___dealloc__(BPy_UnaryFunction0DUnsigned *self)
int UnaryFunction0DUnsigned_Init(PyObject *module)
static PyObject * UnaryFunction0DUnsigned___repr__(BPy_UnaryFunction0DUnsigned *self)
PyTypeObject UnaryFunction0DUnsigned_Type
static int UnaryFunction0DUnsigned___init__(BPy_UnaryFunction0DUnsigned *self, PyObject *args, PyObject *kwds)
static char UnaryFunction0DUnsigned___doc__[]
PyTypeObject UnaryFunction0D_Type
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32