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:
@@ -20,14 +20,13 @@ static void UnaryFunction1DVectorViewShape___dealloc__(BPy_UnaryFunction1DVector
|
||||
static PyObject * UnaryFunction1DVectorViewShape___repr__(BPy_UnaryFunction1DVectorViewShape* self);
|
||||
|
||||
static PyObject * UnaryFunction1DVectorViewShape_getName( BPy_UnaryFunction1DVectorViewShape *self);
|
||||
static PyObject * UnaryFunction1DVectorViewShape___call__( BPy_UnaryFunction1DVectorViewShape *self, PyObject *args);
|
||||
static PyObject * UnaryFunction1DVectorViewShape___call__( BPy_UnaryFunction1DVectorViewShape *self, PyObject *args, PyObject *kwds);
|
||||
static PyObject * UnaryFunction1DVectorViewShape_setIntegrationType(BPy_UnaryFunction1DVectorViewShape* self, PyObject *args);
|
||||
static PyObject * UnaryFunction1DVectorViewShape_getIntegrationType(BPy_UnaryFunction1DVectorViewShape* self);
|
||||
|
||||
/*----------------------UnaryFunction1DVectorViewShape instance definitions ----------------------------*/
|
||||
static PyMethodDef BPy_UnaryFunction1DVectorViewShape_methods[] = {
|
||||
{"getName", ( PyCFunction ) UnaryFunction1DVectorViewShape_getName, METH_NOARGS, "( )Returns the string of the name of the unary 1D function."},
|
||||
{"__call__", ( PyCFunction ) UnaryFunction1DVectorViewShape___call__, METH_VARARGS, "(Interface1D if1D )Builds a UnaryFunction1D from an integration type. " },
|
||||
{"setIntegrationType", ( PyCFunction ) UnaryFunction1DVectorViewShape_setIntegrationType, METH_VARARGS, "(IntegrationType i )Sets the integration method" },
|
||||
{"getIntegrationType", ( PyCFunction ) UnaryFunction1DVectorViewShape_getIntegrationType, METH_NOARGS, "() Returns the integration method." },
|
||||
{NULL, NULL, 0, NULL}
|
||||
@@ -59,7 +58,7 @@ PyTypeObject UnaryFunction1DVectorViewShape_Type = {
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
(ternaryfunc)UnaryFunction1DVectorViewShape___call__, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
@@ -187,13 +186,21 @@ PyObject * UnaryFunction1DVectorViewShape_getName( BPy_UnaryFunction1DVectorView
|
||||
return PyString_FromString( self->uf1D_vectorviewshape->getName().c_str() );
|
||||
}
|
||||
|
||||
PyObject * UnaryFunction1DVectorViewShape___call__( BPy_UnaryFunction1DVectorViewShape *self, PyObject *args)
|
||||
PyObject * UnaryFunction1DVectorViewShape___call__( BPy_UnaryFunction1DVectorViewShape *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!", &Interface1D_Type, &obj) )
|
||||
return NULL;
|
||||
|
||||
if( typeid(*(self->uf1D_vectorviewshape)) == typeid(UnaryFunction1D<std::vector<ViewShape*>>) ) {
|
||||
PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded");
|
||||
return NULL;
|
||||
}
|
||||
if (self->uf1D_vectorviewshape->operator()(*( ((BPy_Interface1D *) obj)->if1D )) < 0) {
|
||||
if (!PyErr_Occurred()) {
|
||||
string msg(self->uf1D_vectorviewshape->getName() + " __call__ method failed");
|
||||
|
||||
Reference in New Issue
Block a user