aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-11-11 17:58:40 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:08:58 -0300
commita79d9e796b82a9277ab4ac8de19ae596b5bfa266 (patch)
tree25339eb1db0c04dd4f7e7bfe773f77e751a1b6ed /libshiboken
parentab78a6601e67d8bf2121c09fbd22e61032c38f04 (diff)
Add operator= to AutoDecRef.
Reviewer: Renato Araújo <renato.filho@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/autodecref.h47
1 files changed, 34 insertions, 13 deletions
diff --git a/libshiboken/autodecref.h b/libshiboken/autodecref.h
index 20ed168d8..85445951f 100644
--- a/libshiboken/autodecref.h
+++ b/libshiboken/autodecref.h
@@ -37,34 +37,55 @@ class LIBSHIBOKEN_API AutoDecRef
public:
/**
* AutoDecRef constructor.
- * /param pyobj A borrowed reference to a Python object
+ * \param pyobj A borrowed reference to a Python object
*/
- explicit AutoDecRef(PyObject* pyobj) : m_pyobj(pyobj) {}
+ explicit AutoDecRef(PyObject* pyObj) : m_pyObj(pyObj) {}
- ~AutoDecRef() {
- Py_XDECREF(m_pyobj);
+ /// Decref the borrowed python reference
+ ~AutoDecRef()
+ {
+ Py_XDECREF(m_pyObj);
}
- inline bool isNull() const { return m_pyobj == 0; }
+ inline bool isNull() const { return m_pyObj == 0; }
/// Returns the pointer of the Python object being held.
- inline PyObject* object() { return m_pyobj; }
- inline operator PyObject*() { return m_pyobj; }
- inline operator PyTupleObject*() { return reinterpret_cast<PyTupleObject*>(m_pyobj); }
- inline operator bool() const { return m_pyobj; }
- inline PyObject* operator->() { return m_pyobj; }
+ inline PyObject* object() { return m_pyObj; }
+ inline operator PyObject*() { return m_pyObj; }
+ inline operator PyTupleObject*() { return reinterpret_cast<PyTupleObject*>(m_pyObj); }
+ inline operator bool() const { return m_pyObj; }
+ inline PyObject* operator->() { return m_pyObj; }
template<typename T>
T cast()
{
- return reinterpret_cast<T>(m_pyobj);
+ return reinterpret_cast<T>(m_pyObj);
+ }
+
+ /**
+ * Decref the current borrowed python reference and take the reference
+ * borrowed by \p other, so other.isNull() will return true.
+ */
+ void operator=(AutoDecRef& other)
+ {
+ Py_XDECREF(m_pyObj);
+ m_pyObj = other.m_pyObj;
+ other.m_pyObj = 0;
+ }
+
+ /**
+ * Decref the current borrowed python reference and borrow \p other.
+ */
+ void operator=(PyObject* other)
+ {
+ Py_XDECREF(m_pyObj);
+ m_pyObj = other;
}
private:
- PyObject* m_pyobj;
+ PyObject* m_pyObj;
AutoDecRef(const AutoDecRef&);
AutoDecRef& operator=(const AutoDecRef&);
};
-
} // namespace Shiboken
#endif // AUTODECREF_H