Skip to content
Snippets Groups Projects
PyObjectPtr.cpp 1.32 KiB
Newer Older
  • Learn to ignore specific revisions
  • //  ************************************************************************************************
    //
    //  BornAgain: simulate and fit reflection and scattering
    //
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    //! @file      PyCore/Embed/PyObjectPtr.cpp
    
    //! @brief     Implements class PyObjectPtr.
    
    //!
    //! @homepage  http://www.bornagainproject.org
    //! @license   GNU General Public License v3 or higher (see COPYING)
    //! @copyright Forschungszentrum Jülich GmbH 2018
    //! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
    //
    //  ************************************************************************************************
    
    
    #include "PyInterpreter.h"
    
    PyObjectPtr::PyObjectPtr(PyObject* pyobject_ptr, const bool borrowed)
    
    AlQuemist's avatar
    AlQuemist committed
        : m_ptr{pyobject_ptr}
    
        , m_borrowed{borrowed}
    
    PyObjectPtr::PyObjectPtr(PyObjectPtr&& other)
    
        : PyObjectPtr(other.release())
    
        reset();
        return pyobject_ptr;
    }
    
    void PyObjectPtr::reset()
    {
    
        if (m_borrowed) {
            // borrowed reference need no reference decrement
            reset();
            return;
        }
    
        PyInterpreter::DecRef(m_ptr);
    
    AlQuemist's avatar
    AlQuemist committed
        return static_cast<bool>(m_ptr);