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/UnaryFunction0D/BPy_UnaryFunction0DDouble.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/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp index 822ad6c22bd..cfc4bb24a56 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DDouble.cpp @@ -28,12 +28,11 @@ static void UnaryFunction0DDouble___dealloc__(BPy_UnaryFunction0DDouble* self); static PyObject * UnaryFunction0DDouble___repr__(BPy_UnaryFunction0DDouble* self); static PyObject * UnaryFunction0DDouble_getName( BPy_UnaryFunction0DDouble *self); -static PyObject * UnaryFunction0DDouble___call__( BPy_UnaryFunction0DDouble *self, PyObject *args); +static PyObject * UnaryFunction0DDouble___call__( BPy_UnaryFunction0DDouble *self, PyObject *args, PyObject *kwds); /*----------------------UnaryFunction0DDouble instance definitions ----------------------------*/ static PyMethodDef BPy_UnaryFunction0DDouble_methods[] = { {"getName", ( PyCFunction ) UnaryFunction0DDouble_getName, METH_NOARGS, "( )Returns the string of the name of the unary 0D function."}, - {"__call__", ( PyCFunction ) UnaryFunction0DDouble___call__, METH_VARARGS, "(Interface0DIterator it )Executes the operator () on the iterator it pointing onto the point at which we wish to evaluate the function." }, {NULL, NULL, 0, NULL} }; @@ -63,7 +62,7 @@ PyTypeObject UnaryFunction0DDouble_Type = { /* More standard operations (here for binary compatibility) */ NULL, /* hashfunc tp_hash; */ - NULL, /* ternaryfunc tp_call; */ + (ternaryfunc)UnaryFunction0DDouble___call__, /* ternaryfunc tp_call; */ NULL, /* reprfunc tp_str; */ NULL, /* getattrofunc tp_getattro; */ NULL, /* setattrofunc tp_setattro; */ @@ -213,13 +212,21 @@ PyObject * UnaryFunction0DDouble_getName( BPy_UnaryFunction0DDouble *self ) return PyString_FromString( self->uf0D_double->getName().c_str() ); } -PyObject * UnaryFunction0DDouble___call__( BPy_UnaryFunction0DDouble *self, PyObject *args) +PyObject * UnaryFunction0DDouble___call__( BPy_UnaryFunction0DDouble *self, PyObject *args, PyObject *kwds) { PyObject *obj; + if( kwds != NULL ) { + PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported"); + return NULL; + } if(!PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj)) return NULL; + if( typeid(*(self->uf0D_double)) == typeid(UnaryFunction0D<double>) ) { + PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded"); + return NULL; + } if (self->uf0D_double->operator()(*( ((BPy_Interface0DIterator *) obj)->if0D_it)) < 0) { if (!PyErr_Occurred()) { string msg(self->uf0D_double->getName() + " __call__ method failed"); |