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