Open Search
    CPyInterface Class Reference

    #include <cpython_ref.h>

    Inheritance diagram for CPyInterface:

    Detailed Description

    Interface class for CPyRefs which removes the need for manual reference counting. The internally stored PyObject can be disconnected from this wrapper class by calling CPyInterface::Disconnect.

    @MAXON_ANNOTATION{refclass=false}

    Public Member Functions

    MAXON_METHOD void Init (const CPythonLibraryInterface *lib, REFTYPE refType, NativePyObject *pyObject)
     
    MAXON_METHOD void Incref ()
     
    MAXON_METHOD void Decref ()
     
    MAXON_METHOD Int64 GetRefCount ()
     
    MAXON_METHOD const CPythonLibraryInterfaceGetLibrary () const
     
    MAXON_METHOD CPyTypeRef GetTypeRef () const
     
    MAXON_METHOD NativePyObjectGetPyObject () const
     
    MAXON_METHOD NativePyObjectDisconnect ()
     
    template<typename T = NativePyObject>
    MAXON_FUNCTION T * Get () const
     
    template<typename T = NativePyObject>
    MAXON_FUNCTION T * GetAndIncref ()
     

    Static Public Member Functions

    static MAXON_FUNCTION CPyRef CreateRef (const CPythonLibraryInterface *lib, REFTYPE refType, NativePyObject *pyObject)
     
    static MAXON_FUNCTION CPyConstRef CreateConstRef (const CPythonLibraryInterface *lib, REFTYPE refType, NativePyObject *pyObject)
     
    static MAXON_FUNCTION CPyTempRef CreateTempRef (const CPythonLibraryInterface *lib, NativePyObject *pyObject)
     

    Private Member Functions

     MAXON_INTERFACE (CPyInterface, MAXON_REFERENCE_NORMAL, "net.maxon.python.interface.cpyref")
     

    Member Function Documentation

    ◆ MAXON_INTERFACE()

    MAXON_INTERFACE ( CPyInterface  ,
    MAXON_REFERENCE_NORMAL  ,
    "net.maxon.python.interface.cpyref"   
    )
    private

    ◆ CreateRef()

    static MAXON_FUNCTION CPyRef CreateRef ( const CPythonLibraryInterface lib,
    REFTYPE  refType,
    NativePyObject pyObject 
    )
    static

    Creates a CPyRef reference by a given NativePyObject. GIL must be held.

    Parameters
    [in]libThe NativePyObject's library origin.
    [in]refTypeRef count handler information.
    Returns
    Returns a new wrapper reference.

    ◆ CreateConstRef()

    static MAXON_FUNCTION CPyConstRef CreateConstRef ( const CPythonLibraryInterface lib,
    REFTYPE  refType,
    NativePyObject pyObject 
    )
    static

    Creates a immutable CPyConstRef reference by a given NativePyObject. GIL must be held.

    Parameters
    [in]libThe NativePyObject's library origin.
    [in]refTypeRef count handler information.
    Returns
    Returns a new wrapper reference.

    ◆ CreateTempRef()

    static MAXON_FUNCTION CPyTempRef CreateTempRef ( const CPythonLibraryInterface lib,
    NativePyObject pyObject 
    )
    static

    Creates a temporary CPyTempRef reference by a given NativePyObject. GIL must be held.

    Parameters
    [in]libThe NativePyObject's library origin.
    Returns
    Returns a new wrapper reference.

    ◆ Init()

    MAXON_METHOD void Init ( const CPythonLibraryInterface lib,
    REFTYPE  refType,
    NativePyObject pyObject 
    )

    Initializes the wrapper reference. GIL must be held.

    Parameters
    [in]libThe NativePyObject's library origin.
    [in]refTypeRef count handler information.

    ◆ Incref()

    MAXON_METHOD void Incref ( )

    Increments the reference count. Instance must be already initialized. GIL must be held.

    ◆ Decref()

    MAXON_METHOD void Decref ( )

    Decrements the reference count. Instance must be already initialized. GIL must be held.

    ◆ GetRefCount()

    MAXON_METHOD Int64 GetRefCount ( )

    Decrements the reference count. Instance must be already initialized. GIL must be held.

    Returns
    Reference count.

    ◆ GetLibrary()

    MAXON_METHOD const CPythonLibraryInterface* GetLibrary ( ) const

    Returns the library pointer with which the instance got initialized.

    ◆ GetTypeRef()

    MAXON_METHOD CPyTypeRef GetTypeRef ( ) const

    Returns the type object of the wrapped NativePyObject. GIL must be held.

    Returns
    Type reference.

    ◆ GetPyObject()

    MAXON_METHOD NativePyObject* GetPyObject ( ) const

    Returns the internal NativePyObject with which the instance got initialized. No reference count change is performed.

    Returns
    Internal NativePyObject

    ◆ Disconnect()

    MAXON_METHOD NativePyObject* Disconnect ( )

    Returns the internal NativePyObject with which the instance got initialized. Objects reference count needs to be decremented if not used anymore. The wrapper reference becomes invalid, no other function should be called, and it should be deleted soon as possible. GIL must be held.

    Returns
    Internal NativePyObject

    ◆ Get()

    MAXON_FUNCTION T* Get ( ) const

    Returns the internal NativePyObject cast to a target type. GIL must be held. No check is performed if the cast is valid or not. No reference count change is performed.

    Returns
    Internal NativePyObject casted.

    ◆ GetAndIncref()

    MAXON_FUNCTION T* GetAndIncref ( )

    Returns the internal NativePyObject cast to a target type. No check is performed if the cast is valid or not. Reference count is incremented before function returns. The wrapper reference stays valid. GIL must be held.

    Returns
    Internal NativePyObject casted.