VTK
vtkPythonUtil.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPythonUtil.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
19 #ifndef vtkPythonUtil_h
20 #define vtkPythonUtil_h
21 
22 #include "vtkPython.h"
23 #include "PyVTKClass.h"
24 #include "PyVTKMutableObject.h"
25 #include "PyVTKNamespace.h"
26 #include "PyVTKObject.h"
27 #include "PyVTKSpecialObject.h"
28 
29 class vtkPythonClassMap;
30 class vtkPythonCommand;
31 class vtkPythonCommandList;
32 class vtkPythonGhostMap;
33 class vtkPythonObjectMap;
34 class vtkPythonSpecialTypeMap;
35 class vtkPythonNamespaceMap;
36 class vtkStdString;
37 class vtkUnicodeString;
38 class vtkVariant;
39 
40 extern "C" void vtkPythonUtilDelete();
41 
43 {
44 public:
45 
48  static const char *PythonicClassName(const char *classname);
49 
52  static void AddClassToMap(PyObject *obj, const char *classname);
53 
55  static PyObject *FindClass(const char *classname);
56 
61 
63 
68  const char *classname);
70 
76 
80  static void *SIPGetPointerFromObject(PyObject *obj, const char *classname);
81 
83 
86  const void *ptr, const char* classname, bool is_new);
88 
91  static PyObject *GetObjectFromObject(PyObject *arg, const char *type);
92 
96  static void AddObjectToMap(PyObject *obj, vtkObjectBase *anInstance);
97 
101 
103 
105  static PyVTKSpecialType *AddSpecialTypeToMap(
106  PyTypeObject *pytype, PyMethodDef *methods, PyMethodDef *constructors,
107  const char *docstring[], PyVTKSpecialCopyFunc copyfunc);
109 
111  static PyVTKSpecialType *FindSpecialType(const char *classname);
112 
114 
122  PyObject *obj, const char *result_type, PyObject **newobj);
124 
127  static void AddNamespaceToMap(PyObject *o);
128 
132 
134  static PyObject *FindNamespace(const char *name);
135 
138  static PyObject *BuildDocString(const char *docstring[]);
139 
141  static char *ManglePointer(const void *ptr, const char *type);
142 
144  static void *UnmanglePointer(char *ptrText, int *len, const char *type);
145 
147  static long VariantHash(const vtkVariant *variant);
148 
150 
158 
159 private:
160  vtkPythonUtil();
161  ~vtkPythonUtil();
162  vtkPythonUtil(const vtkPythonUtil&); // Not implemented.
163  void operator=(const vtkPythonUtil&); // Not implemented.
164 
165  vtkPythonObjectMap *ObjectMap;
166  vtkPythonGhostMap *GhostMap;
167  vtkPythonClassMap *ClassMap;
168  vtkPythonSpecialTypeMap *SpecialTypeMap;
169  vtkPythonNamespaceMap *NamespaceMap;
170  vtkPythonCommandList *PythonCommandList;
171 
172  friend void vtkPythonUtilDelete();
174 };
175 
176 // For use by SetXXMethod() , SetXXMethodArgDelete()
179 
180 // The following macro is used to suppress missing initializer
181 // warnings. Python documentation says these should not be necessary.
182 // We define it as a macro in case the length needs to change across
183 // python versions.
184 #if PY_VERSION_HEX >= 0x02060000 // for tp_version_tag
185 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \
186  0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0, 0,
187 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \
188  0, 0,
189 #elif PY_VERSION_HEX >= 0x02030000
190 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \
191  0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,
192 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \
193  0,
194 #elif PY_VERSION_HEX >= 0x02020000
195 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \
196  0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
197 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED
198 #else
199 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED
200 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED
201 #endif
202 
203 #if PY_VERSION_HEX < 0x02050000
204  typedef int Py_ssize_t;
205 #endif
206 
207 #endif
vtkPythonUtil::FindNearestBaseClass
static PyObject * FindNearestBaseClass(vtkObjectBase *ptr)
vtkPythonUtil::FindNamespace
static PyObject * FindNamespace(const char *name)
vtkgl::obj
GLsizei GLsizei GLuint * obj
Definition: vtkgl.h:11994
vtkPythonUtil::AddObjectToMap
static void AddObjectToMap(PyObject *obj, vtkObjectBase *anInstance)
vtkPythonUtil::GetPointerFromObject
static vtkObjectBase * GetPointerFromObject(PyObject *obj, const char *classname)
VTKWRAPPINGPYTHONCORE_EXPORT
#define VTKWRAPPINGPYTHONCORE_EXPORT
Definition: vtkWrappingPythonCoreModule.h:15
vtkPythonUtil::SIPGetObjectFromPointer
static PyObject * SIPGetObjectFromPointer(const void *ptr, const char *classname, bool is_new)
vtkPythonUtil::PythonicClassName
static const char * PythonicClassName(const char *classname)
vtkPythonUtil::vtkPythonUtilCreateIfNeeded
friend void vtkPythonUtilCreateIfNeeded()
vtkPythonUtil::VariantHash
static long VariantHash(const vtkVariant *variant)
PyObject
struct _object PyObject
Definition: vtkMatplotlibMathTextUtilities.h:37
Py_ssize_t
int Py_ssize_t
Definition: vtkPythonUtil.h:204
vtkPythonVoidFuncArgDelete
VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFuncArgDelete(void *)
vtkgl::name
GLuint const GLchar * name
Definition: vtkgl.h:11983
vtkPythonUtil::UnRegisterPythonCommand
static void UnRegisterPythonCommand(vtkPythonCommand *)
vtkPythonUtil::AddSpecialTypeToMap
static PyVTKSpecialType * AddSpecialTypeToMap(PyTypeObject *pytype, PyMethodDef *methods, PyMethodDef *constructors, const char *docstring[], PyVTKSpecialCopyFunc copyfunc)
vtkPythonUtil::BuildDocString
static PyObject * BuildDocString(const char *docstring[])
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:60
vtkPythonUtilDelete
void vtkPythonUtilDelete()
vtkPythonUtil::RemoveObjectFromMap
static void RemoveObjectFromMap(PyObject *obj)
vtkPythonUtil::FindSpecialType
static PyVTKSpecialType * FindSpecialType(const char *classname)
vtkPythonUtil::UnmanglePointer
static void * UnmanglePointer(char *ptrText, int *len, const char *type)
vtkPythonUtil::RemoveNamespaceFromMap
static void RemoveNamespaceFromMap(PyObject *o)
vtkPythonUtil::ManglePointer
static char * ManglePointer(const void *ptr, const char *type)
vtkPythonUtil::vtkPythonUtilDelete
friend void vtkPythonUtilDelete()
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:72
vtkPythonUtil::AddNamespaceToMap
static void AddNamespaceToMap(PyObject *o)
vtkPythonUtil::GetPointerFromSpecialObject
static void * GetPointerFromSpecialObject(PyObject *obj, const char *result_type, PyObject **newobj)
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:79
vtkPythonVoidFunc
VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFunc(void *)
vtkPythonUtil
Definition: vtkPythonUtil.h:43
vtkPythonUtil::FindClass
static PyObject * FindClass(const char *classname)
vtkPythonUtil::GetObjectFromObject
static PyObject * GetObjectFromObject(PyObject *arg, const char *type)
vtkPythonUtil::SIPGetPointerFromObject
static void * SIPGetPointerFromObject(PyObject *obj, const char *classname)
vtkPythonUtil::AddClassToMap
static void AddClassToMap(PyObject *obj, const char *classname)
vtkgl::len
GLenum GLsizei len
Definition: vtkgl.h:13010
vtkPythonCommand
Definition: vtkPythonCommand.h:25
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:48
vtkgl::type
GLuint GLuint GLsizei GLenum type
Definition: vtkgl.h:11315
vtkPythonUtil::GetObjectFromPointer
static PyObject * GetObjectFromPointer(vtkObjectBase *ptr)
vtkPythonUtil::RegisterPythonCommand
static void RegisterPythonCommand(vtkPythonCommand *)