VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkPythonUtil.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 00019 #ifndef vtkPythonUtil_h 00020 #define vtkPythonUtil_h 00021 00022 #include "vtkPython.h" 00023 #include "PyVTKClass.h" 00024 #include "PyVTKMutableObject.h" 00025 #include "PyVTKNamespace.h" 00026 #include "PyVTKObject.h" 00027 #include "PyVTKSpecialObject.h" 00028 00029 class vtkPythonClassMap; 00030 class vtkPythonCommand; 00031 class vtkPythonCommandList; 00032 class vtkPythonGhostMap; 00033 class vtkPythonObjectMap; 00034 class vtkPythonSpecialTypeMap; 00035 class vtkPythonNamespaceMap; 00036 class vtkStdString; 00037 class vtkUnicodeString; 00038 class vtkVariant; 00039 00040 extern "C" void vtkPythonUtilDelete(); 00041 00042 class VTKWRAPPINGPYTHONCORE_EXPORT vtkPythonUtil 00043 { 00044 public: 00045 00048 static const char *PythonicClassName(const char *classname); 00049 00052 static void AddClassToMap(PyObject *obj, const char *classname); 00053 00055 static PyObject *FindClass(const char *classname); 00056 00060 static PyObject *FindNearestBaseClass(vtkObjectBase *ptr); 00061 00063 00067 static vtkObjectBase *GetPointerFromObject(PyObject *obj, 00068 const char *classname); 00070 00075 static PyObject *GetObjectFromPointer(vtkObjectBase *ptr); 00076 00080 static void *SIPGetPointerFromObject(PyObject *obj, const char *classname); 00081 00083 00085 static PyObject *SIPGetObjectFromPointer( 00086 const void *ptr, const char* classname, bool is_new); 00088 00091 static PyObject *GetObjectFromObject(PyObject *arg, const char *type); 00092 00096 static void AddObjectToMap(PyObject *obj, vtkObjectBase *anInstance); 00097 00100 static void RemoveObjectFromMap(PyObject *obj); 00101 00103 00105 static PyVTKSpecialType *AddSpecialTypeToMap( 00106 PyTypeObject *pytype, PyMethodDef *methods, PyMethodDef *constructors, 00107 const char *docstring[], PyVTKSpecialCopyFunc copyfunc); 00109 00111 static PyVTKSpecialType *FindSpecialType(const char *classname); 00112 00114 00121 static void *GetPointerFromSpecialObject( 00122 PyObject *obj, const char *result_type, PyObject **newobj); 00124 00127 static void AddNamespaceToMap(PyObject *o); 00128 00131 static void RemoveNamespaceFromMap(PyObject *o); 00132 00134 static PyObject *FindNamespace(const char *name); 00135 00138 static PyObject *BuildDocString(const char *docstring[]); 00139 00141 static char *ManglePointer(const void *ptr, const char *type); 00142 00144 static void *UnmanglePointer(char *ptrText, int *len, const char *type); 00145 00147 static long VariantHash(const vtkVariant *variant); 00148 00150 00155 static void RegisterPythonCommand(vtkPythonCommand*); 00156 static void UnRegisterPythonCommand(vtkPythonCommand*); 00158 00159 private: 00160 vtkPythonUtil(); 00161 ~vtkPythonUtil(); 00162 vtkPythonUtil(const vtkPythonUtil&); // Not implemented. 00163 void operator=(const vtkPythonUtil&); // Not implemented. 00164 00165 vtkPythonObjectMap *ObjectMap; 00166 vtkPythonGhostMap *GhostMap; 00167 vtkPythonClassMap *ClassMap; 00168 vtkPythonSpecialTypeMap *SpecialTypeMap; 00169 vtkPythonNamespaceMap *NamespaceMap; 00170 vtkPythonCommandList *PythonCommandList; 00171 00172 friend void vtkPythonUtilDelete(); 00173 friend void vtkPythonUtilCreateIfNeeded(); 00174 }; 00175 00176 // For use by SetXXMethod() , SetXXMethodArgDelete() 00177 extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFunc(void *); 00178 extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFuncArgDelete(void *); 00179 00180 // The following macro is used to suppress missing initializer 00181 // warnings. Python documentation says these should not be necessary. 00182 // We define it as a macro in case the length needs to change across 00183 // python versions. 00184 #if PY_VERSION_HEX >= 0x02060000 // for tp_version_tag 00185 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \ 00186 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0, 0, 00187 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \ 00188 0, 0, 00189 #elif PY_VERSION_HEX >= 0x02030000 00190 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \ 00191 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0, 00192 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \ 00193 0, 00194 #elif PY_VERSION_HEX >= 0x02020000 00195 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \ 00196 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 00197 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED 00198 #else 00199 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED 00200 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED 00201 #endif 00202 00203 #if PY_VERSION_HEX < 0x02050000 00204 typedef int Py_ssize_t; 00205 #endif 00206 00207 #endif