VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkPythonArgs.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 /*----------------------------------------------------------------------- 00016 The vtkPythonArgs class was created in Oct 2010 by David Gobbi for. 00017 00018 This class provides methods for reading an argument tuple from Python 00019 and converting it to types that can be used by VTK. It is meant to be 00020 more efficient and flexible that the original PyArg_ParseTuple() code, 00021 resulting in wrapper code that is faster and more compact. 00022 -----------------------------------------------------------------------*/ 00023 00027 #ifndef vtkPythonArgs_h 00028 #define vtkPythonArgs_h 00029 00030 #include "vtkWrappingPythonCoreModule.h" // For export macro 00031 #include "vtkPythonUtil.h" 00032 #include "PyVTKClass.h" 00033 #include "PyVTKTemplate.h" 00034 00035 #include "vtkConfigure.h" 00036 #include "vtkUnicodeString.h" 00037 00038 #include <string> 00039 00040 class VTKWRAPPINGPYTHONCORE_EXPORT vtkPythonArgs 00041 { 00042 public: 00043 00045 00046 vtkPythonArgs(PyObject *self, PyObject *args, const char *methodname) : 00047 Args(args), MethodName(methodname) { 00048 this->N = PyTuple_GET_SIZE(args); 00049 this->M = PyVTKClass_Check(self); 00050 this->I = this->M; 00051 } 00053 00055 00056 vtkPythonArgs(PyObject *args, const char *methodname) : 00057 Args(args), MethodName(methodname) { 00058 this->N = PyTuple_GET_SIZE(args); 00059 this->M = 0; 00060 this->I = 0; 00061 } 00063 00065 void Reset() { this->I = this->M; } 00066 00070 static vtkObjectBase *GetSelfPointer(PyObject *self, PyObject *args); 00071 00074 static void *GetSelfPointer(PyObject *self); 00075 00077 bool CheckArgCount(int nmin, int nmax); 00078 00080 bool CheckArgCount(int n); 00081 00083 bool IsBound() { return (this->M == 0); } 00084 00086 bool IsPureVirtual(); 00087 00089 static bool ErrorOccurred(); 00090 00092 bool NoArgsLeft() { return (this->I >= this->N); } 00093 00097 int GetArgSize(int i); 00098 00100 00101 bool GetPythonObject(PyObject *&v) { 00102 bool b; 00103 v = this->GetArgAsPythonObject(b); 00104 return b; } 00105 bool GetPythonObject(PyObject *o, PyObject *&v) { 00106 bool b; 00107 v = vtkPythonArgs::GetArgAsPythonObject(o, b); 00108 return b; } 00110 00112 00116 template<class T> 00117 bool GetVTKObject(T *&v, const char *classname) { 00118 bool b; 00119 v = (T *)this->GetArgAsVTKObject(classname, b); 00120 return b; } 00121 template<class T> 00122 bool GetVTKObject(PyObject *o, T *&v, const char *classname) { 00123 bool b; 00124 v = (T *)vtkPythonArgs::GetArgAsVTKObject(o, classname, b); 00125 return b; } 00127 00129 00132 template<class T> 00133 bool GetSpecialObject(T *&v, PyObject *&o, const char *classname) { 00134 v = static_cast<T *>(this->GetArgAsSpecialObject(classname, &o)); 00135 return (v != NULL); } 00136 template<class T> 00137 static bool GetSpecialObject( 00138 PyObject *arg, T *&v, PyObject *&o, const char *classname) { 00139 v = static_cast<T *>( 00140 vtkPythonArgs::GetArgAsSpecialObject(arg, classname, &o)); 00141 return (v != NULL); } 00143 00145 00147 template<class T> 00148 bool GetSpecialObject(T *&v, const char *classname) { 00149 v = static_cast<T *>(this->GetArgAsSpecialObject(classname, NULL)); 00150 return (v != NULL); } 00151 template<class T> 00152 static bool GetSpecialObject(PyObject *o, T *&v, const char *classname) { 00153 v = static_cast<T *>( 00154 vtkPythonArgs::GetArgAsSpecialObject(o, classname, NULL)); 00155 return (v != NULL); } 00157 00159 00160 template<class T> 00161 bool GetEnumValue(T &v, PyTypeObject *enumtype) { 00162 bool r; 00163 v = static_cast<T>(this->GetArgAsEnum(enumtype, r)); 00164 return r; } 00165 template<class T> 00166 static bool GetEnumValue(PyObject *o, T &v, PyTypeObject *enumtype) { 00167 bool r; 00168 v = static_cast<T>(vtkPythonArgs::GetArgAsEnum(o, enumtype, r)); 00169 return r; } 00171 00173 00174 template<class T> 00175 bool GetSIPObject(T *&v, const char *classname) { 00176 bool r; 00177 v = (T *)this->GetArgAsSIPObject(classname, r); 00178 return r; } 00179 template<class T> 00180 static bool GetSIPObject(PyObject *o, T *&v, const char *classname) { 00181 bool r; 00182 v = (T *)vtkPythonArgs::GetArgAsSIPObject(o, classname, r); 00183 return r; } 00185 00187 00188 template<class T> 00189 bool GetSIPEnumValue(T &v, const char *enumname) { 00190 bool r; 00191 v = static_cast<T>(this->GetArgAsSIPEnum(enumname, r)); 00192 return r; } 00193 template<class T> 00194 static bool GetSIPEnumValue(PyObject *o, T &v, const char *enumname) { 00195 bool r; 00196 v = static_cast<T>(vtkPythonArgs::GetArgAsSIPEnum(o, enumname, r)); 00197 return r; } 00199 00201 00203 bool GetFunction(PyObject *&o); 00204 static bool GetFunction(PyObject *arg, PyObject *&o); 00206 00207 // Get the next arg as a void pointer (to a buffer object). 00208 bool GetValue(void *&v); 00209 static bool GetValue(PyObject *o, void *&v); 00210 bool GetValue(const void *&v); 00211 static bool GetValue(PyObject *o, const void *&v); 00212 00214 00215 bool GetValue(const char *&v); 00216 static bool GetValue(PyObject *o, const char *&v); 00217 bool GetValue(char *&v); 00218 static bool GetValue(PyObject *o, char *&v); 00219 bool GetValue(std::string &v); 00220 static bool GetValue(PyObject *o, std::string &v); 00221 bool GetValue(vtkUnicodeString &v); 00222 static bool GetValue(PyObject *o, vtkUnicodeString &v); 00224 00226 00227 bool GetValue(char &v); 00228 static bool GetValue(PyObject *o, char &v); 00230 00232 00233 bool GetValue(float &v); 00234 static bool GetValue(PyObject *o, float &v); 00235 bool GetValue(double &v); 00236 static bool GetValue(PyObject *o, double &v); 00237 bool GetValue(bool &v); 00238 static bool GetValue(PyObject *o, bool &v); 00239 bool GetValue(signed char &v); 00240 static bool GetValue(PyObject *o, signed char &v); 00241 bool GetValue(unsigned char &v); 00242 static bool GetValue(PyObject *o, unsigned char &v); 00243 bool GetValue(short &v); 00244 static bool GetValue(PyObject *o, short &v); 00245 bool GetValue(unsigned short &v); 00246 static bool GetValue(PyObject *o, unsigned short &v); 00247 bool GetValue(int &v); 00248 static bool GetValue(PyObject *o, int &v); 00249 bool GetValue(unsigned int &v); 00250 static bool GetValue(PyObject *o, unsigned int &v); 00251 bool GetValue(long &v); 00252 static bool GetValue(PyObject *o, long &v); 00253 bool GetValue(unsigned long &v); 00254 static bool GetValue(PyObject *o, unsigned long &v); 00255 #ifdef VTK_TYPE_USE_LONG_LONG 00256 bool GetValue(long long &v); 00257 static bool GetValue(PyObject *o, long long &v); 00258 bool GetValue(unsigned long long &v); 00259 static bool GetValue(PyObject *o, unsigned long long &v); 00260 #endif 00261 #ifdef VTK_TYPE_USE___INT64 00262 bool GetValue(__int64 &v); 00263 static bool GetValue(PyObject *o, __int64 &v); 00264 bool GetValue(unsigned __int64 &v); 00265 static bool GetValue(PyObject *o, unsigned __int64 &v); 00266 #endif 00267 00268 00270 00271 bool GetArray(float *v, int n); 00272 bool GetArray(double *v, int n); 00273 bool GetArray(bool *v, int n); 00274 bool GetArray(char *v, int n); 00275 bool GetArray(signed char *v, int n); 00276 bool GetArray(unsigned char *v, int n); 00277 bool GetArray(short *v, int n); 00278 bool GetArray(unsigned short *v, int n); 00279 bool GetArray(int *v, int n); 00280 bool GetArray(unsigned int *v, int n); 00281 bool GetArray(long *v, int n); 00282 bool GetArray(unsigned long *v, int n); 00283 #ifdef VTK_TYPE_USE_LONG_LONG 00284 bool GetArray(long long *v, int n); 00285 bool GetArray(unsigned long long *v, int n); 00286 #endif 00287 #ifdef VTK_TYPE_USE___INT64 00288 bool GetArray(__int64 *v, int n); 00289 bool GetArray(unsigned __int64 *v, int n); 00290 #endif 00291 00292 00294 00295 bool GetNArray(float *v, int ndims, const int *dims); 00296 bool GetNArray(double *v, int ndims, const int *dims); 00297 bool GetNArray(bool *v, int ndims, const int *dims); 00298 bool GetNArray(char *v, int ndims, const int *dims); 00299 bool GetNArray(signed char *v, int ndims, const int *dims); 00300 bool GetNArray(unsigned char *v, int ndims, const int *dims); 00301 bool GetNArray(short *v, int ndims, const int *dims); 00302 bool GetNArray(unsigned short *v, int ndims, const int *dims); 00303 bool GetNArray(int *v, int ndims, const int *dims); 00304 bool GetNArray(unsigned int *v, int ndims, const int *dims); 00305 bool GetNArray(long *v, int ndims, const int *dims); 00306 bool GetNArray(unsigned long *v, int ndims, const int *dims); 00307 #ifdef VTK_TYPE_USE_LONG_LONG 00308 bool GetNArray(long long *v, int ndims, const int *dims); 00309 bool GetNArray(unsigned long long *v, int ndims, const int *dims); 00310 #endif 00311 #ifdef VTK_TYPE_USE___INT64 00312 bool GetNArray(__int64 *v, int ndims, const int *dims); 00313 bool GetNArray(unsigned __int64 *v, int ndims, const int *dims); 00314 #endif 00315 00316 00318 00319 bool SetArgValue(int i, const std::string &v); 00320 bool SetArgValue(int i, const vtkUnicodeString &v); 00321 bool SetArgValue(int i, char v); 00322 bool SetArgValue(int i, float v); 00323 bool SetArgValue(int i, double v); 00324 bool SetArgValue(int i, bool v); 00325 bool SetArgValue(int i, signed char v); 00326 bool SetArgValue(int i, unsigned char v); 00327 bool SetArgValue(int i, short v); 00328 bool SetArgValue(int i, unsigned short v); 00329 bool SetArgValue(int i, int v); 00330 bool SetArgValue(int i, unsigned int v); 00331 bool SetArgValue(int i, long v); 00332 bool SetArgValue(int i, unsigned long v); 00333 #ifdef VTK_TYPE_USE_LONG_LONG 00334 bool SetArgValue(int i, long long v); 00335 bool SetArgValue(int i, unsigned long long v); 00336 #endif 00337 #ifdef VTK_TYPE_USE___INT64 00338 bool SetArgValue(int i, __int64 v); 00339 bool SetArgValue(int i, unsigned __int64 v); 00340 #endif 00341 00342 00344 00345 bool SetArray(int i, const float *v, int n); 00346 bool SetArray(int i, const double *v, int n); 00347 bool SetArray(int i, const bool *v, int n); 00348 bool SetArray(int i, const char *v, int n); 00349 bool SetArray(int i, const signed char *v, int n); 00350 bool SetArray(int i, const unsigned char *v, int n); 00351 bool SetArray(int i, const short *v, int n); 00352 bool SetArray(int i, const unsigned short *v, int n); 00353 bool SetArray(int i, const int *v, int n); 00354 bool SetArray(int i, const unsigned int *v, int n); 00355 bool SetArray(int i, const long *v, int n); 00356 bool SetArray(int i, const unsigned long *v, int n); 00357 #ifdef VTK_TYPE_USE_LONG_LONG 00358 bool SetArray(int i, const long long *v, int n); 00359 bool SetArray(int i, const unsigned long long *v, int n); 00360 #endif 00361 #ifdef VTK_TYPE_USE___INT64 00362 bool SetArray(int i, const __int64 *v, int n); 00363 bool SetArray(int i, const unsigned __int64 *v, int n); 00364 #endif 00365 00366 00368 00369 bool SetNArray(int i, const float *v, int n, const int *d); 00370 bool SetNArray(int i, const double *v, int n, const int *d); 00371 bool SetNArray(int i, const bool *v, int n, const int *d); 00372 bool SetNArray(int i, const char *v, int n, const int *d); 00373 bool SetNArray(int i, const signed char *v, int n, const int *d); 00374 bool SetNArray(int i, const unsigned char *v, int n, const int *d); 00375 bool SetNArray(int i, const short *v, int n, const int *d); 00376 bool SetNArray(int i, const unsigned short *v, int n, const int *d); 00377 bool SetNArray(int i, const int *v, int n, const int *d); 00378 bool SetNArray(int i, const unsigned int *v, int n, const int *d); 00379 bool SetNArray(int i, const long *v, int n, const int *d); 00380 bool SetNArray(int i, const unsigned long *v, int n, const int *d); 00381 #ifdef VTK_TYPE_USE_LONG_LONG 00382 bool SetNArray(int i, const long long *v, int n, const int *d); 00383 bool SetNArray(int i, const unsigned long long *v, int n, const int *d); 00384 #endif 00385 #ifdef VTK_TYPE_USE___INT64 00386 bool SetNArray(int i, const __int64 *v, int n, const int *d); 00387 bool SetNArray(int i, const unsigned __int64 *v, int n, const int *d); 00388 #endif 00389 00390 00392 static PyObject *BuildNone(); 00393 00396 static PyObject *BuildVTKObject(const void *v); 00397 00399 static PyObject *BuildSpecialObject(const void *v, const char *classname); 00400 00402 static PyObject *BuildEnumValue(int v, const char *enumname); 00403 00405 00407 static PyObject *BuildSIPObject( 00408 const void *v, const char *classname, bool created); 00410 00412 static PyObject *BuildSIPEnumValue(int v, const char *classname); 00413 00415 static PyObject *BuildValue(const void *v); 00416 00418 00419 static PyObject *BuildValue(const char *v); 00420 static PyObject *BuildValue(const std::string &v); 00421 static PyObject *BuildValue(const vtkUnicodeString &v); 00423 00425 static PyObject *BuildValue(char v); 00426 00428 00429 static PyObject *BuildValue(double v); 00430 static PyObject *BuildValue(bool v); 00431 static PyObject *BuildValue(int v); 00432 static PyObject *BuildValue(unsigned int v); 00433 static PyObject *BuildValue(long v); 00434 static PyObject *BuildValue(unsigned long v); 00435 #ifdef VTK_TYPE_USE_LONG_LONG 00436 static PyObject *BuildValue(long long v); 00437 static PyObject *BuildValue(unsigned long long v); 00438 #endif 00439 #ifdef VTK_TYPE_USE___INT64 00440 static PyObject *BuildValue(__int64 v); 00441 static PyObject *BuildValue(unsigned __int64 v); 00442 #endif 00443 00444 00446 static PyObject *BuildBytes(const char *v, int n); 00447 00449 00450 static PyObject *BuildTuple(const float *v, int n); 00451 static PyObject *BuildTuple(const double *v, int n); 00452 static PyObject *BuildTuple(const bool *v, int n); 00453 static PyObject *BuildTuple(const signed char *v, int n); 00454 static PyObject *BuildTuple(const unsigned char *v, int n); 00455 static PyObject *BuildTuple(const short *v, int n); 00456 static PyObject *BuildTuple(const unsigned short *v, int n); 00457 static PyObject *BuildTuple(const int *v, int n); 00458 static PyObject *BuildTuple(const unsigned int *v, int n); 00459 static PyObject *BuildTuple(const long *v, int n); 00460 static PyObject *BuildTuple(const unsigned long *v, int n); 00461 #ifdef VTK_TYPE_USE_LONG_LONG 00462 static PyObject *BuildTuple(const long long *v, int n); 00463 static PyObject *BuildTuple(const unsigned long long *v, int n); 00464 #endif 00465 #ifdef VTK_TYPE_USE___INT64 00466 static PyObject *BuildTuple(const __int64 *v, int n); 00467 static PyObject *BuildTuple(const unsigned __int64 *v, int n); 00468 #endif 00469 00470 00472 00473 template<class T> 00474 static void SaveArray(const T *a, T *b, int n) { 00475 int i = 0; 00476 do { b[i] = a[i]; } while (++i < n); } 00478 00480 00481 template<class T> 00482 static bool ArrayHasChanged(const T *a, const T *b, int n) { 00483 int i = 0; 00484 do { if (a[i] != b[i]) break; } while (++i < n); 00485 return (i < n); } 00487 00489 00490 static int GetArgCount(PyObject *args) { 00491 return static_cast<int>(PyTuple_GET_SIZE(args)); } 00493 00495 00496 static int GetArgCount(PyObject *self, PyObject *args) { 00497 return (static_cast<int>(PyTuple_GET_SIZE(args)) - 00498 PyVTKClass_Check(self)); } 00500 00502 static bool ArgCountError(int n, const char *name); 00503 00504 00505 protected: 00506 00508 static vtkObjectBase *GetSelfFromFirstArg(PyObject *self, PyObject *args); 00509 00511 00512 PyObject *GetArgAsPythonObject(bool &valid); 00513 static PyObject *GetArgAsPythonObject( 00514 PyObject *o, bool &valid); 00516 00518 00519 vtkObjectBase *GetArgAsVTKObject(const char *classname, bool &valid); 00520 static vtkObjectBase *GetArgAsVTKObject( 00521 PyObject *o, const char *classname, bool &valid); 00523 00525 00526 void *GetArgAsSpecialObject(const char *classname, PyObject **newobj); 00527 static void *GetArgAsSpecialObject( 00528 PyObject *o, const char *classname, PyObject **newobj); 00530 00532 00533 int GetArgAsEnum(PyTypeObject *enumtype, bool &valid); 00534 static int GetArgAsEnum( 00535 PyObject *o, PyTypeObject *enumtype, bool &valid); 00537 00539 00540 void *GetArgAsSIPObject(const char *classname, bool &valid); 00541 static void *GetArgAsSIPObject( 00542 PyObject *o, const char *classname, bool &valid); 00544 00546 00547 int GetArgAsSIPEnum(const char *classname, bool &valid); 00548 static int GetArgAsSIPEnum( 00549 PyObject *o, const char *classname, bool &valid); 00551 00553 bool PureVirtualError(); 00554 00556 bool ArgCountError(int m, int n); 00557 00559 bool RefineArgTypeError(int i); 00560 00561 private: 00562 00563 PyObject *Args; 00564 const char *MethodName; 00565 00566 int N; // size of args tuple 00567 int M; // 1 if Self is a PyVTKClass and first arg is the PyVTKObject 00568 int I; // the arg counter, starts at M 00569 }; 00570 00571 //-------------------------------------------------------------------- 00572 // Inline methods for getting "self" as its original type 00573 00574 // Get "self" from a PyVTKObject, which contains a vtkObjectBase object. 00575 inline 00576 vtkObjectBase *vtkPythonArgs::GetSelfPointer(PyObject *self, PyObject *args) 00577 { 00578 if (PyVTKClass_Check(self)) 00579 { 00580 return vtkPythonArgs::GetSelfFromFirstArg(self, args); 00581 } 00582 return ((PyVTKObject *)self)->vtk_ptr; 00583 } 00584 00585 // Get "self" from a PyVTKSpecialObject. 00586 inline 00587 void *vtkPythonArgs::GetSelfPointer(PyObject *self) 00588 { 00589 return ((PyVTKSpecialObject *)self)->vtk_ptr; 00590 } 00591 00592 //-------------------------------------------------------------------- 00593 // Inline methods for checking the arg count 00594 00595 // Verify the arg count for a method with optional arguments. 00596 inline 00597 bool vtkPythonArgs::CheckArgCount(int nmin, int nmax) 00598 { 00599 int nargs = this->N - this->M; 00600 if (nargs >= nmin && nargs <= nmax) 00601 { 00602 return true; 00603 } 00604 this->ArgCountError(nmin, nmax); 00605 return false; 00606 } 00607 00608 // Verify the arg count for a method with optional arguments. 00609 inline 00610 bool vtkPythonArgs::CheckArgCount(int n) 00611 { 00612 int nargs = this->N - this->M; 00613 if (nargs == n) 00614 { 00615 return true; 00616 } 00617 this->ArgCountError(n, n); 00618 return false; 00619 } 00620 00621 //-------------------------------------------------------------------- 00622 // Inline method for guarding against pure virtual method calls 00623 00624 inline 00625 bool vtkPythonArgs::IsPureVirtual() 00626 { 00627 if (IsBound()) 00628 { 00629 return false; 00630 } 00631 this->PureVirtualError(); 00632 return true; 00633 } 00634 00635 //-------------------------------------------------------------------- 00636 // Inline method for checking if an error has occurred. 00637 00638 inline 00639 bool vtkPythonArgs::ErrorOccurred() 00640 { 00641 return (PyErr_Occurred() != NULL); 00642 } 00643 00644 //-------------------------------------------------------------------- 00645 // Inline methods for building python objects of various types. 00646 00647 inline 00648 PyObject *vtkPythonArgs::BuildNone() 00649 { 00650 Py_INCREF(Py_None); 00651 return Py_None; 00652 } 00653 00654 inline 00655 PyObject *vtkPythonArgs::BuildVTKObject(const void *v) 00656 { 00657 return vtkPythonUtil::GetObjectFromPointer( 00658 static_cast<vtkObjectBase *>(const_cast<void *>(v))); 00659 } 00660 00661 inline 00662 PyObject *vtkPythonArgs::BuildSpecialObject(const void *v, 00663 const char *classname) 00664 { 00665 return PyVTKSpecialObject_CopyNew(classname, v); 00666 } 00667 00668 inline 00669 PyObject *vtkPythonArgs::BuildEnumValue(int, const char *) 00670 { 00671 /* not implemented */ 00672 return NULL; 00673 } 00674 00675 inline 00676 PyObject *vtkPythonArgs::BuildSIPObject( 00677 const void *v, const char *classname, bool created) 00678 { 00679 return vtkPythonUtil::SIPGetObjectFromPointer(v, classname, created); 00680 } 00681 00682 inline 00683 PyObject *vtkPythonArgs::BuildSIPEnumValue(int, const char *) 00684 { 00685 /* not implemented */ 00686 return NULL; 00687 } 00688 00689 inline 00690 PyObject *vtkPythonArgs::BuildValue(const void *a) 00691 { 00692 if (a) 00693 { 00694 const char *s = vtkPythonUtil::ManglePointer(a, "p_void"); 00695 return PyString_FromString(s); 00696 } 00697 Py_INCREF(Py_None); 00698 return Py_None; 00699 } 00700 00701 inline 00702 PyObject *vtkPythonArgs::BuildValue(const char *a) 00703 { 00704 if (a) 00705 { 00706 return PyString_FromString(a); 00707 } 00708 Py_INCREF(Py_None); 00709 return Py_None; 00710 } 00711 00712 inline 00713 PyObject *vtkPythonArgs::BuildValue(const std::string &a) 00714 { 00715 return PyString_FromStringAndSize(a.c_str(), static_cast<Py_ssize_t>(a.size())); 00716 } 00717 00718 inline 00719 PyObject *vtkPythonArgs::BuildValue(const vtkUnicodeString &a) 00720 { 00721 std::string s; 00722 a.utf8_str(s); 00723 #ifdef Py_USING_UNICODE 00724 return PyUnicode_DecodeUTF8(s.c_str(), static_cast<Py_ssize_t>(s.size()), NULL); 00725 #else 00726 return PyString_FromStringAndSize(s.c_str(), static_cast<Py_ssize_t>(s.size())); 00727 #endif 00728 } 00729 00730 inline 00731 PyObject *vtkPythonArgs::BuildValue(char a) 00732 { 00733 char b[2]; 00734 b[0] = a; 00735 b[1] = '\0'; 00736 return PyString_FromString(b); 00737 } 00738 00739 inline 00740 PyObject *vtkPythonArgs::BuildValue(double a) 00741 { 00742 return PyFloat_FromDouble(a); 00743 } 00744 00745 inline 00746 PyObject *vtkPythonArgs::BuildValue(bool a) 00747 { 00748 #if PY_VERSION_HEX >= 0x02030000 00749 return PyBool_FromLong((long)a); 00750 #else 00751 return PyInt_FromLong((long)a); 00752 #endif 00753 } 00754 00755 inline 00756 PyObject *vtkPythonArgs::BuildValue(int a) 00757 { 00758 return PyInt_FromLong(a); 00759 } 00760 00761 inline 00762 PyObject *vtkPythonArgs::BuildValue(unsigned int a) 00763 { 00764 #if VTK_SIZEOF_INT < VTK_SIZEOF_LONG 00765 return PyInt_FromLong(a); 00766 #else 00767 if ((long)(a) >= 0) 00768 { 00769 return PyInt_FromLong((long)(a)); 00770 } 00771 return PyLong_FromUnsignedLong(a); 00772 #endif 00773 } 00774 00775 inline 00776 PyObject *vtkPythonArgs::BuildValue(long a) 00777 { 00778 return PyInt_FromLong(a); 00779 } 00780 00781 inline 00782 PyObject *vtkPythonArgs::BuildValue(unsigned long a) 00783 { 00784 if ((long)(a) >= 0) 00785 { 00786 return PyInt_FromLong((long)(a)); 00787 } 00788 return PyLong_FromUnsignedLong(a); 00789 } 00790 00791 #if defined(VTK_TYPE_USE_LONG_LONG) 00792 inline 00793 PyObject *vtkPythonArgs::BuildValue(long long a) 00794 { 00795 #if defined(PY_LONG_LONG) 00796 return PyLong_FromLongLong(a); 00797 #else 00798 return PyLong_FromLong((long)(a)); 00799 #endif 00800 } 00801 00802 inline 00803 PyObject *vtkPythonArgs::BuildValue(unsigned long long a) 00804 { 00805 #if defined(PY_LONG_LONG) 00806 return PyLong_FromUnsignedLongLong(a); 00807 #else 00808 return PyLong_FromUnsignedLong((unsigned long)(a)); 00809 #endif 00810 } 00811 #endif 00812 00813 #if defined(VTK_TYPE_USE___INT64) 00814 inline 00815 PyObject *vtkPythonArgs::BuildValue(__int64 a) 00816 { 00817 #if defined(PY_LONG_LONG) 00818 return PyLong_FromLongLong(a); 00819 #else 00820 return PyLong_FromLong((long)(a)); 00821 #endif 00822 } 00823 00824 inline 00825 PyObject *vtkPythonArgs::BuildValue(unsigned __int64 a) 00826 { 00827 #if defined(PY_LONG_LONG) 00828 return PyLong_FromUnsignedLongLong(a); 00829 #else 00830 return PyLong_FromUnsignedLong((unsigned long)(a)); 00831 #endif 00832 } 00833 #endif 00834 00835 inline 00836 PyObject *vtkPythonArgs::BuildBytes(const char *a, int n) 00837 { 00838 return PyString_FromStringAndSize(a, n); 00839 } 00840 00841 #endif