Missing code updates in the previous commit.

Also improved __repr__() so that the .getName() is no longer necessary in user-defined
Function0D and Function1D subclasses.
This commit is contained in:
2013-02-22 02:48:41 +00:00
parent 33f34e1a7b
commit a4a7341aef
18 changed files with 93 additions and 162 deletions
@@ -13,19 +13,19 @@ extern "C" {
//-------------------MODULE INITIALIZATION--------------------------------
int UnaryFunction0DVec3f_Init( PyObject *module ) {
int UnaryFunction0DVec3f_Init(PyObject *module) {
if( module == NULL )
if (module == NULL)
return -1;
if( PyType_Ready( &UnaryFunction0DVec3f_Type ) < 0 )
if (PyType_Ready(&UnaryFunction0DVec3f_Type) < 0)
return -1;
Py_INCREF( &UnaryFunction0DVec3f_Type );
Py_INCREF(&UnaryFunction0DVec3f_Type);
PyModule_AddObject(module, "UnaryFunction0DVec3f", (PyObject *)&UnaryFunction0DVec3f_Type);
if( PyType_Ready( &VertexOrientation3DF0D_Type ) < 0 )
if (PyType_Ready(&VertexOrientation3DF0D_Type) < 0)
return -1;
Py_INCREF( &VertexOrientation3DF0D_Type );
Py_INCREF(&VertexOrientation3DF0D_Type);
PyModule_AddObject(module, "VertexOrientation3DF0D", (PyObject *)&VertexOrientation3DF0D_Type);
return 0;
@@ -45,8 +45,10 @@ static char UnaryFunction0DVec3f___doc__[] =
static int UnaryFunction0DVec3f___init__(BPy_UnaryFunction0DVec3f* self, PyObject *args, PyObject *kwds)
{
if ( !PyArg_ParseTuple(args, "") )
return -1;
static const char *kwlist[] = {NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist))
return -1;
self->uf0D_vec3f = new UnaryFunction0D<Vec3f>();
self->uf0D_vec3f->py_uf0D = (PyObject *)self;
return 0;
@@ -61,51 +63,32 @@ static void UnaryFunction0DVec3f___dealloc__(BPy_UnaryFunction0DVec3f* self)
static PyObject * UnaryFunction0DVec3f___repr__(BPy_UnaryFunction0DVec3f* self)
{
return PyUnicode_FromFormat("type: %s - address: %p", self->uf0D_vec3f->getName().c_str(), self->uf0D_vec3f );
return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec3f);
}
static char UnaryFunction0DVec3f_getName___doc__[] =
".. method:: getName()\n"
"\n"
" Returns the name of the unary 0D predicate.\n"
"\n"
" :return: The name of the unary 0D predicate.\n"
" :rtype: str\n";
static PyObject * UnaryFunction0DVec3f_getName( BPy_UnaryFunction0DVec3f *self )
{
return PyUnicode_FromString( self->uf0D_vec3f->getName().c_str() );
}
static PyObject * UnaryFunction0DVec3f___call__( BPy_UnaryFunction0DVec3f *self, PyObject *args, PyObject *kwds)
static PyObject * UnaryFunction0DVec3f___call__(BPy_UnaryFunction0DVec3f *self, PyObject *args, PyObject *kwds)
{
static const char *kwlist[] = {"it", NULL};
PyObject *obj;
if( kwds != NULL ) {
PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj))
return NULL;
}
if(!PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj))
return NULL;
if( typeid(*(self->uf0D_vec3f)) == typeid(UnaryFunction0D<Vec3f>) ) {
if (typeid(*(self->uf0D_vec3f)) == typeid(UnaryFunction0D<Vec3f>)) {
PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
return NULL;
}
if (self->uf0D_vec3f->operator()(*( ((BPy_Interface0DIterator *) obj)->if0D_it )) < 0) {
if (self->uf0D_vec3f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
if (!PyErr_Occurred()) {
string class_name(Py_TYPE(self)->tp_name);
PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
}
return NULL;
}
return Vector_from_Vec3f( self->uf0D_vec3f->result );
return Vector_from_Vec3f(self->uf0D_vec3f->result);
}
/*----------------------UnaryFunction0DVec3f instance definitions ----------------------------*/
static PyMethodDef BPy_UnaryFunction0DVec3f_methods[] = {
{"getName", ( PyCFunction ) UnaryFunction0DVec3f_getName, METH_NOARGS, UnaryFunction0DVec3f_getName___doc__},
{NULL, NULL, 0, NULL}
};