Commit d0d6e833 authored by David Gobbi's avatar David Gobbi
Browse files

Simplify PyVTKClass struct by removing vtk_mangle.

The vtk_mangle member was exactly the same as the python name for
the class, so it can be retrieved from the PyTypeObject.  I also
renamed the vtk_cppname member to vtk_name and renamed its attrib
to __vtkname__.  This attrib is what the VTK GetClassName() method
returns.
parent 41c65801
......@@ -45,14 +45,12 @@ static PyTypeObject *PyVTKObject_Type = 0;
//--------------------------------------------------------------------
PyVTKClass::PyVTKClass(
PyTypeObject *typeobj, PyMethodDef *methods,
const char *classname, const char *manglename,
vtknewfunc constructor)
const char *classname, vtknewfunc constructor)
{
this->py_type = typeobj;
this->vtk_methods = methods;
this->py_methods = methods;
this->vtk_name = classname;
this->vtk_new = constructor;
this->vtk_cppname = classname;
this->vtk_mangle = (manglename ? manglename : classname);
}
//--------------------------------------------------------------------
......@@ -63,13 +61,13 @@ PyVTKClass::PyVTKClass(
// value of NULL signifies that the class was already added.
PyVTKClass *PyVTKClass_Add(
PyTypeObject *pytype, PyMethodDef *methods,
const char *classname, const char *manglename,
const char *docstring[], vtknewfunc constructor)
const char *classname, const char *docstring[],
vtknewfunc constructor)
{
// Add this type to the vtk class map
PyVTKClass *info =
vtkPythonUtil::AddClassToMap(
pytype, methods, classname, manglename, constructor);
pytype, methods, classname, constructor);
if (info == 0)
{
......@@ -94,9 +92,9 @@ PyVTKClass *PyVTKClass_Add(
PyDict_SetItemString(pytype->tp_dict, "__doc__", doc);
Py_DECREF(doc);
// Add special attribute __cppname__
// Add special attribute __vtkname__
PyObject *s = PyString_FromString(classname);
PyDict_SetItemString(pytype->tp_dict, "__cppname__", s);
PyDict_SetItemString(pytype->tp_dict, "__vtkname__", s);
Py_DECREF(s);
// Add all of the methods
......@@ -190,7 +188,7 @@ PyObject *PyVTKObject_New(PyTypeObject *tp, PyObject *args, PyObject *kwds)
if (o)
{
// should use vtk_mangle instead of tp_name, to match __this__
// used to create a VTK object from a SWIG pointer
return vtkPythonUtil::GetObjectFromObject(
o, vtkPythonUtil::StripModule(tp->tp_name));
}
......@@ -242,10 +240,10 @@ static PyObject *PyVTKObject_GetThis(PyObject *op, void *)
{
do { cp++; } while (isalnum(*cp) || *cp == '_');
}
// otherwise, use the mangled form of the class name
// otherwise, use the pythonic form of the class name
if (*cp != '\0')
{
classname = self->vtk_class->vtk_mangle;
classname = vtkPythonUtil::StripModule(op->ob_type->tp_name);
}
sprintf(buf, "p_%.500s", classname);
return PyString_FromString(
......@@ -352,8 +350,8 @@ PyObject *PyVTKObject_FromPointer(
if (cls == 0)
{
// Use the cppname of the supplied class type
PyObject *s = PyObject_GetAttrString((PyObject *)pytype, "__cppname__");
// Use the vtkname of the supplied class type
PyObject *s = PyObject_GetAttrString((PyObject *)pytype, "__vtkname__");
if (s)
{
classname = PyString_AsString(s);
......
......@@ -37,20 +37,16 @@ class VTKWRAPPINGPYTHONCORE_EXPORT PyVTKClass
{
public:
PyVTKClass() :
py_type(0), vtk_methods(0), vtk_new(0),
vtk_cppname(0), vtk_mangle(0) {}
py_type(0), py_methods(0), vtk_name(0), vtk_new(0) {}
PyVTKClass(
PyTypeObject *typeobj, PyMethodDef *methods,
const char *classname, const char *manglename,
vtknewfunc constructor);
const char *classname, vtknewfunc constructor);
// general information
PyTypeObject *py_type;
PyMethodDef *vtk_methods;
PyMethodDef *py_methods;
const char *vtk_name; // the name returned by GetClassName()
vtknewfunc vtk_new; // creates a C++ instance of classtype
const char *vtk_cppname; // set to typeid(classtype).name()
const char *vtk_mangle; // the classtype, mangled with vtkParseMangle
};
// This is the VTK/Python 'object,' it contains the python object header
......@@ -73,7 +69,7 @@ extern "C"
VTKWRAPPINGPYTHONCORE_EXPORT
PyVTKClass *PyVTKClass_Add(
PyTypeObject *pytype, PyMethodDef *methods, const char *classname,
const char *manglename, const char *docstring[], vtknewfunc constructor);
const char *docstring[], vtknewfunc constructor);
VTKWRAPPINGPYTHONCORE_EXPORT
int PyVTKObject_Check(PyObject *obj);
......
......@@ -519,7 +519,7 @@ const char *vtkPythonUtil::PythonicClassName(const char *classname)
PyVTKClass *o = vtkPythonUtil::FindClass(classname);
if (o)
{
classname = o->vtk_mangle;
classname = vtkPythonUtil::StripModule(o->py_type->tp_name);
}
}
......@@ -544,8 +544,7 @@ const char *vtkPythonUtil::StripModule(const char *tpname)
//--------------------------------------------------------------------
PyVTKClass *vtkPythonUtil::AddClassToMap(
PyTypeObject *pytype, PyMethodDef *methods,
const char *classname, const char *manglename,
vtknewfunc constructor)
const char *classname, vtknewfunc constructor)
{
vtkPythonUtilCreateIfNeeded();
......@@ -560,7 +559,7 @@ PyVTKClass *vtkPythonUtil::AddClassToMap(
i = vtkPythonMap->ClassMap->insert(i,
vtkPythonClassMap::value_type(
classname,
PyVTKClass(pytype, methods, classname, manglename, constructor)));
PyVTKClass(pytype, methods, classname, constructor)));
return &i->second;
}
......@@ -596,7 +595,7 @@ PyVTKClass *vtkPythonUtil::FindNearestBaseClass(vtkObjectBase *ptr)
{
PyVTKClass *pyclass = &classes->second;
if (ptr->IsA(pyclass->vtk_cppname))
if (ptr->IsA(pyclass->vtk_name))
{
PyTypeObject *base = pyclass->py_type->tp_base;
// count the hierarchy depth for this class
......
......@@ -56,8 +56,7 @@ public:
// create object given only the class name.
static PyVTKClass *AddClassToMap(
PyTypeObject *pytype, PyMethodDef *methods,
const char *classname, const char *manglename,
vtknewfunc constructor);
const char *classname, vtknewfunc constructor);
// Description:
// Get information about a special VTK type, given the type name.
......
......@@ -361,7 +361,7 @@ static void vtkWrapPython_GenerateObjectNew(
if (strcmp(data->Name, classname) == 0)
{
fprintf(fp,
" \"%s\", NULL,\n"
" \"%s\",\n"
" Py%s_Doc(),",
classname, classname);
}
......@@ -369,9 +369,9 @@ static void vtkWrapPython_GenerateObjectNew(
{
/* use of typeid() matches vtkTypeTemplate */
fprintf(fp,
" typeid(%s).name(), \"%s\",\n"
" typeid(%s).name(),\n"
" Py%s_Doc(),",
data->Name, classname, classname);
data->Name, classname);
}
if (class_has_new)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment