Blender V5.0
BPy_Iterator.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_Iterator.h"
10
11#include "BPy_Convert.h"
22
23using namespace Freestyle;
24
26
27//-------------------MODULE INITIALIZATION--------------------------------
28int Iterator_Init(PyObject *module)
29{
30 if (module == nullptr) {
31 return -1;
32 }
33
34 if (PyType_Ready(&Iterator_Type) < 0) {
35 return -1;
36 }
37 PyModule_AddObjectRef(module, "Iterator", (PyObject *)&Iterator_Type);
38
39 if (PyType_Ready(&AdjacencyIterator_Type) < 0) {
40 return -1;
41 }
42 PyModule_AddObjectRef(module, "AdjacencyIterator", (PyObject *)&AdjacencyIterator_Type);
43
44 if (PyType_Ready(&Interface0DIterator_Type) < 0) {
45 return -1;
46 }
47 PyModule_AddObjectRef(module, "Interface0DIterator", (PyObject *)&Interface0DIterator_Type);
48
49 if (PyType_Ready(&CurvePointIterator_Type) < 0) {
50 return -1;
51 }
52 PyModule_AddObjectRef(module, "CurvePointIterator", (PyObject *)&CurvePointIterator_Type);
53
54 if (PyType_Ready(&StrokeVertexIterator_Type) < 0) {
55 return -1;
56 }
57 PyModule_AddObjectRef(module, "StrokeVertexIterator", (PyObject *)&StrokeVertexIterator_Type);
58
59 if (PyType_Ready(&SVertexIterator_Type) < 0) {
60 return -1;
61 }
62 PyModule_AddObjectRef(module, "SVertexIterator", (PyObject *)&SVertexIterator_Type);
63
64 if (PyType_Ready(&orientedViewEdgeIterator_Type) < 0) {
65 return -1;
66 }
67 PyModule_AddObjectRef(
68 module, "orientedViewEdgeIterator", (PyObject *)&orientedViewEdgeIterator_Type);
69
70 if (PyType_Ready(&ViewEdgeIterator_Type) < 0) {
71 return -1;
72 }
73 PyModule_AddObjectRef(module, "ViewEdgeIterator", (PyObject *)&ViewEdgeIterator_Type);
74
75 if (PyType_Ready(&ChainingIterator_Type) < 0) {
76 return -1;
77 }
78 PyModule_AddObjectRef(module, "ChainingIterator", (PyObject *)&ChainingIterator_Type);
79
80 if (PyType_Ready(&ChainPredicateIterator_Type) < 0) {
81 return -1;
82 }
83 PyModule_AddObjectRef(
84 module, "ChainPredicateIterator", (PyObject *)&ChainPredicateIterator_Type);
85
86 if (PyType_Ready(&ChainSilhouetteIterator_Type) < 0) {
87 return -1;
88 }
89 PyModule_AddObjectRef(
90 module, "ChainSilhouetteIterator", (PyObject *)&ChainSilhouetteIterator_Type);
91
92 return 0;
93}
94
95//------------------------INSTANCE METHODS ----------------------------------
96
98 /* Wrap. */
99 Iterator_doc,
100 "Base class to define iterators.\n"
101 "\n"
102 ".. method:: __init__()\n"
103 "\n"
104 " Default constructor.\n");
105static int Iterator_init(BPy_Iterator *self, PyObject *args, PyObject *kwds)
106{
107 static const char *kwlist[] = {nullptr};
108
109 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
110 return -1;
111 }
112 self->it = new Iterator();
113 return 0;
114}
115
117{
118 delete self->it;
119 Py_TYPE(self)->tp_free((PyObject *)self);
120}
121
123{
124 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->it);
125}
126
128 /* Wrap. */
129 Iterator_increment_doc,
130 ".. method:: increment()\n"
131 "\n"
132 " Makes the iterator point the next element.\n");
134{
135 if (self->it->isEnd()) {
136 PyErr_SetString(PyExc_RuntimeError, "cannot increment any more");
137 return nullptr;
138 }
139 self->it->increment();
140 Py_RETURN_NONE;
141}
142
144 /* Wrap. */
145 Iterator_decrement_doc,
146 ".. method:: decrement()\n"
147 "\n"
148 " Makes the iterator point the previous element.\n");
150{
151 if (self->it->isBegin()) {
152 PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more");
153 return nullptr;
154 }
155 self->it->decrement();
156 Py_RETURN_NONE;
157}
158
159#ifdef __GNUC__
160# ifdef __clang__
161# pragma clang diagnostic push
162# pragma clang diagnostic ignored "-Wcast-function-type"
163# else
164# pragma GCC diagnostic push
165# pragma GCC diagnostic ignored "-Wcast-function-type"
166# endif
167#endif
168
169static PyMethodDef BPy_Iterator_methods[] = {
170 {"increment", (PyCFunction)Iterator_increment, METH_NOARGS, Iterator_increment_doc},
171 {"decrement", (PyCFunction)Iterator_decrement, METH_NOARGS, Iterator_decrement_doc},
172 {nullptr, nullptr, 0, nullptr},
173};
174
175#ifdef __GNUC__
176# ifdef __clang__
177# pragma clang diagnostic pop
178# else
179# pragma GCC diagnostic pop
180# endif
181#endif
182
183/*----------------------Iterator get/setters ----------------------------*/
184
186 /* Wrap. */
187 Iterator_name_doc,
188 "The string of the name of this iterator.\n"
189 "\n"
190 ":type: str\n");
191static PyObject *Iterator_name_get(BPy_Iterator *self, void * /*closure*/)
192{
193 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
194}
195
197 /* Wrap. */
198 Iterator_is_begin_doc,
199 "True if the iterator points to the first element.\n"
200 "\n"
201 ":type: bool\n");
202static PyObject *Iterator_is_begin_get(BPy_Iterator *self, void * /*closure*/)
203{
204 return PyBool_from_bool(self->it->isBegin());
205}
206
208 /* Wrap. */
209 Iterator_is_end_doc,
210 "True if the iterator points to the last element.\n"
211 "\n"
212 ":type: bool\n");
213static PyObject *Iterator_is_end_get(BPy_Iterator *self, void * /*closure*/)
214{
215 return PyBool_from_bool(self->it->isEnd());
216}
217
218static PyGetSetDef BPy_Iterator_getseters[] = {
219 {"name", (getter)Iterator_name_get, (setter) nullptr, Iterator_name_doc, nullptr},
220 {"is_begin", (getter)Iterator_is_begin_get, (setter) nullptr, Iterator_is_begin_doc, nullptr},
221 {"is_end", (getter)Iterator_is_end_get, (setter) nullptr, Iterator_is_end_doc, nullptr},
222 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
223};
224
225/*-----------------------BPy_Iterator type definition ------------------------------*/
226
227PyTypeObject Iterator_Type = {
228 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
229 /*tp_name*/ "Iterator",
230 /*tp_basicsize*/ sizeof(BPy_Iterator),
231 /*tp_itemsize*/ 0,
232 /*tp_dealloc*/ (destructor)Iterator_dealloc,
233 /*tp_vectorcall_offset*/ 0,
234 /*tp_getattr*/ nullptr,
235 /*tp_setattr*/ nullptr,
236 /*tp_as_async*/ nullptr,
237 /*tp_repr*/ (reprfunc)Iterator_repr,
238 /*tp_as_number*/ nullptr,
239 /*tp_as_sequence*/ nullptr,
240 /*tp_as_mapping*/ nullptr,
241 /*tp_hash*/ nullptr,
242 /*tp_call*/ nullptr,
243 /*tp_str*/ nullptr,
244 /*tp_getattro*/ nullptr,
245 /*tp_setattro*/ nullptr,
246 /*tp_as_buffer*/ nullptr,
247 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
248 /*tp_doc*/ Iterator_doc,
249 /*tp_traverse*/ nullptr,
250 /*tp_clear*/ nullptr,
251 /*tp_richcompare*/ nullptr,
252 /*tp_weaklistoffset*/ 0,
253 /*tp_iter*/ nullptr,
254 /*tp_iternext*/ nullptr,
255 /*tp_methods*/ BPy_Iterator_methods,
256 /*tp_members*/ nullptr,
257 /*tp_getset*/ BPy_Iterator_getseters,
258 /*tp_base*/ nullptr,
259 /*tp_dict*/ nullptr,
260 /*tp_descr_get*/ nullptr,
261 /*tp_descr_set*/ nullptr,
262 /*tp_dictoffset*/ 0,
263 /*tp_init*/ (initproc)Iterator_init,
264 /*tp_alloc*/ nullptr,
265 /*tp_new*/ PyType_GenericNew,
266};
267
PyTypeObject AdjacencyIterator_Type
PyTypeObject ChainPredicateIterator_Type
PyTypeObject ChainSilhouetteIterator_Type
PyTypeObject ChainingIterator_Type
PyObject * PyBool_from_bool(bool b)
PyTypeObject CurvePointIterator_Type
PyTypeObject Interface0DIterator_Type
static PyGetSetDef BPy_Iterator_getseters[]
static PyObject * Iterator_increment(BPy_Iterator *self)
static PyObject * Iterator_is_end_get(BPy_Iterator *self, void *)
static PyMethodDef BPy_Iterator_methods[]
static void Iterator_dealloc(BPy_Iterator *self)
static PyObject * Iterator_is_begin_get(BPy_Iterator *self, void *)
PyDoc_STRVAR(Iterator_doc, "Base class to define iterators.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.\n")
static int Iterator_init(BPy_Iterator *self, PyObject *args, PyObject *kwds)
PyTypeObject Iterator_Type
int Iterator_Init(PyObject *module)
static PyObject * Iterator_repr(BPy_Iterator *self)
static PyObject * Iterator_decrement(BPy_Iterator *self)
static PyObject * Iterator_name_get(BPy_Iterator *self, void *)
PyTypeObject SVertexIterator_Type
PyTypeObject StrokeVertexIterator_Type
PyTypeObject ViewEdgeIterator_Type
PyTypeObject orientedViewEdgeIterator_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:796