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 00104 template<class T> 00105 bool GetVTKObject(T *&v, const char *classname) { 00106 bool b; 00107 v = (T *)this->GetArgAsVTKObject(classname, b); 00108 return b; } 00109 template<class T> 00110 bool GetVTKObject(PyObject *o, T *&v, const char *classname) { 00111 bool b; 00112 v = (T *)vtkPythonArgs::GetArgAsVTKObject(o, classname, b); 00113 return b; } 00115 00117 00120 template<class T> 00121 bool GetSpecialObject(T *&v, PyObject *&o, const char *classname) { 00122 v = static_cast<T *>(this->GetArgAsSpecialObject(classname, &o)); 00123 return (v != NULL); } 00124 template<class T> 00125 static bool GetSpecialObject( 00126 PyObject *arg, T *&v, PyObject *&o, const char *classname) { 00127 v = static_cast<T *>( 00128 vtkPythonArgs::GetArgAsSpecialObject(arg, classname, &o)); 00129 return (v != NULL); } 00131 00133 00135 template<class T> 00136 bool GetSpecialObject(T *&v, const char *classname) { 00137 v = static_cast<T *>(this->GetArgAsSpecialObject(classname, NULL)); 00138 return (v != NULL); } 00139 template<class T> 00140 static bool GetSpecialObject(PyObject *o, T *&v, const char *classname) { 00141 v = static_cast<T *>( 00142 vtkPythonArgs::GetArgAsSpecialObject(o, classname, NULL)); 00143 return (v != NULL); } 00145 00147 00148 template<class T> 00149 bool GetEnumValue(T &v, const char *enumname) { 00150 bool r; 00151 v = static_cast<T>(this->GetArgAsEnum(enumname, r)); 00152 return r; } 00153 template<class T> 00154 static bool GetEnumValue(PyObject *o, T &v, const char *enumname) { 00155 bool r; 00156 v = static_cast<T>(vtkPythonArgs::GetArgAsEnum(o, enumname, r)); 00157 return r; } 00159 00161 00162 template<class T> 00163 bool GetSIPObject(T *&v, const char *classname) { 00164 bool r; 00165 v = (T *)this->GetArgAsSIPObject(classname, r); 00166 return r; } 00167 template<class T> 00168 static bool GetSIPObject(PyObject *o, T *&v, const char *classname) { 00169 bool r; 00170 v = (T *)vtkPythonArgs::GetArgAsSIPObject(o, classname, r); 00171 return r; } 00173 00175 00176 template<class T> 00177 bool GetSIPEnumValue(T &v, const char *enumname) { 00178 bool r; 00179 v = static_cast<T>(this->GetArgAsSIPEnum(enumname, r)); 00180 return r; } 00181 template<class T> 00182 static bool GetSIPEnumValue(PyObject *o, T &v, const char *enumname) { 00183 bool r; 00184 v = static_cast<T>(vtkPythonArgs::GetArgAsSIPEnum(o, enumname, r)); 00185 return r; } 00187 00189 00191 bool GetFunction(PyObject *&o); 00192 static bool GetFunction(PyObject *arg, PyObject *&o); 00194 00195 // Get the next arg as a void pointer (to a buffer object). 00196 bool GetValue(void *&v); 00197 static bool GetValue(PyObject *o, void *&v); 00198 bool GetValue(const void *&v); 00199 static bool GetValue(PyObject *o, const void *&v); 00200 00202 00203 bool GetValue(const char *&v); 00204 static bool GetValue(PyObject *o, const char *&v); 00205 bool GetValue(char *&v); 00206 static bool GetValue(PyObject *o, char *&v); 00207 bool GetValue(std::string &v); 00208 static bool GetValue(PyObject *o, std::string &v); 00209 bool GetValue(vtkUnicodeString &v); 00210 static bool GetValue(PyObject *o, vtkUnicodeString &v); 00212 00214 00215 bool GetValue(char &v); 00216 static bool GetValue(PyObject *o, char &v); 00218 00220 00221 bool GetValue(float &v); 00222 static bool GetValue(PyObject *o, float &v); 00223 bool GetValue(double &v); 00224 static bool GetValue(PyObject *o, double &v); 00225 bool GetValue(bool &v); 00226 static bool GetValue(PyObject *o, bool &v); 00227 bool GetValue(signed char &v); 00228 static bool GetValue(PyObject *o, signed char &v); 00229 bool GetValue(unsigned char &v); 00230 static bool GetValue(PyObject *o, unsigned char &v); 00231 bool GetValue(short &v); 00232 static bool GetValue(PyObject *o, short &v); 00233 bool GetValue(unsigned short &v); 00234 static bool GetValue(PyObject *o, unsigned short &v); 00235 bool GetValue(int &v); 00236 static bool GetValue(PyObject *o, int &v); 00237 bool GetValue(unsigned int &v); 00238 static bool GetValue(PyObject *o, unsigned int &v); 00239 bool GetValue(long &v); 00240 static bool GetValue(PyObject *o, long &v); 00241 bool GetValue(unsigned long &v); 00242 static bool GetValue(PyObject *o, unsigned long &v); 00243 #ifdef VTK_TYPE_USE_LONG_LONG 00244 bool GetValue(long long &v); 00245 static bool GetValue(PyObject *o, long long &v); 00246 bool GetValue(unsigned long long &v); 00247 static bool GetValue(PyObject *o, unsigned long long &v); 00248 #endif 00249 #ifdef VTK_TYPE_USE___INT64 00250 bool GetValue(__int64 &v); 00251 static bool GetValue(PyObject *o, __int64 &v); 00252 bool GetValue(unsigned __int64 &v); 00253 static bool GetValue(PyObject *o, unsigned __int64 &v); 00254 #endif 00255 00256 00258 00259 bool GetArray(float *v, int n); 00260 bool GetArray(double *v, int n); 00261 bool GetArray(bool *v, int n); 00262 bool GetArray(char *v, int n); 00263 bool GetArray(signed char *v, int n); 00264 bool GetArray(unsigned char *v, int n); 00265 bool GetArray(short *v, int n); 00266 bool GetArray(unsigned short *v, int n); 00267 bool GetArray(int *v, int n); 00268 bool GetArray(unsigned int *v, int n); 00269 bool GetArray(long *v, int n); 00270 bool GetArray(unsigned long *v, int n); 00271 #ifdef VTK_TYPE_USE_LONG_LONG 00272 bool GetArray(long long *v, int n); 00273 bool GetArray(unsigned long long *v, int n); 00274 #endif 00275 #ifdef VTK_TYPE_USE___INT64 00276 bool GetArray(__int64 *v, int n); 00277 bool GetArray(unsigned __int64 *v, int n); 00278 #endif 00279 00280 00282 00283 bool GetNArray(float *v, int ndims, const int *dims); 00284 bool GetNArray(double *v, int ndims, const int *dims); 00285 bool GetNArray(bool *v, int ndims, const int *dims); 00286 bool GetNArray(char *v, int ndims, const int *dims); 00287 bool GetNArray(signed char *v, int ndims, const int *dims); 00288 bool GetNArray(unsigned char *v, int ndims, const int *dims); 00289 bool GetNArray(short *v, int ndims, const int *dims); 00290 bool GetNArray(unsigned short *v, int ndims, const int *dims); 00291 bool GetNArray(int *v, int ndims, const int *dims); 00292 bool GetNArray(unsigned int *v, int ndims, const int *dims); 00293 bool GetNArray(long *v, int ndims, const int *dims); 00294 bool GetNArray(unsigned long *v, int ndims, const int *dims); 00295 #ifdef VTK_TYPE_USE_LONG_LONG 00296 bool GetNArray(long long *v, int ndims, const int *dims); 00297 bool GetNArray(unsigned long long *v, int ndims, const int *dims); 00298 #endif 00299 #ifdef VTK_TYPE_USE___INT64 00300 bool GetNArray(__int64 *v, int ndims, const int *dims); 00301 bool GetNArray(unsigned __int64 *v, int ndims, const int *dims); 00302 #endif 00303 00304 00306 00307 bool SetArgValue(int i, const std::string &v); 00308 bool SetArgValue(int i, const vtkUnicodeString &v); 00309 bool SetArgValue(int i, char v); 00310 bool SetArgValue(int i, float v); 00311 bool SetArgValue(int i, double v); 00312 bool SetArgValue(int i, bool v); 00313 bool SetArgValue(int i, signed char v); 00314 bool SetArgValue(int i, unsigned char v); 00315 bool SetArgValue(int i, short v); 00316 bool SetArgValue(int i, unsigned short v); 00317 bool SetArgValue(int i, int v); 00318 bool SetArgValue(int i, unsigned int v); 00319 bool SetArgValue(int i, long v); 00320 bool SetArgValue(int i, unsigned long v); 00321 #ifdef VTK_TYPE_USE_LONG_LONG 00322 bool SetArgValue(int i, long long v); 00323 bool SetArgValue(int i, unsigned long long v); 00324 #endif 00325 #ifdef VTK_TYPE_USE___INT64 00326 bool SetArgValue(int i, __int64 v); 00327 bool SetArgValue(int i, unsigned __int64 v); 00328 #endif 00329 00330 00332 00333 bool SetArray(int i, const float *v, int n); 00334 bool SetArray(int i, const double *v, int n); 00335 bool SetArray(int i, const bool *v, int n); 00336 bool SetArray(int i, const char *v, int n); 00337 bool SetArray(int i, const signed char *v, int n); 00338 bool SetArray(int i, const unsigned char *v, int n); 00339 bool SetArray(int i, const short *v, int n); 00340 bool SetArray(int i, const unsigned short *v, int n); 00341 bool SetArray(int i, const int *v, int n); 00342 bool SetArray(int i, const unsigned int *v, int n); 00343 bool SetArray(int i, const long *v, int n); 00344 bool SetArray(int i, const unsigned long *v, int n); 00345 #ifdef VTK_TYPE_USE_LONG_LONG 00346 bool SetArray(int i, const long long *v, int n); 00347 bool SetArray(int i, const unsigned long long *v, int n); 00348 #endif 00349 #ifdef VTK_TYPE_USE___INT64 00350 bool SetArray(int i, const __int64 *v, int n); 00351 bool SetArray(int i, const unsigned __int64 *v, int n); 00352 #endif 00353 00354 00356 00357 bool SetNArray(int i, const float *v, int n, const int *d); 00358 bool SetNArray(int i, const double *v, int n, const int *d); 00359 bool SetNArray(int i, const bool *v, int n, const int *d); 00360 bool SetNArray(int i, const char *v, int n, const int *d); 00361 bool SetNArray(int i, const signed char *v, int n, const int *d); 00362 bool SetNArray(int i, const unsigned char *v, int n, const int *d); 00363 bool SetNArray(int i, const short *v, int n, const int *d); 00364 bool SetNArray(int i, const unsigned short *v, int n, const int *d); 00365 bool SetNArray(int i, const int *v, int n, const int *d); 00366 bool SetNArray(int i, const unsigned int *v, int n, const int *d); 00367 bool SetNArray(int i, const long *v, int n, const int *d); 00368 bool SetNArray(int i, const unsigned long *v, int n, const int *d); 00369 #ifdef VTK_TYPE_USE_LONG_LONG 00370 bool SetNArray(int i, const long long *v, int n, const int *d); 00371 bool SetNArray(int i, const unsigned long long *v, int n, const int *d); 00372 #endif 00373 #ifdef VTK_TYPE_USE___INT64 00374 bool SetNArray(int i, const __int64 *v, int n, const int *d); 00375 bool SetNArray(int i, const unsigned __int64 *v, int n, const int *d); 00376 #endif 00377 00378 00380 static PyObject *BuildNone(); 00381 00384 static PyObject *BuildVTKObject(const void *v); 00385 00387 static PyObject *BuildSpecialObject(const void *v, const char *classname); 00388 00390 static PyObject *BuildEnumValue(int v, const char *enumname); 00391 00393 00395 static PyObject *BuildSIPObject( 00396 const void *v, const char *classname, bool created); 00398 00400 static PyObject *BuildSIPEnumValue(int v, const char *classname); 00401 00403 static PyObject *BuildValue(const void *v); 00404 00406 00407 static PyObject *BuildValue(const char *v); 00408 static PyObject *BuildValue(const std::string &v); 00409 static PyObject *BuildValue(const vtkUnicodeString &v); 00411 00413 static PyObject *BuildValue(char v); 00414 00416 00417 static PyObject *BuildValue(double v); 00418 static PyObject *BuildValue(bool v); 00419 static PyObject *BuildValue(int v); 00420 static PyObject *BuildValue(unsigned int v); 00421 static PyObject *BuildValue(long v); 00422 static PyObject *BuildValue(unsigned long v); 00423 #ifdef VTK_TYPE_USE_LONG_LONG 00424 static PyObject *BuildValue(long long v); 00425 static PyObject *BuildValue(unsigned long long v); 00426 #endif 00427 #ifdef VTK_TYPE_USE___INT64 00428 static PyObject *BuildValue(__int64 v); 00429 static PyObject *BuildValue(unsigned __int64 v); 00430 #endif 00431 00432 00434 static PyObject *BuildBytes(const char *v, int n); 00435 00437 00438 static PyObject *BuildTuple(const float *v, int n); 00439 static PyObject *BuildTuple(const double *v, int n); 00440 static PyObject *BuildTuple(const bool *v, int n); 00441 static PyObject *BuildTuple(const signed char *v, int n); 00442 static PyObject *BuildTuple(const unsigned char *v, int n); 00443 static PyObject *BuildTuple(const short *v, int n); 00444 static PyObject *BuildTuple(const unsigned short *v, int n); 00445 static PyObject *BuildTuple(const int *v, int n); 00446 static PyObject *BuildTuple(const unsigned int *v, int n); 00447 static PyObject *BuildTuple(const long *v, int n); 00448 static PyObject *BuildTuple(const unsigned long *v, int n); 00449 #ifdef VTK_TYPE_USE_LONG_LONG 00450 static PyObject *BuildTuple(const long long *v, int n); 00451 static PyObject *BuildTuple(const unsigned long long *v, int n); 00452 #endif 00453 #ifdef VTK_TYPE_USE___INT64 00454 static PyObject *BuildTuple(const __int64 *v, int n); 00455 static PyObject *BuildTuple(const unsigned __int64 *v, int n); 00456 #endif 00457 00458 00460 00461 template<class T> 00462 static void SaveArray(const T *a, T *b, int n) { 00463 int i = 0; 00464 do { b[i] = a[i]; } while (++i < n); } 00466 00468 00469 template<class T> 00470 static bool ArrayHasChanged(const T *a, const T *b, int n) { 00471 int i = 0; 00472 do { if (a[i] != b[i]) break; } while (++i < n); 00473 return (i < n); } 00475 00477 00478 static int GetArgCount(PyObject *args) { 00479 return static_cast<int>(PyTuple_GET_SIZE(args)); } 00481 00483 00484 static int GetArgCount(PyObject *self, PyObject *args) { 00485 return (static_cast<int>(PyTuple_GET_SIZE(args)) - 00486 PyVTKClass_Check(self)); } 00488 00490 static bool ArgCountError(int n, const char *name); 00491 00492 00493 protected: 00494 00496 static vtkObjectBase *GetSelfFromFirstArg(PyObject *self, PyObject *args); 00497 00499 00500 vtkObjectBase *GetArgAsVTKObject(const char *classname, bool &valid); 00501 static vtkObjectBase *GetArgAsVTKObject( 00502 PyObject *o, const char *classname, bool &valid); 00504 00506 00507 void *GetArgAsSpecialObject(const char *classname, PyObject **newobj); 00508 static void *GetArgAsSpecialObject( 00509 PyObject *o, const char *classname, PyObject **newobj); 00511 00513 00514 int GetArgAsEnum(const char *classname, bool &valid); 00515 static int GetArgAsEnum( 00516 PyObject *o, const char *classname, bool &valid); 00518 00520 00521 void *GetArgAsSIPObject(const char *classname, bool &valid); 00522 static void *GetArgAsSIPObject( 00523 PyObject *o, const char *classname, bool &valid); 00525 00527 00528 int GetArgAsSIPEnum(const char *classname, bool &valid); 00529 static int GetArgAsSIPEnum( 00530 PyObject *o, const char *classname, bool &valid); 00532 00534 bool PureVirtualError(); 00535 00537 bool ArgCountError(int m, int n); 00538 00540 bool RefineArgTypeError(int i); 00541 00542 private: 00543 00544 PyObject *Args; 00545 const char *MethodName; 00546 00547 int N; // size of args tuple 00548 int M; // 1 if Self is a PyVTKClass and first arg is the PyVTKObject 00549 int I; // the arg counter, starts at M 00550 }; 00551 00552 //-------------------------------------------------------------------- 00553 // Inline methods for getting "self" as its original type 00554 00555 // Get "self" from a PyVTKObject, which contains a vtkObjectBase object. 00556 inline 00557 vtkObjectBase *vtkPythonArgs::GetSelfPointer(PyObject *self, PyObject *args) 00558 { 00559 if (PyVTKClass_Check(self)) 00560 { 00561 return vtkPythonArgs::GetSelfFromFirstArg(self, args); 00562 } 00563 return ((PyVTKObject *)self)->vtk_ptr; 00564 } 00565 00566 // Get "self" from a PyVTKSpecialObject. 00567 inline 00568 void *vtkPythonArgs::GetSelfPointer(PyObject *self) 00569 { 00570 return ((PyVTKSpecialObject *)self)->vtk_ptr; 00571 } 00572 00573 //-------------------------------------------------------------------- 00574 // Inline methods for checking the arg count 00575 00576 // Verify the arg count for a method with optional arguments. 00577 inline 00578 bool vtkPythonArgs::CheckArgCount(int nmin, int nmax) 00579 { 00580 int nargs = this->N - this->M; 00581 if (nargs >= nmin && nargs <= nmax) 00582 { 00583 return true; 00584 } 00585 this->ArgCountError(nmin, nmax); 00586 return false; 00587 } 00588 00589 // Verify the arg count for a method with optional arguments. 00590 inline 00591 bool vtkPythonArgs::CheckArgCount(int n) 00592 { 00593 int nargs = this->N - this->M; 00594 if (nargs == n) 00595 { 00596 return true; 00597 } 00598 this->ArgCountError(n, n); 00599 return false; 00600 } 00601 00602 //-------------------------------------------------------------------- 00603 // Inline method for guarding against pure virtual method calls 00604 00605 inline 00606 bool vtkPythonArgs::IsPureVirtual() 00607 { 00608 if (IsBound()) 00609 { 00610 return false; 00611 } 00612 this->PureVirtualError(); 00613 return true; 00614 } 00615 00616 //-------------------------------------------------------------------- 00617 // Inline method for checking if an error has occurred. 00618 00619 inline 00620 bool vtkPythonArgs::ErrorOccurred() 00621 { 00622 return (PyErr_Occurred() != NULL); 00623 } 00624 00625 //-------------------------------------------------------------------- 00626 // Inline methods for building python objects of various types. 00627 00628 inline 00629 PyObject *vtkPythonArgs::BuildNone() 00630 { 00631 Py_INCREF(Py_None); 00632 return Py_None; 00633 } 00634 00635 inline 00636 PyObject *vtkPythonArgs::BuildVTKObject(const void *v) 00637 { 00638 return vtkPythonUtil::GetObjectFromPointer( 00639 static_cast<vtkObjectBase *>(const_cast<void *>(v))); 00640 } 00641 00642 inline 00643 PyObject *vtkPythonArgs::BuildSpecialObject(const void *v, 00644 const char *classname) 00645 { 00646 return PyVTKSpecialObject_CopyNew(classname, v); 00647 } 00648 00649 inline 00650 PyObject *vtkPythonArgs::BuildEnumValue(int, const char *) 00651 { 00652 /* not implemented */ 00653 return NULL; 00654 } 00655 00656 inline 00657 PyObject *vtkPythonArgs::BuildSIPObject( 00658 const void *v, const char *classname, bool created) 00659 { 00660 return vtkPythonUtil::SIPGetObjectFromPointer(v, classname, created); 00661 } 00662 00663 inline 00664 PyObject *vtkPythonArgs::BuildSIPEnumValue(int, const char *) 00665 { 00666 /* not implemented */ 00667 return NULL; 00668 } 00669 00670 inline 00671 PyObject *vtkPythonArgs::BuildValue(const void *a) 00672 { 00673 if (a) 00674 { 00675 const char *s = vtkPythonUtil::ManglePointer(a, "void_p"); 00676 return PyString_FromString(s); 00677 } 00678 Py_INCREF(Py_None); 00679 return Py_None; 00680 } 00681 00682 inline 00683 PyObject *vtkPythonArgs::BuildValue(const char *a) 00684 { 00685 if (a) 00686 { 00687 return PyString_FromString(a); 00688 } 00689 Py_INCREF(Py_None); 00690 return Py_None; 00691 } 00692 00693 inline 00694 PyObject *vtkPythonArgs::BuildValue(const std::string &a) 00695 { 00696 return PyString_FromStringAndSize(a.c_str(), static_cast<Py_ssize_t>(a.size())); 00697 } 00698 00699 inline 00700 PyObject *vtkPythonArgs::BuildValue(const vtkUnicodeString &a) 00701 { 00702 std::string s; 00703 a.utf8_str(s); 00704 #ifdef Py_USING_UNICODE 00705 return PyUnicode_DecodeUTF8(s.c_str(), static_cast<Py_ssize_t>(s.size()), NULL); 00706 #else 00707 return PyString_FromStringAndSize(s.c_str(), static_cast<Py_ssize_t>(s.size())); 00708 #endif 00709 } 00710 00711 inline 00712 PyObject *vtkPythonArgs::BuildValue(char a) 00713 { 00714 char b[2]; 00715 b[0] = a; 00716 b[1] = '\0'; 00717 return PyString_FromString(b); 00718 } 00719 00720 inline 00721 PyObject *vtkPythonArgs::BuildValue(double a) 00722 { 00723 return PyFloat_FromDouble(a); 00724 } 00725 00726 inline 00727 PyObject *vtkPythonArgs::BuildValue(bool a) 00728 { 00729 #if PY_VERSION_HEX >= 0x02030000 00730 return PyBool_FromLong((long)a); 00731 #else 00732 return PyInt_FromLong((long)a); 00733 #endif 00734 } 00735 00736 inline 00737 PyObject *vtkPythonArgs::BuildValue(int a) 00738 { 00739 return PyInt_FromLong(a); 00740 } 00741 00742 inline 00743 PyObject *vtkPythonArgs::BuildValue(unsigned int a) 00744 { 00745 #if VTK_SIZEOF_INT < VTK_SIZEOF_LONG 00746 return PyInt_FromLong(a); 00747 #else 00748 if ((long)(a) >= 0) 00749 { 00750 return PyInt_FromLong((long)(a)); 00751 } 00752 return PyLong_FromUnsignedLong(a); 00753 #endif 00754 } 00755 00756 inline 00757 PyObject *vtkPythonArgs::BuildValue(long a) 00758 { 00759 return PyInt_FromLong(a); 00760 } 00761 00762 inline 00763 PyObject *vtkPythonArgs::BuildValue(unsigned long a) 00764 { 00765 if ((long)(a) >= 0) 00766 { 00767 return PyInt_FromLong((long)(a)); 00768 } 00769 return PyLong_FromUnsignedLong(a); 00770 } 00771 00772 #if defined(VTK_TYPE_USE_LONG_LONG) 00773 inline 00774 PyObject *vtkPythonArgs::BuildValue(long long a) 00775 { 00776 #if defined(PY_LONG_LONG) 00777 return PyLong_FromLongLong(a); 00778 #else 00779 return PyLong_FromLong((long)(a)); 00780 #endif 00781 } 00782 00783 inline 00784 PyObject *vtkPythonArgs::BuildValue(unsigned long long a) 00785 { 00786 #if defined(PY_LONG_LONG) 00787 return PyLong_FromUnsignedLongLong(a); 00788 #else 00789 return PyLong_FromUnsignedLong((unsigned long)(a)); 00790 #endif 00791 } 00792 #endif 00793 00794 #if defined(VTK_TYPE_USE___INT64) 00795 inline 00796 PyObject *vtkPythonArgs::BuildValue(__int64 a) 00797 { 00798 #if defined(PY_LONG_LONG) 00799 return PyLong_FromLongLong(a); 00800 #else 00801 return PyLong_FromLong((long)(a)); 00802 #endif 00803 } 00804 00805 inline 00806 PyObject *vtkPythonArgs::BuildValue(unsigned __int64 a) 00807 { 00808 #if defined(PY_LONG_LONG) 00809 return PyLong_FromUnsignedLongLong(a); 00810 #else 00811 return PyLong_FromUnsignedLong((unsigned long)(a)); 00812 #endif 00813 } 00814 #endif 00815 00816 inline 00817 PyObject *vtkPythonArgs::BuildBytes(const char *a, int n) 00818 { 00819 return PyString_FromStringAndSize(a, n); 00820 } 00821 00822 #endif