[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21930] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/python: Made predicate and function types callable in the sense that
Tamito Kajiyama
rd6t-kjym at asahi-net.or.jp
Sun Jul 26 18:15:34 CEST 2009
Revision: 21930
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21930
Author: kjym3
Date: 2009-07-26 18:15:28 +0200 (Sun, 26 Jul 2009)
Log Message:
-----------
Made predicate and function types callable in the sense that
callable(I, T) returns True when I is an object of a type T or
of a subtype of T. Also implemented a measure to avoid an
infinite loop when user-defined predicate and function classes
do not properly overload the __call__ method (including the
cases of directly instantiating the base classes such as
UnaryPredicate0D and BinaryPredicate1D).
Modified Paths:
--------------
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DEdgeNature.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DFloat.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DId.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DMaterial.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DUnsigned.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec3f.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DViewShape.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DDouble.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DEdgeNature.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DUnsigned.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec2f.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVec3f.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVoid.cpp
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp 2009-07-26 14:58:31 UTC (rev 21929)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate0D.cpp 2009-07-26 16:15:28 UTC (rev 21930)
@@ -15,12 +15,11 @@
static PyObject * BinaryPredicate0D___repr__(BPy_BinaryPredicate0D *self);
static PyObject * BinaryPredicate0D_getName( BPy_BinaryPredicate0D *self, PyObject *args);
-static PyObject * BinaryPredicate0D___call__( BPy_BinaryPredicate0D *self, PyObject *args);
+static PyObject * BinaryPredicate0D___call__( BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds);
/*----------------------BinaryPredicate0D instance definitions ----------------------------*/
static PyMethodDef BPy_BinaryPredicate0D_methods[] = {
{"getName", ( PyCFunction ) BinaryPredicate0D_getName, METH_NOARGS, "( )Returns the string of the name of the binary predicate."},
- {"__call__", ( PyCFunction ) BinaryPredicate0D___call__, METH_VARARGS, "BinaryPredicate0D(Interface0D, Interface0D ). Must be overloaded by inherited classes. It evaluates a relation between two Interface0D." },
{NULL, NULL, 0, NULL}
};
@@ -50,7 +49,7 @@
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
- NULL, /* ternaryfunc tp_call; */
+ (ternaryfunc)BinaryPredicate0D___call__, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
@@ -150,13 +149,21 @@
return PyString_FromString( self->bp0D->getName().c_str() );
}
-PyObject * BinaryPredicate0D___call__( BPy_BinaryPredicate0D *self, PyObject *args)
+PyObject * BinaryPredicate0D___call__( BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
{
BPy_Interface0D *obj1, *obj2;
+ if( kwds != NULL ) {
+ PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
+ return NULL;
+ }
if( !PyArg_ParseTuple(args, "O!O!", &Interface0D_Type, &obj1, &Interface0D_Type, &obj2) )
return NULL;
+ if( typeid(*(self->bp0D)) == typeid(BinaryPredicate0D) ) {
+ PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded");
+ return NULL;
+ }
if (self->bp0D->operator()( *(obj1->if0D) , *(obj2->if0D) ) < 0) {
if (!PyErr_Occurred()) {
string msg(self->bp0D->getName() + " __call__ method failed");
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp 2009-07-26 14:58:31 UTC (rev 21929)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_BinaryPredicate1D.cpp 2009-07-26 16:15:28 UTC (rev 21930)
@@ -21,12 +21,11 @@
static PyObject * BinaryPredicate1D___repr__(BPy_BinaryPredicate1D *self);
static PyObject * BinaryPredicate1D_getName( BPy_BinaryPredicate1D *self, PyObject *args);
-static PyObject * BinaryPredicate1D___call__( BPy_BinaryPredicate1D *self, PyObject *args);
+static PyObject * BinaryPredicate1D___call__( BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds);
/*----------------------BinaryPredicate1D instance definitions ----------------------------*/
static PyMethodDef BPy_BinaryPredicate1D_methods[] = {
{"getName", ( PyCFunction ) BinaryPredicate1D_getName, METH_NOARGS, "( )Returns the string of the name of the binary predicate."},
- {"__call__", ( PyCFunction ) BinaryPredicate1D___call__, METH_VARARGS, "BinaryPredicate1D(Interface1D, Interface1D ). Must be overloaded by inherited classes. It evaluates a relation between two Interface1D." },
{NULL, NULL, 0, NULL}
};
@@ -55,7 +54,7 @@
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
- NULL, /* ternaryfunc tp_call; */
+ (ternaryfunc)BinaryPredicate1D___call__, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
@@ -179,13 +178,21 @@
return PyString_FromString( self->bp1D->getName().c_str() );
}
-PyObject *BinaryPredicate1D___call__( BPy_BinaryPredicate1D *self, PyObject *args)
+PyObject *BinaryPredicate1D___call__( BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds)
{
BPy_Interface1D *obj1, *obj2;
+ if( kwds != NULL ) {
+ PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
+ return NULL;
+ }
if( !PyArg_ParseTuple(args, "O!O!", &Interface1D_Type, &obj1, &Interface1D_Type, &obj2) )
return NULL;
+ if( typeid(*(self->bp1D)) == typeid(BinaryPredicate1D) ) {
+ PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded");
+ return NULL;
+ }
if (self->bp1D->operator()( *(obj1->if1D) , *(obj2->if1D) ) < 0) {
if (!PyErr_Occurred()) {
string msg(self->bp1D->getName() + " __call__ method failed");
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp 2009-07-26 14:58:31 UTC (rev 21929)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp 2009-07-26 16:15:28 UTC (rev 21930)
@@ -17,12 +17,11 @@
static PyObject * UnaryPredicate0D___repr__(BPy_UnaryPredicate0D *self);
static PyObject * UnaryPredicate0D_getName( BPy_UnaryPredicate0D *self );
-static PyObject * UnaryPredicate0D___call__( BPy_UnaryPredicate0D *self, PyObject *args);
+static PyObject * UnaryPredicate0D___call__( BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds);
/*----------------------UnaryPredicate0D instance definitions ----------------------------*/
static PyMethodDef BPy_UnaryPredicate0D_methods[] = {
{"getName", ( PyCFunction ) UnaryPredicate0D_getName, METH_NOARGS, "Returns the string of the name of the UnaryPredicate0D."},
- {"__call__", ( PyCFunction ) UnaryPredicate0D___call__, METH_VARARGS, "The () operator. Must be overload by inherited classes." },
{NULL, NULL, 0, NULL}
};
@@ -52,7 +51,7 @@
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
- NULL, /* ternaryfunc tp_call; */
+ (ternaryfunc)UnaryPredicate0D___call__, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
@@ -161,10 +160,14 @@
return PyString_FromString( self->up0D->getName().c_str() );
}
-PyObject * UnaryPredicate0D___call__( BPy_UnaryPredicate0D *self, PyObject *args)
+PyObject * UnaryPredicate0D___call__( BPy_UnaryPredicate0D *self, PyObject *args, PyObject *kwds)
{
PyObject *py_if0D_it;
+ if( kwds != NULL ) {
+ PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
+ return NULL;
+ }
if( !PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &py_if0D_it) )
return NULL;
@@ -175,6 +178,10 @@
PyErr_SetString(PyExc_RuntimeError, msg.c_str());
return NULL;
}
+ if( typeid(*(self->up0D)) == typeid(UnaryPredicate0D) ) {
+ PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded");
+ return NULL;
+ }
if (self->up0D->operator()(*if0D_it) < 0) {
if (!PyErr_Occurred()) {
string msg(self->up0D->getName() + " __call__ method failed");
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp 2009-07-26 14:58:31 UTC (rev 21929)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp 2009-07-26 16:15:28 UTC (rev 21930)
@@ -25,12 +25,11 @@
static PyObject * UnaryPredicate1D___repr__(BPy_UnaryPredicate1D *self);
static PyObject * UnaryPredicate1D_getName( BPy_UnaryPredicate1D *self, PyObject *args);
-static PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args);
+static PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds);
/*----------------------UnaryPredicate1D instance definitions ----------------------------*/
static PyMethodDef BPy_UnaryPredicate1D_methods[] = {
{"getName", ( PyCFunction ) UnaryPredicate1D_getName, METH_NOARGS, ""},
- {"__call__", ( PyCFunction ) UnaryPredicate1D___call__, METH_VARARGS, "" },
{NULL, NULL, 0, NULL}
};
@@ -60,7 +59,7 @@
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
- NULL, /* ternaryfunc tp_call; */
+ (ternaryfunc)UnaryPredicate1D___call__, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
@@ -203,10 +202,14 @@
return PyString_FromString( self->up1D->getName().c_str() );
}
-PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args)
+static PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds)
{
PyObject *py_if1D;
+ if( kwds != NULL ) {
+ PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
+ return NULL;
+ }
if( !PyArg_ParseTuple(args, "O!", &Interface1D_Type, &py_if1D) )
return NULL;
@@ -217,6 +220,10 @@
PyErr_SetString(PyExc_RuntimeError, msg.c_str());
return NULL;
}
+ if( typeid(*(self->up1D)) == typeid(UnaryPredicate1D) ) {
+ PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded");
+ return NULL;
+ }
if( self->up1D->operator()(*if1D) < 0 ) {
if (!PyErr_Occurred()) {
string msg(self->up1D->getName() + " __call__ method failed");
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list