Commit f5ed6d8c authored by David Gobbi's avatar David Gobbi Committed by Marcus D. Hanwell
Browse files

ENH: docstring for special object constructors

parent d87c3486
......@@ -29,6 +29,7 @@
#include <vtksys/ios/sstream>
#include <vtkstd/map>
#include <vtkstd/string>
#include <vtkstd/utility>
// Silent warning like
// "dereferencing type-punned pointer will break strict-aliasing rules"
......@@ -1857,7 +1858,7 @@ PyVTKSpecialTypeInfo::PyVTKSpecialTypeInfo(
}
//--------------------------------------------------------------------
void vtkPythonAddSpecialTypeToHash(
PyVTKSpecialTypeInfo *vtkPythonAddSpecialTypeToHash(
char *classname, char *docstring[], PyMethodDef *methods,
PyMethodDef *constructors, PyVTKSpecialCopyFunc copy_func,
PyVTKSpecialDeleteFunc delete_func, PyVTKSpecialPrintFunc print_func)
......@@ -1880,16 +1881,20 @@ void vtkPythonAddSpecialTypeToHash(
#ifdef VTKPYTHONDEBUG
vtkGenericWarningMacro("Attempt to add type to the hash when already there!!!");
#endif
return;
return 0;
}
(*vtkPythonHash->SpecialTypeHash)[classname] =
PyVTKSpecialTypeInfo(classname, docstring, methods, constructors,
copy_func, delete_func, print_func);
i = vtkPythonHash->SpecialTypeHash->insert(i,
vtkstd::pair<const vtkstd::string, PyVTKSpecialTypeInfo>(
classname,
PyVTKSpecialTypeInfo(classname, docstring, methods, constructors,
copy_func, delete_func, print_func)));
#ifdef VTKPYTHONDEBUG
// vtkGenericWarningMacro("Added type to hash type = " << typeObject);
#endif
return &i->second;
}
//--------------------------------------------------------------------
......
......@@ -154,7 +154,7 @@ PyObject *vtkPythonGetObjectFromObject(PyObject *arg, const char *type);
// Add a non-VTK type to the type lookup table, this allows us to later
// create object given only the class name.
extern VTK_PYTHON_EXPORT
void vtkPythonAddSpecialTypeToHash(
PyVTKSpecialTypeInfo *vtkPythonAddSpecialTypeToHash(
char *classname, char *docstring[], PyMethodDef *methods,
PyMethodDef *constructors, PyVTKSpecialCopyFunc copyfunc,
PyVTKSpecialDeleteFunc deletefunc, PyVTKSpecialPrintFunc printfunc);
......
......@@ -2071,20 +2071,20 @@ static void vtkWrapPython_ClassDoc(FILE *fp, FileInfo *data)
text++;
}
fprintf(fp,
" (char*)\"%s\\n\\n\",\n",
" \"%s\\n\\n\",\n",
vtkWrapPython_QuoteString(text,500));
}
else
{
fprintf(fp,
" (char*)\"%s - no description provided.\\n\\n\",\n",
" \"%s - no description provided.\\n\\n\",\n",
vtkWrapPython_QuoteString(data->ClassName,500));
}
if (data->NumberOfSuperClasses > 0)
{
fprintf(fp,
" \"Super Class:\\n\\n %s\\n\\n\",\n",
" \"Super Class:\\n\\n %s\\n\\n\",\n",
vtkWrapPython_QuoteString(data->SuperClasses[0],500));
}
......@@ -2098,13 +2098,13 @@ static void vtkWrapPython_ClassDoc(FILE *fp, FileInfo *data)
if (i < n-1)
{
fprintf(fp,
" (char*)\"%s\",\n",
" \"%s\",\n",
vtkWrapPython_QuoteString(temp,500));
}
else
{ /* just for the last time */
fprintf(fp,
" (char*)\"%s\\n\",\n",
" \"%s\\n\",\n",
vtkWrapPython_QuoteString(temp,500));
}
}
......@@ -2112,14 +2112,14 @@ static void vtkWrapPython_ClassDoc(FILE *fp, FileInfo *data)
else
{
fprintf(fp,
" (char*)\"%s\\n\",\n",
" \"%s\\n\",\n",
"None provided.\\n");
}
if (data->Caveats)
{
fprintf(fp,
" \"Caveats:\\n\\n%s\\n\",\n",
" \"Caveats:\\n\\n%s\\n\",\n",
vtkWrapPython_QuoteString(data->Caveats,500));
}
......@@ -2128,21 +2128,31 @@ static void vtkWrapPython_ClassDoc(FILE *fp, FileInfo *data)
char *sdup, *tok;
fprintf(fp,
" \"See Also:\\n\\n");
" \"See Also:\\n\\n");
sdup = strdup(data->SeeAlso);
tok = strtok(sdup," ");
while (tok)
{
fprintf(fp," %s",vtkWrapPython_QuoteString(tok,120));
fprintf(fp," %s",vtkWrapPython_QuoteString(tok,120));
tok = strtok(NULL," ");
}
free(sdup);
fprintf(fp,"\\n\",\n");
}
fprintf(fp,
" NULL\n");
/* for special objects, add constructor signatures to the doc */
if ((data->NumberOfSuperClasses == 0) &&
(strcmp(data->ClassName,"vtkObjectBase") != 0))
{
for (i = 0; i < data->NumberOfFunctions; i++)
{
if (vtkWrapPython_MethodCheck(data, &data->Functions[i], 1))
{
fprintf(fp," \"%s\\n\",\n", data->Functions[i].Signature);
}
}
}
}
/* -------------------------------------------------------------------- */
......@@ -2201,6 +2211,16 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
data->SuperClasses[i]);
}
/* prototype for the docstring function */
if (data->NumberOfSuperClasses || !data->IsAbstract)
{
fprintf(fp,
"\n"
"static const char **%sDoc();\n"
"\n",
data->ClassName);
}
/* the python vtkObject needs special hooks for observers */
if (!strcmp("vtkObject",data->ClassName))
{
......@@ -2315,20 +2335,6 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
vtkWrapPython_GenerateMethods(fp, data, class_has_new, 0);
}
/* the docstring for the class, as a static var ending in "Doc" */
if (data->NumberOfSuperClasses || !data->IsAbstract)
{
fprintf(fp,
"static const char *%sDoc[] = {\n",
data->ClassName);
vtkWrapPython_ClassDoc(fp,data);
fprintf(fp,
"};\n"
"\n");
}
/* output the class initilization function */
/* the New method for vtkObjectBase */
......@@ -2365,7 +2371,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp,
" Py%sMethods,\n"
" (char*)\"%s\",modulename,\n"
" (char**)%sDoc,0);\n"
" (char**)%sDoc(),0);\n"
"}\n"
"\n",
data->ClassName, data->ClassName, data->ClassName);
......@@ -2405,7 +2411,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp,
" Py%sMethods,\n"
" (char*)\"%s\",modulename,\n"
" (char**)%sDoc,\n"
" (char**)%sDoc(),\n"
" PyVTKClass_%sNew(modulename));\n"
"}\n"
"\n",
......@@ -2423,10 +2429,10 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp,
"static PyMethodDef Py%sNewMethod = \\\n"
"{ (char*)\"%s\", (PyCFunction)Py%s_%s, 1,\n"
" (char*)%sDoc[0] };\n"
" (char*)\"\" };\n"
"\n",
data->ClassName, data->ClassName, data->ClassName,
data->ClassName, data->ClassName);
data->ClassName);
/* the copy constructor */
fprintf(fp,
......@@ -2469,17 +2475,21 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp,
"PyObject *PyVTKClass_%sNew(char *)\n"
"{\n"
" vtkPythonAddSpecialTypeToHash(\n"
" (char *)\"%s\", (char**)%sDoc, Py%sMethods,\n"
" Py%s_%sMethods, &vtkSpecial_%sCopy,\n"
" &vtkSpecial_%sDelete, &vtkSpecial_%sPrint);\n"
" PyVTKSpecialTypeInfo *info =\n"
" vtkPythonAddSpecialTypeToHash(\n"
" (char *)\"%s\", (char**)%sDoc(), Py%sMethods,\n"
" Py%s_%sMethods, &vtkSpecial_%sCopy,\n"
" &vtkSpecial_%sDelete, &vtkSpecial_%sPrint);\n"
"\n"
" Py%sNewMethod.ml_doc = PyString_AsString(info->docstring);\n"
"\n"
" return PyCFunction_New(&Py%sNewMethod,Py_None);\n"
"}\n"
"\n",
data->ClassName, data->ClassName, data->ClassName,
data->ClassName, data->ClassName, data->ClassName,
data->ClassName, data->ClassName, data->ClassName,
data->ClassName);
data->ClassName, data->ClassName);
}
/* the New method for un-wrappable classes returns "NULL" */
......@@ -2493,5 +2503,25 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
"\n",
data->ClassName);
}
/* the docstring for the class, as a static var ending in "Doc" */
if (data->NumberOfSuperClasses || !data->IsAbstract)
{
fprintf(fp,
"const char **%sDoc()\n"
"{\n"
" static const char *docstring[] = {\n",
data->ClassName);
vtkWrapPython_ClassDoc(fp,data);
fprintf(fp,
" NULL\n"
" };\n"
"\n"
" return docstring;\n"
"}\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