[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22003] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp: Added changes to the AdjacencyIterator type to support Python's

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Wed Jul 29 02:18:15 CEST 2009


Revision: 22003
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22003
Author:   kjym3
Date:     2009-07-29 02:18:13 +0200 (Wed, 29 Jul 2009)

Log Message:
-----------
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):
        ...

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp	2009-07-29 00:11:41 UTC (rev 22002)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp	2009-07-29 00:18:13 UTC (rev 22003)
@@ -11,6 +11,7 @@
 
 /*---------------  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 @@
 
   /*** 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 @@
 
 }
 
+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());
 }





More information about the Bf-blender-cvs mailing list