Commit b271e764 authored by David Gobbi's avatar David Gobbi

Wrap namespaces in python.

For now, namespaces can only be used to define constants and enum types.
Any functions or methods in the namespace will not be wrapped.

Change-Id: If876e77f814630aa4cb0336579826fd9b58c66f2
parent 57b47954
......@@ -78,6 +78,7 @@ if(NOT CMAKE_CROSSCOMPILING)
vtkWrapPythonEnum.c
vtkWrapPythonMethod.c
vtkWrapPythonMethodDef.c
vtkWrapPythonNamespace.c
vtkWrapPythonOverload.c
vtkWrapPythonTemplate.c
vtkWrapPythonType.c
......
......@@ -17,6 +17,7 @@
#include "vtkWrapPythonConstant.h"
#include "vtkWrapPythonEnum.h"
#include "vtkWrapPythonMethodDef.h"
#include "vtkWrapPythonNamespace.h"
#include "vtkWrap.h"
#include "vtkParseMain.h"
......@@ -372,6 +373,12 @@ int main(int argc, char *argv[])
vtkWrapPython_GenerateEnumType(fp, NULL, contents->Enums[i]);
}
/* Wrap any namespaces */
for (i = 0; i < contents->NumberOfNamespaces; i++)
{
vtkWrapPython_WrapNamespace(fp, contents->Namespaces[i]);
}
/* Check for all special classes before any classes are wrapped */
for (i = 0; i < contents->NumberOfClasses; i++)
{
......@@ -423,7 +430,9 @@ int main(int argc, char *argv[])
}
/* The function for adding everything to the module dict */
wrapped_anything = (numberOfWrappedClasses || contents->NumberOfConstants);
wrapped_anything = (numberOfWrappedClasses ||
contents->NumberOfConstants ||
contents->NumberOfNamespaces);
fprintf(fp,
"void PyVTKAddFile_%s(\n"
" PyObject *%s, const char *%s)\n"
......@@ -434,6 +443,20 @@ int main(int argc, char *argv[])
(numberOfWrappedClasses ? "modulename" : ""),
(wrapped_anything ? " PyObject *o;\n" : ""));
/* Add all of the namespaces */
for (j = 0; j < contents->NumberOfNamespaces; j++)
{
fprintf(fp,
" o = PyVTKNamespace_%s();\n"
" if (o && PyDict_SetItemString(dict, (char *)\"%s\", o) != 0)\n"
" {\n"
" Py_DECREF(o);\n"
" }\n"
"\n",
contents->Namespaces[j]->Name,
contents->Namespaces[j]->Name);
}
/* Add all of the classes that have been wrapped */
for (i = 0; i < numberOfWrappedClasses; i++)
{
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonNamespace.c
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkWrapPythonNamespace.h"
#include "vtkWrapPythonConstant.h"
#include "vtkWrapPythonEnum.h"
#include "vtkWrap.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* -------------------------------------------------------------------- */
/* Wrap the namespace */
int vtkWrapPython_WrapNamespace(FILE *fp, NamespaceInfo *data)
{
int i;
/* create any enum types defined in the namespace */
for (i = 0; i < data->NumberOfEnums; i++)
{
vtkWrapPython_GenerateEnumType(
fp, data->Name, data->Enums[i]);
}
fprintf(fp,
"static PyObject *PyVTKNamespace_%s()\n"
"{\n"
" PyObject *m = PyModule_New(\"%s\");\n"
"\n",
data->Name, data->Name);
if (data->NumberOfEnums ||
data->NumberOfConstants)
{
fprintf(fp,
" PyObject *d = PyModule_GetDict(m);\n"
" PyObject *o;\n"
"\n");
/* add any enum types defined in the namespace */
for (i = 0; i < data->NumberOfEnums; i++)
{
vtkWrapPython_AddEnumType(
fp, " ", "d", "o", data->Name, data->Enums[i]);
fprintf(fp, "\n");
}
/* add any constants defined in the namespace */
for (i = 0; i < data->NumberOfConstants; i++)
{
vtkWrapPython_AddConstant(
fp, " ", "d", "o", data->Name, data->Constants[i]);
fprintf(fp, "\n");
}
}
fprintf(fp,
" return m;\n"
"}\n"
"\n");
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkWrapPythonNamespace.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef VTK_WRAP_PYTHON_NAMESPACE_H
#define VTK_WRAP_PYTHON_NAMESPACE_H
#include "vtkParse.h"
#include "vtkParseData.h"
#include "vtkParseHierarchy.h"
/* Wrap one class, returns zero if not wrappable */
int vtkWrapPython_WrapNamespace(FILE *fp, NamespaceInfo *data);
#endif /* VTK_WRAP_PYTHON_NAMESPACE_H */
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