Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-07-29 04:18:13 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-07-29 04:18:13 +0400
commit76000379241e781c801040082dbe14e1784cddc6 (patch)
treea3c73e839cdf78f785f124018b5a93daab280278 /source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp
parent8eb1064f4166cc939e2216e560a8e0f0a1ce76ce (diff)
Added changes to the AdjacencyIterator type to support Python's
iterator protocol. Now the following code in the conventional SWIG-based syntax: it = AdjacencyIterator(iter) while not it.isEnd(): ve = it.getObject() ... it.increment() can be written using the iterator protocol as follows: for ve in AdjacencyIterator(iter): ...
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp')
-rw-r--r--source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp
index 1fba493234e..71105c6896c 100644
--- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp
+++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp
@@ -11,6 +11,7 @@ extern "C" {
/*--------------- Python API function prototypes for AdjacencyIterator instance -----------*/
static int AdjacencyIterator___init__(BPy_AdjacencyIterator *self, PyObject *args);
+static PyObject * AdjacencyIterator_iternext(BPy_AdjacencyIterator *self);
static PyObject * AdjacencyIterator_isIncoming(BPy_AdjacencyIterator *self);
static PyObject * AdjacencyIterator_getObject(BPy_AdjacencyIterator *self);
@@ -76,8 +77,8 @@ PyTypeObject AdjacencyIterator_Type = {
/*** Added in release 2.2 ***/
/* Iterators */
- NULL, /* getiterfunc tp_iter; */
- NULL, /* iternextfunc tp_iternext; */
+ PyObject_SelfIter, /* getiterfunc tp_iter; */
+ (iternextfunc)AdjacencyIterator_iternext, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
BPy_AdjacencyIterator_methods, /* struct PyMethodDef *tp_methods; */
@@ -142,6 +143,16 @@ int AdjacencyIterator___init__(BPy_AdjacencyIterator *self, PyObject *args )
}
+PyObject * AdjacencyIterator_iternext(BPy_AdjacencyIterator *self) {
+ if (self->a_it->isEnd()) {
+ PyErr_SetNone(PyExc_StopIteration);
+ return NULL;
+ }
+ ViewEdge *ve = self->a_it->operator->();
+ self->a_it->increment();
+ return BPy_ViewEdge_from_ViewEdge_ptr( ve );
+}
+
PyObject * AdjacencyIterator_isIncoming(BPy_AdjacencyIterator *self) {
return PyBool_from_bool(self->a_it->isIncoming());
}