Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

PyObjectPlus.h

Go to the documentation of this file.
00001 #ifndef _adr_py_lib_h_                          // only process once,
00002 #define _adr_py_lib_h_                          // even if multiply included
00003 
00004 #ifndef __cplusplus                             // c++ only
00005 #error Must be compiled with C++
00006 #endif
00007 
00008 #include "Python.h"
00009 
00010 /*------------------------------

00011  * Python defines

00012 ------------------------------*/
00013 
00014                                                                 // some basic python macros
00015 #define Py_NEWARGS 1                    
00016 #define Py_Return Py_INCREF(Py_None); return Py_None;   
00017 
00018 #define Py_Error(E, M)   {PyErr_SetString(E, M); return NULL;}
00019 #define Py_Try(F) {if (!(F)) return NULL;}
00020 #define Py_Assert(A,E,M) {if (!(A)) {PyErr_SetString(E, M); return NULL;}}
00021 
00022 inline void Py_Fatal(char *M) {
00023         //cout << M << endl; 
00024         exit(-1);
00025 };
00026 
00027                                                                 // This must be the first line of each 
00028                                                                 // PyC++ class
00029 #define Py_Header \

00030  public: \

00031   static PyTypeObject   Type; \

00032   static PyMethodDef    Methods[]; \

00033   static PyParentObject Parents[]; \

00034   virtual PyTypeObject *GetType(void) {return &Type;}; \

00035   virtual PyParentObject *GetParents(void) {return Parents;}
00036 
00037                                                                 // This defines the _getattr_up macro
00038                                                                 // which allows attribute and method calls
00039                                                                 // to be properly passed up the hierarchy.
00040 #define _getattr_up(Parent) \

00041   PyObject *rvalue = Py_FindMethod(Methods, this, attr); \

00042   if (rvalue == NULL) \

00043     { \

00044       PyErr_Clear(); \

00045       return Parent::_getattr(attr); \

00046     } \

00047   else \

00048     return rvalue 
00049 
00050 
00051 /*------------------------------

00052  * PyObjectPlus

00053 ------------------------------*/
00054 typedef PyTypeObject * PyParentObject;                          // Define the PyParent Object
00055 
00056 class PyObjectPlus : public PyObject {                          // The PyObjectPlus abstract class
00057 
00058   Py_Header;                                                    // Always start with Py_Header
00059 
00060  public:  
00061   PyObjectPlus(PyTypeObject *T)                                 // constructor
00062     {this->ob_type = T; _Py_NewReference(this);};
00063   
00064   virtual ~PyObjectPlus() {};                                   // destructor
00065   static void PyDestructor(PyObject *P)                         // python wrapper
00066   {  
00067           delete ((PyObjectPlus *) P);  
00068   };
00069 
00070   void INCREF(void) {
00071           Py_INCREF(this);
00072   };                            // incref method
00073   void DECREF(void) {
00074           Py_DECREF(this);
00075   };                            // decref method
00076 
00077   virtual PyObject *_getattr(char *attr);                       // _getattr method
00078   static  PyObject *__getattr(PyObject * PyObj, char *attr)     // This should be the entry in Type. 
00079     { return ((PyObjectPlus*) PyObj)->_getattr(attr); };
00080    
00081   virtual int _setattr(char *attr, PyObject *value);            // _setattr method
00082   static  int __setattr(PyObject *PyObj,                        // This should be the entry in Type. 
00083                         char *attr, 
00084                         PyObject *value)

00085     { return ((PyObjectPlus*) PyObj)->_setattr(attr, value);  };
00086 
00087   virtual PyObject *_repr(void);                                // _repr method
00088   static  PyObject *__repr(PyObject *PyObj)                     // This should be the entry in Type.
00089     {  return ((PyObjectPlus*) PyObj)->_repr();  };
00090 
00091 
00092                                                                 // isA methods
00093   bool isA(PyTypeObject *T);
00094   bool isA(const char *mytypename);
00095   PyObject *Py_isA(PyObject *args);
00096   static PyObject *sPy_isA(PyObject *self, PyObject *args, PyObject *kwd)

00097     {return ((PyObjectPlus*)self)->Py_isA(args);};
00098 };
00099 
00100 #endif //  _adr_py_lib_h_

Generated at Thu Feb 1 13:03:08 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000