namespace py2cpp
{
+PyPtr::PyPtr()
+: _PyPtr()
+{
+}
+
+PyPtr::PyPtr(std::nullptr_t copy)
+: _PyPtr(copy)
+{
+}
+
+PyPtr::PyPtr(PyObject* pyObj)
+: _PyPtr(pyObj)
+{
+}
+
+PyPtr::PyPtr(const PyPtr& copy)
+: _PyPtr(copy.get())
+{
+ Py_XINCREF(copy.get());
+}
+
+PyPtr::PyPtr(PyPtr&& move)
+: _PyPtr(std::move(move))
+{
+}
+
+PyPtr& PyPtr::operator=(std::nullptr_t copy)
+{
+ _PyPtr::operator=(copy);
+ return *this;
+}
+
+PyPtr& PyPtr::operator=(const PyPtr& copy)
+{
+ PyObject* pyCopy = copy.get();
+ if(get() != pyCopy)
+ {
+ Py_XINCREF(pyCopy);
+ reset(pyCopy);
+ }
+ return *this;
+}
+
+PyPtr& PyPtr::operator=(PyPtr&& move)
+{
+ _PyPtr::operator=(std::move(move));
+ return *this;
+}
+
PyPtr PyPtr::getAttr(const std::string& attribute)const
{
PyObject* result = nullptr;
class PyPtr: public _PyPtr
{
public:
- using _PyPtr::_PyPtr;
+ PyPtr();
+ PyPtr(std::nullptr_t copy);
+ PyPtr(PyObject* pyObj);
+ PyPtr(const PyPtr& copy);
+ PyPtr(PyPtr&& move);
+ PyPtr& operator=(const PyPtr& copy);
+ PyPtr& operator=(PyPtr&& move);
+ PyPtr& operator=(std::nullptr_t copy);
+
PyPtr getAttr(const std::string& attribute)const;
void setAttr(const std::string& attribute, const PyPtr& value)const;
std::string repr()const;
CPPUNIT_ASSERT(4.2==d2);
py2cpp::pyResult(i2) = py2cpp::toPyPtr(42);
CPPUNIT_ASSERT(42 == i2);
+ py2cpp::PyPtr copy(obj);
+ i2=0; d2=0.;
+ py2cpp::pyResult(i2, d2) = copy;
+ CPPUNIT_ASSERT(4==i2);
+ CPPUNIT_ASSERT(4.2==d2);
+ py2cpp::PyPtr copy2;
+ copy2 = obj;
+ i2=0; d2=0.;
+ py2cpp::pyResult(i2, d2) = copy2;
+ CPPUNIT_ASSERT(4==i2);
+ CPPUNIT_ASSERT(4.2==d2);
}
void ConversionTest::functionTest()