Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-07-26 20:15:28 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-07-26 20:15:28 +0400
commit730fb1021c8b189229625866dac0f6e83db6418c (patch)
tree7985373b62cea17b3247a4e80842fbd372181058 /source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp
parent78ce17fce88c23ba2c32b561bd9cc398a60a8278 (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/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp')
-rw-r--r--source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp
index f71a0c8af35..2a8d8f9ec75 100644
--- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp
+++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DFloat.cpp
@@ -16,14 +16,13 @@ static void UnaryFunction1DFloat___dealloc__(BPy_UnaryFunction1DFloat* self);
static PyObject * UnaryFunction1DFloat___repr__(BPy_UnaryFunction1DFloat* self);
static PyObject * UnaryFunction1DFloat_getName( BPy_UnaryFunction1DFloat *self);
-static PyObject * UnaryFunction1DFloat___call__( BPy_UnaryFunction1DFloat *self, PyObject *args);
+static PyObject * UnaryFunction1DFloat___call__( BPy_UnaryFunction1DFloat *self, PyObject *args, PyObject *kwds);
static PyObject * UnaryFunction1DFloat_setIntegrationType(BPy_UnaryFunction1DFloat* self, PyObject *args);
static PyObject * UnaryFunction1DFloat_getIntegrationType(BPy_UnaryFunction1DFloat* self);
/*----------------------UnaryFunction1DFloat instance definitions ----------------------------*/
static PyMethodDef BPy_UnaryFunction1DFloat_methods[] = {
{"getName", ( PyCFunction ) UnaryFunction1DFloat_getName, METH_NOARGS, "( )Returns the string of the name of the unary 1D function."},
- {"__call__", ( PyCFunction ) UnaryFunction1DFloat___call__, METH_VARARGS, "(Interface1D if1D )Builds a UnaryFunction1D from an integration type. " },
{"setIntegrationType", ( PyCFunction ) UnaryFunction1DFloat_setIntegrationType, METH_VARARGS, "(IntegrationType i )Sets the integration method" },
{"getIntegrationType", ( PyCFunction ) UnaryFunction1DFloat_getIntegrationType, METH_NOARGS, "() Returns the integration method." },
{NULL, NULL, 0, NULL}
@@ -55,7 +54,7 @@ PyTypeObject UnaryFunction1DFloat_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
- NULL, /* ternaryfunc tp_call; */
+ (ternaryfunc)UnaryFunction1DFloat___call__, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
@@ -166,13 +165,21 @@ PyObject * UnaryFunction1DFloat_getName( BPy_UnaryFunction1DFloat *self )
return PyString_FromString( self->uf1D_float->getName().c_str() );
}
-PyObject * UnaryFunction1DFloat___call__( BPy_UnaryFunction1DFloat *self, PyObject *args)
+PyObject * UnaryFunction1DFloat___call__( BPy_UnaryFunction1DFloat *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_float)) == typeid(UnaryFunction1D<float>) ) {
+ PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded");
+ return NULL;
+ }
if (self->uf1D_float->operator()(*( ((BPy_Interface1D *) obj)->if1D )) < 0) {
if (!PyErr_Occurred()) {
string msg(self->uf1D_float->getName() + " __call__ method failed");