diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-07-26 20:15:28 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-07-26 20:15:28 +0400 |
commit | 730fb1021c8b189229625866dac0f6e83db6418c (patch) | |
tree | 7985373b62cea17b3247a4e80842fbd372181058 /source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp | |
parent | 78ce17fce88c23ba2c32b561bd9cc398a60a8278 (diff) |
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).
Diffstat (limited to 'source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp index 19d4a8abdbf..5f3312a1801 100644 --- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp +++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp @@ -17,12 +17,11 @@ static void UnaryPredicate0D___dealloc__(BPy_UnaryPredicate0D *self); 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 @@ PyTypeObject UnaryPredicate0D_Type = { /* 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 @@ PyObject * UnaryPredicate0D_getName( BPy_UnaryPredicate0D *self ) 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 @@ PyObject * UnaryPredicate0D___call__( BPy_UnaryPredicate0D *self, PyObject *args 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"); |