Blender  V3.3
BPy_UnaryFunction0DId.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(&UnaryFunction0DId_Type) < 0) {
31  return -1;
32  }
33  Py_INCREF(&UnaryFunction0DId_Type);
34  PyModule_AddObject(module, "UnaryFunction0DId", (PyObject *)&UnaryFunction0DId_Type);
35 
36  if (PyType_Ready(&ShapeIdF0D_Type) < 0) {
37  return -1;
38  }
39  Py_INCREF(&ShapeIdF0D_Type);
40  PyModule_AddObject(module, "ShapeIdF0D", (PyObject *)&ShapeIdF0D_Type);
41 
42  return 0;
43 }
44 
45 //------------------------INSTANCE METHODS ----------------------------------
46 
48  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DId`\n"
49  "\n"
50  "Base class for unary functions (functors) that work on\n"
51  ":class:`Interface0DIterator` and return an :class:`Id` object.\n"
52  "\n"
53  ".. method:: __init__()\n"
54  "\n"
55  " Default constructor.\n";
56 
57 static int UnaryFunction0DId___init__(BPy_UnaryFunction0DId *self, PyObject *args, PyObject *kwds)
58 {
59  static const char *kwlist[] = {nullptr};
60 
61  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
62  return -1;
63  }
64  self->uf0D_id = new UnaryFunction0D<Id>();
65  self->uf0D_id->py_uf0D = (PyObject *)self;
66  return 0;
67 }
68 
70 {
71  delete self->uf0D_id;
72  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
73 }
74 
76 {
77  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_id);
78 }
79 
81  PyObject *args,
82  PyObject *kwds)
83 {
84  static const char *kwlist[] = {"it", nullptr};
85  PyObject *obj;
86 
87  if (!PyArg_ParseTupleAndKeywords(
88  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
89  return nullptr;
90  }
91 
92  if (typeid(*(self->uf0D_id)) == typeid(UnaryFunction0D<Id>)) {
93  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
94  return nullptr;
95  }
96  if (self->uf0D_id->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
97  if (!PyErr_Occurred()) {
98  string class_name(Py_TYPE(self)->tp_name);
99  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
100  }
101  return nullptr;
102  }
103  return BPy_Id_from_Id(self->uf0D_id->result);
104 }
105 
106 /*-----------------------BPy_UnaryFunction0DId type definition ------------------------------*/
107 
108 PyTypeObject UnaryFunction0DId_Type = {
109  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DId", /* tp_name */
110  sizeof(BPy_UnaryFunction0DId), /* tp_basicsize */
111  0, /* tp_itemsize */
112  (destructor)UnaryFunction0DId___dealloc__, /* tp_dealloc */
113  0, /* tp_vectorcall_offset */
114  nullptr, /* tp_getattr */
115  nullptr, /* tp_setattr */
116  nullptr, /* tp_reserved */
117  (reprfunc)UnaryFunction0DId___repr__, /* tp_repr */
118  nullptr, /* tp_as_number */
119  nullptr, /* tp_as_sequence */
120  nullptr, /* tp_as_mapping */
121  nullptr, /* tp_hash */
122  (ternaryfunc)UnaryFunction0DId___call__, /* tp_call */
123  nullptr, /* tp_str */
124  nullptr, /* tp_getattro */
125  nullptr, /* tp_setattro */
126  nullptr, /* tp_as_buffer */
127  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
128  UnaryFunction0DId___doc__, /* tp_doc */
129  nullptr, /* tp_traverse */
130  nullptr, /* tp_clear */
131  nullptr, /* tp_richcompare */
132  0, /* tp_weaklistoffset */
133  nullptr, /* tp_iter */
134  nullptr, /* tp_iternext */
135  nullptr, /* tp_methods */
136  nullptr, /* tp_members */
137  nullptr, /* tp_getset */
138  &UnaryFunction0D_Type, /* tp_base */
139  nullptr, /* tp_dict */
140  nullptr, /* tp_descr_get */
141  nullptr, /* tp_descr_set */
142  0, /* tp_dictoffset */
143  (initproc)UnaryFunction0DId___init__, /* tp_init */
144  nullptr, /* tp_alloc */
145  nullptr, /* tp_new */
146 };
147 
149 
150 #ifdef __cplusplus
151 }
152 #endif
PyObject * BPy_Id_from_Id(Id &id)
Definition: BPy_Convert.cpp:90
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
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972