Blender  V3.3
BPy_UnaryFunction0DUnsigned.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 "../Iterator/BPy_Interface0DIterator.h"
11 
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 using namespace Freestyle;
19 
21 
22 //-------------------MODULE INITIALIZATION--------------------------------
23 
25 {
26  if (module == nullptr) {
27  return -1;
28  }
29 
30  if (PyType_Ready(&UnaryFunction0DUnsigned_Type) < 0) {
31  return -1;
32  }
33  Py_INCREF(&UnaryFunction0DUnsigned_Type);
34  PyModule_AddObject(module, "UnaryFunction0DUnsigned", (PyObject *)&UnaryFunction0DUnsigned_Type);
35 
36  if (PyType_Ready(&QuantitativeInvisibilityF0D_Type) < 0) {
37  return -1;
38  }
40  PyModule_AddObject(
41  module, "QuantitativeInvisibilityF0D", (PyObject *)&QuantitativeInvisibilityF0D_Type);
42 
43  return 0;
44 }
45 
46 //------------------------INSTANCE METHODS ----------------------------------
47 
49  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DUnsigned`\n"
50  "\n"
51  "Base class for unary functions (functors) that work on\n"
52  ":class:`Interface0DIterator` and return an int value.\n"
53  "\n"
54  ".. method:: __init__()\n"
55  "\n"
56  " Default constructor.\n";
57 
59  PyObject *args,
60  PyObject *kwds)
61 {
62  static const char *kwlist[] = {nullptr};
63 
64  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
65  return -1;
66  }
67  self->uf0D_unsigned = new UnaryFunction0D<unsigned int>();
68  self->uf0D_unsigned->py_uf0D = (PyObject *)self;
69  return 0;
70 }
71 
73 {
74  delete self->uf0D_unsigned;
75  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
76 }
77 
79 {
80  return PyUnicode_FromFormat(
81  "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_unsigned);
82 }
83 
85  PyObject *args,
86  PyObject *kwds)
87 {
88  static const char *kwlist[] = {"it", nullptr};
89  PyObject *obj;
90 
91  if (!PyArg_ParseTupleAndKeywords(
92  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
93  return nullptr;
94  }
95 
96  if (typeid(*(self->uf0D_unsigned)) == typeid(UnaryFunction0D<unsigned int>)) {
97  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
98  return nullptr;
99  }
100  if (self->uf0D_unsigned->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
101  if (!PyErr_Occurred()) {
102  string class_name(Py_TYPE(self)->tp_name);
103  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
104  }
105  return nullptr;
106  }
107  return PyLong_FromLong(self->uf0D_unsigned->result);
108 }
109 
110 /*-----------------------BPy_UnaryFunction0DUnsigned type definition ----------------------------*/
111 
113  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DUnsigned", /* tp_name */
114  sizeof(BPy_UnaryFunction0DUnsigned), /* tp_basicsize */
115  0, /* tp_itemsize */
116  (destructor)UnaryFunction0DUnsigned___dealloc__, /* tp_dealloc */
117  0, /* tp_vectorcall_offset */
118  nullptr, /* tp_getattr */
119  nullptr, /* tp_setattr */
120  nullptr, /* tp_reserved */
121  (reprfunc)UnaryFunction0DUnsigned___repr__, /* tp_repr */
122  nullptr, /* tp_as_number */
123  nullptr, /* tp_as_sequence */
124  nullptr, /* tp_as_mapping */
125  nullptr, /* tp_hash */
126  (ternaryfunc)UnaryFunction0DUnsigned___call__, /* tp_call */
127  nullptr, /* tp_str */
128  nullptr, /* tp_getattro */
129  nullptr, /* tp_setattro */
130  nullptr, /* tp_as_buffer */
131  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
132  UnaryFunction0DUnsigned___doc__, /* tp_doc */
133  nullptr, /* tp_traverse */
134  nullptr, /* tp_clear */
135  nullptr, /* tp_richcompare */
136  0, /* tp_weaklistoffset */
137  nullptr, /* tp_iter */
138  nullptr, /* tp_iternext */
139  nullptr, /* tp_methods */
140  nullptr, /* tp_members */
141  nullptr, /* tp_getset */
142  &UnaryFunction0D_Type, /* tp_base */
143  nullptr, /* tp_dict */
144  nullptr, /* tp_descr_get */
145  nullptr, /* tp_descr_set */
146  0, /* tp_dictoffset */
147  (initproc)UnaryFunction0DUnsigned___init__, /* tp_init */
148  nullptr, /* tp_alloc */
149  nullptr, /* tp_new */
150 };
151 
153 
154 #ifdef __cplusplus
155 }
156 #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
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972