VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "PyVTKObject.h"
26 #include "PyVTKSpecialObject.h"
27 
28 class vtkPythonClassMap;
29 class vtkPythonCommand;
30 class vtkPythonCommandList;
31 class vtkPythonGhostMap;
32 class vtkPythonObjectMap;
33 class vtkPythonSpecialTypeMap;
34 class vtkStdString;
35 class vtkUnicodeString;
36 class vtkVariant;
37 
38 extern "C" void vtkPythonUtilDelete();
39 
40 class VTKWRAPPINGPYTHONCORE_EXPORT vtkPythonUtil
41 {
42 public:
43 
46  static const char *PythonicClassName(const char *classname);
47 
50  static void AddClassToMap(PyObject *obj, const char *classname);
51 
53  static PyObject *FindClass(const char *classname);
54 
58  static PyObject *FindNearestBaseClass(vtkObjectBase *ptr);
59 
61 
65  static vtkObjectBase *GetPointerFromObject(PyObject *obj,
66  const char *classname);
68 
73  static PyObject *GetObjectFromPointer(vtkObjectBase *ptr);
74 
78  static void *SIPGetPointerFromObject(PyObject *obj, const char *classname);
79 
81 
83  static PyObject *SIPGetObjectFromPointer(
84  const void *ptr, const char* classname, bool is_new);
86 
89  static PyObject *GetObjectFromObject(PyObject *arg, const char *type);
90 
94  static void AddObjectToMap(PyObject *obj, vtkObjectBase *anInstance);
95 
98  static void RemoveObjectFromMap(PyObject *obj);
99 
101 
103  static PyVTKSpecialType *AddSpecialTypeToMap(
104  PyTypeObject *pytype, PyMethodDef *methods, PyMethodDef *constructors,
105  const char *docstring[], PyVTKSpecialCopyFunc copyfunc);
107 
109  static PyVTKSpecialType *FindSpecialType(const char *classname);
110 
112 
119  static void *GetPointerFromSpecialObject(
120  PyObject *obj, const char *result_type, PyObject **newobj);
122 
125  static PyObject *BuildDocString(const char *docstring[]);
126 
128  static char *ManglePointer(const void *ptr, const char *type);
129 
131  static void *UnmanglePointer(char *ptrText, int *len, const char *type);
132 
134  static long VariantHash(const vtkVariant *variant);
135 
137 
142  static void RegisterPythonCommand(vtkPythonCommand*);
143  static void UnRegisterPythonCommand(vtkPythonCommand*);
145 
146 private:
147  vtkPythonUtil();
148  ~vtkPythonUtil();
149  vtkPythonUtil(const vtkPythonUtil&); // Not implemented.
150  void operator=(const vtkPythonUtil&); // Not implemented.
151 
152  vtkPythonObjectMap *ObjectMap;
153  vtkPythonGhostMap *GhostMap;
154  vtkPythonClassMap *ClassMap;
155  vtkPythonSpecialTypeMap *SpecialTypeMap;
156  vtkPythonCommandList *PythonCommandList;
157 
158  friend void vtkPythonUtilDelete();
159  friend void vtkPythonUtilCreateIfNeeded();
160 };
161 
162 // For use by SetXXMethod() , SetXXMethodArgDelete()
163 extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFunc(void *);
164 extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFuncArgDelete(void *);
165 
166 // The following macro is used to suppress missing initializer
167 // warnings. Python documentation says these should not be necessary.
168 // We define it as a macro in case the length needs to change across
169 // python versions.
170 #if PY_VERSION_HEX >= 0x02060000 // for tp_version_tag
171 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \
172  0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0, 0,
173 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \
174  0, 0,
175 #elif PY_VERSION_HEX >= 0x02030000
176 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \
177  0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,
178 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \
179  0,
180 #elif PY_VERSION_HEX >= 0x02020000
181 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \
182  0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,
183 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED
184 #else
185 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED
186 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED
187 #endif
188 
189 #if PY_VERSION_HEX < 0x02050000
190  typedef int Py_ssize_t;
191 #endif
192 
193 #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:57
VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFunc(void *)
String class that stores Unicode text.