Blender V4.5
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.");
105
106static int Iterator_init(BPy_Iterator *self, PyObject *args, PyObject *kwds)
107{
108 static const char *kwlist[] = {nullptr};
109
110 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
111 return -1;
112 }
113 self->it = new Iterator();
114 return 0;
115}
116
118{
119 delete self->it;
120 Py_TYPE(self)->tp_free((PyObject *)self);
121}
122
124{
125 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->it);
126}
127
129 /* Wrap. */
130 Iterator_increment_doc,
131 ".. method:: increment()\n"
132 "\n"
133 " Makes the iterator point the next element.");
134
136{
137 if (self->it->isEnd()) {
138 PyErr_SetString(PyExc_RuntimeError, "cannot increment any more");
139 return nullptr;
140 }
141 self->it->increment();
142 Py_RETURN_NONE;
143}
144
146 /* Wrap. */
147 Iterator_decrement_doc,
148 ".. method:: decrement()\n"
149 "\n"
150 " Makes the iterator point the previous element.");
151
153{
154 if (self->it->isBegin()) {
155 PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more");
156 return nullptr;
157 }
158 self->it->decrement();
159 Py_RETURN_NONE;
160}
161
162#ifdef __GNUC__
163# ifdef __clang__
164# pragma clang diagnostic push
165# pragma clang diagnostic ignored "-Wcast-function-type"
166# else
167# pragma GCC diagnostic push
168# pragma GCC diagnostic ignored "-Wcast-function-type"
169# endif
170#endif
171
172static PyMethodDef BPy_Iterator_methods[] = {
173 {"increment", (PyCFunction)Iterator_increment, METH_NOARGS, Iterator_increment_doc},
174 {"decrement", (PyCFunction)Iterator_decrement, METH_NOARGS, Iterator_decrement_doc},
175 {nullptr, nullptr, 0, nullptr},
176};
177
178#ifdef __GNUC__
179# ifdef __clang__
180# pragma clang diagnostic pop
181# else
182# pragma GCC diagnostic pop
183# endif
184#endif
185
186/*----------------------Iterator get/setters ----------------------------*/
187
189 /* Wrap. */
190 Iterator_name_doc,
191 "The string of the name of this iterator.\n"
192 "\n"
193 ":type: str");
194
195static PyObject *Iterator_name_get(BPy_Iterator *self, void * /*closure*/)
196{
197 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
198}
199
201 /* Wrap. */
202 Iterator_is_begin_doc,
203 "True if the iterator points to the first element.\n"
204 "\n"
205 ":type: bool");
206
207static PyObject *Iterator_is_begin_get(BPy_Iterator *self, void * /*closure*/)
208{
209 return PyBool_from_bool(self->it->isBegin());
210}
211
213 /* Wrap. */
214 Iterator_is_end_doc,
215 "True if the iterator points to the last element.\n"
216 "\n"
217 ":type: bool");
218
219static PyObject *Iterator_is_end_get(BPy_Iterator *self, void * /*closure*/)
220{
221 return PyBool_from_bool(self->it->isEnd());
222}
223
224static PyGetSetDef BPy_Iterator_getseters[] = {
225 {"name", (getter)Iterator_name_get, (setter) nullptr, Iterator_name_doc, nullptr},
226 {"is_begin", (getter)Iterator_is_begin_get, (setter) nullptr, Iterator_is_begin_doc, nullptr},
227 {"is_end", (getter)Iterator_is_end_get, (setter) nullptr, Iterator_is_end_doc, nullptr},
228 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
229};
230
231/*-----------------------BPy_Iterator type definition ------------------------------*/
232
233PyTypeObject Iterator_Type = {
234 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
235 /*tp_name*/ "Iterator",
236 /*tp_basicsize*/ sizeof(BPy_Iterator),
237 /*tp_itemsize*/ 0,
238 /*tp_dealloc*/ (destructor)Iterator_dealloc,
239 /*tp_vectorcall_offset*/ 0,
240 /*tp_getattr*/ nullptr,
241 /*tp_setattr*/ nullptr,
242 /*tp_as_async*/ nullptr,
243 /*tp_repr*/ (reprfunc)Iterator_repr,
244 /*tp_as_number*/ nullptr,
245 /*tp_as_sequence*/ nullptr,
246 /*tp_as_mapping*/ nullptr,
247 /*tp_hash*/ nullptr,
248 /*tp_call*/ nullptr,
249 /*tp_str*/ nullptr,
250 /*tp_getattro*/ nullptr,
251 /*tp_setattro*/ nullptr,
252 /*tp_as_buffer*/ nullptr,
253 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
254 /*tp_doc*/ Iterator_doc,
255 /*tp_traverse*/ nullptr,
256 /*tp_clear*/ nullptr,
257 /*tp_richcompare*/ nullptr,
258 /*tp_weaklistoffset*/ 0,
259 /*tp_iter*/ nullptr,
260 /*tp_iternext*/ nullptr,
261 /*tp_methods*/ BPy_Iterator_methods,
262 /*tp_members*/ nullptr,
263 /*tp_getset*/ BPy_Iterator_getseters,
264 /*tp_base*/ nullptr,
265 /*tp_dict*/ nullptr,
266 /*tp_descr_get*/ nullptr,
267 /*tp_descr_set*/ nullptr,
268 /*tp_dictoffset*/ 0,
269 /*tp_init*/ (initproc)Iterator_init,
270 /*tp_alloc*/ nullptr,
271 /*tp_new*/ PyType_GenericNew,
272};
273
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 *)
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 *)
PyDoc_STRVAR(Iterator_doc, "Base class to define iterators.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.")
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