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

Special wrapping for abstract classes.

The "special type" wrapping for abstract classes was disabled, making
it impossible to define non-concrete base classes for special types.
parent b7da2abd
......@@ -278,7 +278,7 @@ void vtkWrapPython_ClassDoc(
}
/* for special objects, add constructor signatures to the doc */
if (!is_vtkobject && !data->Template)
if (!is_vtkobject && !data->Template && !data->IsAbstract)
{
for (j = 0; j < data->NumberOfFunctions; j++)
{
......@@ -566,11 +566,8 @@ int vtkWrapPython_WrapOneClass(
}
/* now output all the methods are wrappable */
if (is_vtkobject || !data->IsAbstract)
{
vtkWrapPython_GenerateMethods(
fp, classname, data, finfo, hinfo, is_vtkobject, 0);
}
vtkWrapPython_GenerateMethods(
fp, classname, data, finfo, hinfo, is_vtkobject, 0);
/* output the class initilization function for VTK objects */
if (is_vtkobject)
......@@ -582,31 +579,28 @@ int vtkWrapPython_WrapOneClass(
}
/* output the class initilization function for special objects */
else if (!data->IsAbstract)
else
{
vtkWrapPython_GenerateSpecialType(
fp, module, classname, data, finfo, hinfo);
}
/* the docstring for the class, as a static var ending in "Doc" */
if (is_vtkobject || !data->IsAbstract)
{
fprintf(fp,
"const char **Py%s_Doc()\n"
"{\n"
" static const char *docstring[] = {\n",
classname);
fprintf(fp,
"const char **Py%s_Doc()\n"
"{\n"
" static const char *docstring[] = {\n",
classname);
vtkWrapPython_ClassDoc(fp, finfo, data, hinfo, is_vtkobject);
vtkWrapPython_ClassDoc(fp, finfo, data, hinfo, is_vtkobject);
fprintf(fp,
" NULL\n"
" };\n"
"\n"
" return docstring;\n"
"}\n"
"\n");
}
fprintf(fp,
" NULL\n"
" };\n"
"\n"
" return docstring;\n"
"}\n"
"\n");
return 1;
}
......@@ -71,7 +71,23 @@ static void vtkWrapPython_NewDeleteProtocol(
}
/* the "new" method */
fprintf(fp,
if (data->IsAbstract)
{
fprintf(fp,
"static PyObject *\n"
"Py%s_New(PyTypeObject *, PyObject *, PyObject *)\n"
"{\n"
" PyErr_SetString(PyExc_TypeError,\n"
" \"this abstract class cannot be instantiated\");\n"
"\n"
" return NULL;\n"
"}\n"
"\n",
classname);
}
else
{
fprintf(fp,
"static PyObject *\n"
"Py%s_New(PyTypeObject *, PyObject *args, PyObject *kwds)\n"
"{\n"
......@@ -86,6 +102,7 @@ static void vtkWrapPython_NewDeleteProtocol(
"}\n"
"\n",
classname, classname, (int)n, (int)n, constructor);
}
/* the delete method */
fprintf(fp,
......@@ -589,12 +606,7 @@ int vtkWrapPython_IsSpecialTypeWrappable(ClassInfo *data)
return 0;
}
/* no abstract classes */
if (data->IsAbstract)
{
return 0;
}
/* restrict wrapping to classes that have a "vtk" prefix */
if (strncmp(data->Name, "vtk", 3) != 0)
{
return 0;
......@@ -653,7 +665,10 @@ void vtkWrapPython_GenerateSpecialType(
}
/* generate all constructor methods */
vtkWrapPython_GenerateMethods(fp, classname, data, finfo, hinfo, 0, 1);
if (!data->IsAbstract)
{
vtkWrapPython_GenerateMethods(fp, classname, data, finfo, hinfo, 0, 1);
}
/* generate all functions and protocols needed for the type */
vtkWrapPython_SpecialTypeProtocols(
......@@ -778,7 +793,9 @@ void vtkWrapPython_GenerateSpecialType(
}
/* generate the copy constructor helper function */
fprintf(fp,
if (!data->IsAbstract)
{
fprintf(fp,
"static void *Py%s_CCopy(const void *obj)\n"
"{\n"
" if (obj)\n"
......@@ -789,6 +806,7 @@ void vtkWrapPython_GenerateSpecialType(
"}\n"
"\n",
classname, data->Name, data->Name);
}
/* export New method for use by subclasses */
fprintf(fp,
......@@ -810,16 +828,33 @@ void vtkWrapPython_GenerateSpecialType(
* the unused "const char *" arg is the module name */
fprintf(fp,
"PyObject *Py%s_TypeNew()\n"
"{\n"
"{\n",
classname);
if (data->IsAbstract)
{
fprintf(fp,
" PyVTKSpecialType_Add(\n"
" &Py%s_Type,\n"
" Py%s_Methods,\n"
" NULL,\n"
" Py%s_Doc(), NULL);\n"
"\n",
classname, classname, classname);
}
else
{
fprintf(fp,
" PyVTKSpecialType_Add(\n"
" &Py%s_Type,\n"
" Py%s_Methods,\n"
" Py%s_%*.*s_Methods,\n"
" Py%s_Doc(), &Py%s_CCopy);\n"
"\n",
classname, classname, classname,
classname, classname,
classname, (int)n, (int)n, constructor,
classname, classname);
}
fprintf(fp,
" PyTypeObject *pytype = &Py%s_Type;\n\n",
......
Markdown is supported
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