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