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
00014
00015
00016
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
00026 exit(-1);
00027 };
00028
00029
00030
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
00040
00041
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
00055
00056 typedef PyTypeObject * PyParentObject;
00057
00058 class PyObjectPlus : public PyObject {
00059
00060 Py_Header;
00061
00062 public:
00063 PyObjectPlus(PyTypeObject *T)
00064 {
00065
00066 this->ob_type = T;
00067 _Py_NewReference(this);
00068 };
00069
00070 virtual ~PyObjectPlus() {};
00071 static void PyDestructor(PyObject *P)
00072 {
00073 delete ((PyObjectPlus *) P);
00074 };
00075
00076
00077
00078
00079
00080
00081
00082
00083 virtual PyObject *_getattr(char *attr);
00084 static PyObject *__getattr(PyObject * PyObj, char *attr)
00085 { return ((PyObjectPlus*) PyObj)->_getattr(attr); };
00086
00087 virtual int _setattr(char *attr, PyObject *value);
00088 static int __setattr(PyObject *PyObj,
00089 char *attr,
00090 PyObject *value)
00091 { return ((PyObjectPlus*) PyObj)->_setattr(attr, value); };
00092
00093 virtual PyObject *_repr(void);
00094 static PyObject *__repr(PyObject *PyObj)
00095 { return ((PyObjectPlus*) PyObj)->_repr(); };
00096
00097
00098
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