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
00012
00013
00014
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
00024 exit(-1);
00025 };
00026
00027
00028
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
00038
00039
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
00053
00054 typedef PyTypeObject * PyParentObject;
00055
00056 class PyObjectPlus : public PyObject {
00057
00058 Py_Header;
00059
00060 public:
00061 PyObjectPlus(PyTypeObject *T)
00062 {this->ob_type = T; _Py_NewReference(this);};
00063
00064 virtual ~PyObjectPlus() {};
00065 static void PyDestructor(PyObject *P)
00066 {
00067 delete ((PyObjectPlus *) P);
00068 };
00069
00070 void INCREF(void) {
00071 Py_INCREF(this);
00072 };
00073 void DECREF(void) {
00074 Py_DECREF(this);
00075 };
00076
00077 virtual PyObject *_getattr(char *attr);
00078 static PyObject *__getattr(PyObject * PyObj, char *attr)
00079 { return ((PyObjectPlus*) PyObj)->_getattr(attr); };
00080
00081 virtual int _setattr(char *attr, PyObject *value);
00082 static int __setattr(PyObject *PyObj,
00083 char *attr,
00084 PyObject *value)
00085 { return ((PyObjectPlus*) PyObj)->_setattr(attr, value); };
00086
00087 virtual PyObject *_repr(void);
00088 static PyObject *__repr(PyObject *PyObj)
00089 { return ((PyObjectPlus*) PyObj)->_repr(); };
00090
00091
00092
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_