PyExport.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00031 #ifndef BASE_PYEXPORT_H
00032 #define BASE_PYEXPORT_H
00033
00034
00035 #if defined (_POSIX_C_SOURCE)
00036 # undef _POSIX_C_SOURCE
00037 #endif
00038 #if defined (_XOPEN_SOURCE)
00039 # undef _XOPEN_SOURCE
00040 #endif
00041
00042 #include <Python.h>
00043
00044 namespace Base
00045 {
00046 class PyObjectBase;
00047
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00103 template <class HandledType>
00104 class PyHandle
00105 {
00106 public:
00107
00108
00109
00115 PyHandle(HandledType *ToHandel=0L)
00116 :_pHandels(ToHandel) {
00117 if (_pHandels)
00118 _pHandels->IncRef();
00119 }
00120
00122 PyHandle(const PyHandle <HandledType> &ToHandel)
00123 :_pHandels(ToHandel._pHandels) {
00124 if (_pHandels)
00125 _pHandels->IncRef();
00126 }
00127
00133 ~PyHandle() {
00134 if (_pHandels)
00135 _pHandels->DecRef();
00136 }
00137
00138
00139
00140
00141
00142 PyHandle <HandledType> &operator=( HandledType* other) {
00143 if (_pHandels)
00144 _pHandels->DecRef();
00145
00146 _pHandels = other;
00147 if (_pHandels)
00148 _pHandels->IncRef();
00149 return *this;
00150 }
00151
00152
00153 PyHandle <HandledType> &operator=(const PyHandle <HandledType> &other) {
00154 if (_pHandels)
00155 _pHandels->DecRef();
00156 _pHandels = other._pHandels;
00157 if (_pHandels)
00158 _pHandels->IncRef();
00159 return *this;
00160 }
00161
00163 HandledType &operator*() {
00164 return *_pHandels;
00165 }
00166
00168 HandledType *operator->() {
00169 return _pHandels;
00170 }
00171
00173 const HandledType &operator*() const {
00174 return _pHandels;
00175 }
00176
00178 const HandledType *operator->() const {
00179 return _pHandels;
00180 }
00181
00185 bool operator<(const PyHandle<HandledType> &other) const {
00186
00187
00188 return _pHandels<other._pHandels;
00189 }
00190
00192 bool operator==(const PyHandle<HandledType> &other) const {
00193
00194
00195 return _pHandels==other._pHandels;
00196 }
00197
00199 PyObject* getPyObject(void) const {
00200
00201
00202 return const_cast<HandledType*>(_pHandels)->getPyObject();
00203 }
00204
00205
00206
00208 bool IsValid(void) const {
00209 return _pHandels!=0;
00210 }
00211
00213 bool IsNull(void) const {
00214 return _pHandels==0;
00215 }
00216
00217 private:
00219 HandledType *_pHandels;
00220
00221 };
00222
00223
00224 }
00225
00226 #endif // BASE_PYEXPORT_H