aboutsummaryrefslogtreecommitdiff
path: root/lib/python/python.h
diff options
context:
space:
mode:
authorghost <andreas.monzner@multimedia-labs.de>2009-09-25 16:54:43 +0200
committerghost <andreas.monzner@multimedia-labs.de>2009-09-25 16:54:43 +0200
commit5136ec8c8b20d83f744ce76d7fbcc5b885059e80 (patch)
tree920808353a0697fcebf525ead0f5e36c10939526 /lib/python/python.h
parent72f38fa3d54ce2ded1826e18e9a3ae94b7bc20f3 (diff)
downloadenigma2-5136ec8c8b20d83f744ce76d7fbcc5b885059e80.tar.gz
enigma2-5136ec8c8b20d83f744ce76d7fbcc5b885059e80.zip
add wrapper class for auto Py_INCREF/Py_DECREF ... i.e. usable for STL containers
Diffstat (limited to 'lib/python/python.h')
-rw-r--r--lib/python/python.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/python/python.h b/lib/python/python.h
index 52ec6c1e..18fdac78 100644
--- a/lib/python/python.h
+++ b/lib/python/python.h
@@ -155,6 +155,41 @@ inline void ePyObject::decref()
Py_DECREF(m_ob);
}
+class ePyObjectWrapper
+{
+ ePyObject m_obj;
+public:
+ ePyObjectWrapper(const ePyObjectWrapper &wrapper)
+ :m_obj(wrapper.m_obj)
+ {
+ Py_INCREF(m_obj);
+ }
+ ePyObjectWrapper(const ePyObject &obj)
+ :m_obj(obj)
+ {
+ Py_INCREF(m_obj);
+ }
+ ~ePyObjectWrapper()
+ {
+ Py_DECREF(m_obj);
+ }
+ ePyObjectWrapper &operator=(const ePyObjectWrapper &wrapper)
+ {
+ Py_DECREF(m_obj);
+ m_obj = wrapper.m_obj;
+ Py_INCREF(m_obj);
+ return *this;
+ }
+ operator PyObject*()
+ {
+ return m_obj;
+ }
+ operator ePyObject()
+ {
+ return m_obj;
+ }
+};
+
#endif // ! PYTHON_REFCOUNT_DEBUG
#endif // !SWIG && !SKIP_PART1
@@ -390,5 +425,4 @@ private:
#endif // SWIG
#endif // SKIP_PART2
-
#endif // __lib_python_python_class_h