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 NO_EXP_PYTHON_EMBEDDING
00002 
00003 #ifndef _adr_py_lib_h_                          // only process once,
00004 #define _adr_py_lib_h_                          // even if multiply included
00005 
00006 #ifndef __cplusplus                             // c++ only
00007 #error Must be compiled with C++
00008 #endif
00009 
00010 #include "Python.h"
00011 
00012 /*------------------------------

00013  * Python defines

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

00032  public: \

00033   static PyTypeObject   Type; \

00034   static PyMethodDef    Methods[]; \

00035   static PyParentObject Parents[]; \

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

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

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

00044   if (rvalue == NULL) \

00045     { \

00046       PyErr_Clear(); \

00047       return Parent::_getattr(attr); \

00048     } \

00049   else \

00050     return rvalue 
00051 
00052 
00053 /*------------------------------

00054  * PyObjectPlus

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

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

00103     {return ((PyObjectPlus*)self)->Py_isA(args);};
00104 };
00105 
00106 #endif //  _adr_py_lib_h_
00107 
00108 #endif //NO_EXP_PYTHON_EMBEDDING
00109 

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