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).
This commit is contained in:
@@ -17,12 +17,11 @@ static void UnaryFunction0DVectorViewShape___dealloc__(BPy_UnaryFunction0DVector
|
||||
static PyObject * UnaryFunction0DVectorViewShape___repr__(BPy_UnaryFunction0DVectorViewShape* self);
|
||||
|
||||
static PyObject * UnaryFunction0DVectorViewShape_getName( BPy_UnaryFunction0DVectorViewShape *self);
|
||||
static PyObject * UnaryFunction0DVectorViewShape___call__( BPy_UnaryFunction0DVectorViewShape *self, PyObject *args);
|
||||
static PyObject * UnaryFunction0DVectorViewShape___call__( BPy_UnaryFunction0DVectorViewShape *self, PyObject *args, PyObject *kwds);
|
||||
|
||||
/*----------------------UnaryFunction0DVectorViewShape instance definitions ----------------------------*/
|
||||
static PyMethodDef BPy_UnaryFunction0DVectorViewShape_methods[] = {
|
||||
{"getName", ( PyCFunction ) UnaryFunction0DVectorViewShape_getName, METH_NOARGS, "( )Returns the string of the name of the unary 0D function."},
|
||||
{"__call__", ( PyCFunction ) UnaryFunction0DVectorViewShape___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}
|
||||
};
|
||||
|
||||
@@ -52,7 +51,7 @@ PyTypeObject UnaryFunction0DVectorViewShape_Type = {
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
(ternaryfunc)UnaryFunction0DVectorViewShape___call__, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
@@ -156,13 +155,21 @@ PyObject * UnaryFunction0DVectorViewShape_getName( BPy_UnaryFunction0DVectorView
|
||||
return PyString_FromString( self->uf0D_vectorviewshape->getName().c_str() );
|
||||
}
|
||||
|
||||
PyObject * UnaryFunction0DVectorViewShape___call__( BPy_UnaryFunction0DVectorViewShape *self, PyObject *args)
|
||||
PyObject * UnaryFunction0DVectorViewShape___call__( BPy_UnaryFunction0DVectorViewShape *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_vectorviewshape)) == typeid(UnaryFunction0D<std::vector<ViewShape*>>) ) {
|
||||
PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded");
|
||||
return NULL;
|
||||
}
|
||||
if (self->uf0D_vectorviewshape->operator()(*( ((BPy_Interface0DIterator *) obj)->if0D_it )) < 0) {
|
||||
if (!PyErr_Occurred()) {
|
||||
string msg(self->uf0D_vectorviewshape->getName() + " __call__ method failed");
|
||||
|
||||
Reference in New Issue
Block a user