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 
42 class VTKWRAPPINGPYTHONCORE_EXPORT vtkPythonUtil
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 
60  static PyObject *FindNearestBaseClass(vtkObjectBase *ptr);
61 
63 
67  static vtkObjectBase *GetPointerFromObject(PyObject *obj,
68  const char *classname);
70 
75  static PyObject *GetObjectFromPointer(vtkObjectBase *ptr);
76 
80  static void *SIPGetPointerFromObject(PyObject *obj, const char *classname);
81 
83 
85  static PyObject *SIPGetObjectFromPointer(
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 
100  static void RemoveObjectFromMap(PyObject *obj);
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 
121  static void *GetPointerFromSpecialObject(
122  PyObject *obj, const char *result_type, PyObject **newobj);
124 
127  static void AddNamespaceToMap(PyObject *o);
128 
131  static void RemoveNamespaceFromMap(PyObject *o);
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 
155  static void RegisterPythonCommand(vtkPythonCommand*);
156  static void UnRegisterPythonCommand(vtkPythonCommand*);
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();
173  friend void vtkPythonUtilCreateIfNeeded();
174 };
175 
176 // For use by SetXXMethod() , SetXXMethodArgDelete()
177 extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFunc(void *);
178 extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFuncArgDelete(void *);
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
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
int Py_ssize_t
void vtkPythonUtilDelete()
A atomic type representing the union of many types.
Definition: vtkVariant.h:78
VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFuncArgDelete(void *)
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFunc(void *)
struct _object PyObject
String class that stores Unicode text.