Blender  V3.3
BPy_UnaryPredicate0D.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BPy_UnaryPredicate0D.h"
8 
9 #include "BPy_Convert.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 using namespace Freestyle;
19 
21 
22 //-------------------MODULE INITIALIZATION--------------------------------
24 {
25  if (module == nullptr) {
26  return -1;
27  }
28 
29  if (PyType_Ready(&UnaryPredicate0D_Type) < 0) {
30  return -1;
31  }
32  Py_INCREF(&UnaryPredicate0D_Type);
33  PyModule_AddObject(module, "UnaryPredicate0D", (PyObject *)&UnaryPredicate0D_Type);
34 
35  if (PyType_Ready(&FalseUP0D_Type) < 0) {
36  return -1;
37  }
38  Py_INCREF(&FalseUP0D_Type);
39  PyModule_AddObject(module, "FalseUP0D", (PyObject *)&FalseUP0D_Type);
40 
41  if (PyType_Ready(&TrueUP0D_Type) < 0) {
42  return -1;
43  }
44  Py_INCREF(&TrueUP0D_Type);
45  PyModule_AddObject(module, "TrueUP0D", (PyObject *)&TrueUP0D_Type);
46 
47  return 0;
48 }
49 
50 //------------------------INSTANCE METHODS ----------------------------------
51 
52 static char UnaryPredicate0D___doc__[] =
53  "Base class for unary predicates that work on\n"
54  ":class:`Interface0DIterator`. A UnaryPredicate0D is a functor that\n"
55  "evaluates a condition on an Interface0DIterator and returns true or\n"
56  "false depending on whether this condition is satisfied or not. The\n"
57  "UnaryPredicate0D is used by invoking its __call__() method. Any\n"
58  "inherited class must overload the __call__() method.\n"
59  "\n"
60  ".. method:: __init__()\n"
61  "\n"
62  " Default constructor.\n"
63  "\n"
64  ".. method:: __call__(it)\n"
65  "\n"
66  " Must be overload by inherited classes.\n"
67  "\n"
68  " :arg it: The Interface0DIterator pointing onto the Interface0D at\n"
69  " which we wish to evaluate the predicate.\n"
70  " :type it: :class:`Interface0DIterator`\n"
71  " :return: True if the condition is satisfied, false otherwise.\n"
72  " :rtype: bool\n";
73 
74 static int UnaryPredicate0D___init__(BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds)
75 {
76  static const char *kwlist[] = {nullptr};
77 
78  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
79  return -1;
80  }
81  self->up0D = new UnaryPredicate0D();
82  self->up0D->py_up0D = (PyObject *)self;
83  return 0;
84 }
85 
87 {
88  delete self->up0D;
89  Py_TYPE(self)->tp_free((PyObject *)self);
90 }
91 
93 {
94  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->up0D);
95 }
96 
98  PyObject *args,
99  PyObject *kwds)
100 {
101  static const char *kwlist[] = {"it", nullptr};
102  PyObject *py_if0D_it;
103 
104  if (!PyArg_ParseTupleAndKeywords(
105  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &py_if0D_it)) {
106  return nullptr;
107  }
108 
109  Interface0DIterator *if0D_it = ((BPy_Interface0DIterator *)py_if0D_it)->if0D_it;
110 
111  if (!if0D_it) {
112  string class_name(Py_TYPE(self)->tp_name);
113  PyErr_SetString(PyExc_RuntimeError, (class_name + " has no Interface0DIterator").c_str());
114  return nullptr;
115  }
116  if (typeid(*(self->up0D)) == typeid(UnaryPredicate0D)) {
117  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
118  return nullptr;
119  }
120  if (self->up0D->operator()(*if0D_it) < 0) {
121  if (!PyErr_Occurred()) {
122  string class_name(Py_TYPE(self)->tp_name);
123  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
124  }
125  return nullptr;
126  }
127  return PyBool_from_bool(self->up0D->result);
128 }
129 
130 /*----------------------UnaryPredicate0D get/setters ----------------------------*/
131 
132 PyDoc_STRVAR(UnaryPredicate0D_name_doc,
133  "The name of the unary 0D predicate.\n"
134  "\n"
135  ":type: str");
136 
137 static PyObject *UnaryPredicate0D_name_get(BPy_UnaryPredicate0D *self, void *UNUSED(closure))
138 {
139  return PyUnicode_FromString(Py_TYPE(self)->tp_name);
140 }
141 
142 static PyGetSetDef BPy_UnaryPredicate0D_getseters[] = {
143  {"name",
145  (setter) nullptr,
146  UnaryPredicate0D_name_doc,
147  nullptr},
148  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
149 };
150 
151 /*-----------------------BPy_UnaryPredicate0D type definition ------------------------------*/
152 
153 PyTypeObject UnaryPredicate0D_Type = {
154  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryPredicate0D", /* tp_name */
155  sizeof(BPy_UnaryPredicate0D), /* tp_basicsize */
156  0, /* tp_itemsize */
157  (destructor)UnaryPredicate0D___dealloc__, /* tp_dealloc */
158  0, /* tp_vectorcall_offset */
159  nullptr, /* tp_getattr */
160  nullptr, /* tp_setattr */
161  nullptr, /* tp_reserved */
162  (reprfunc)UnaryPredicate0D___repr__, /* tp_repr */
163  nullptr, /* tp_as_number */
164  nullptr, /* tp_as_sequence */
165  nullptr, /* tp_as_mapping */
166  nullptr, /* tp_hash */
167  (ternaryfunc)UnaryPredicate0D___call__, /* tp_call */
168  nullptr, /* tp_str */
169  nullptr, /* tp_getattro */
170  nullptr, /* tp_setattro */
171  nullptr, /* tp_as_buffer */
172  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
173  UnaryPredicate0D___doc__, /* tp_doc */
174  nullptr, /* tp_traverse */
175  nullptr, /* tp_clear */
176  nullptr, /* tp_richcompare */
177  0, /* tp_weaklistoffset */
178  nullptr, /* tp_iter */
179  nullptr, /* tp_iternext */
180  nullptr, /* tp_methods */
181  nullptr, /* tp_members */
182  BPy_UnaryPredicate0D_getseters, /* tp_getset */
183  nullptr, /* tp_base */
184  nullptr, /* tp_dict */
185  nullptr, /* tp_descr_get */
186  nullptr, /* tp_descr_set */
187  0, /* tp_dictoffset */
188  (initproc)UnaryPredicate0D___init__, /* tp_init */
189  nullptr, /* tp_alloc */
190  PyType_GenericNew, /* tp_new */
191 };
192 
194 
195 #ifdef __cplusplus
196 }
197 #endif
#define UNUSED(x)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:59
PyTypeObject FalseUP0D_Type
PyTypeObject Interface0DIterator_Type
PyTypeObject TrueUP0D_Type
int UnaryPredicate0D_Init(PyObject *module)
static char UnaryPredicate0D___doc__[]
PyTypeObject UnaryPredicate0D_Type
PyDoc_STRVAR(UnaryPredicate0D_name_doc, "The name of the unary 0D predicate.\n" "\n" ":type: str")
static PyObject * UnaryPredicate0D___repr__(BPy_UnaryPredicate0D *self)
static void UnaryPredicate0D___dealloc__(BPy_UnaryPredicate0D *self)
static PyObject * UnaryPredicate0D_name_get(BPy_UnaryPredicate0D *self, void *UNUSED(closure))
static int UnaryPredicate0D___init__(BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds)
static PyObject * UnaryPredicate0D___call__(BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_UnaryPredicate0D_getseters[]
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972