Open Search
    AutoFree< TYPE > Class Template Reference

    #include <ge_autoptr.h>

    Detailed Description

    template<class TYPE>
    class AutoFree< TYPE >

    This class handles automatic deallocation of objects with TYPE::Free(). It is similar in function to AutoAlloc, but the object has to have been previously allocated.

    See also
    AutoAlloc

    Public Member Functions

     AutoFree ()
     
     AutoFree (AutoFree &&src)
     
     MAXON_OPERATOR_MOVE_ASSIGNMENT (AutoFree)
     
     AutoFree (TYPE *p)
     
     ~AutoFree ()
     
    void Set (TYPE *p)
     
     operator TYPE * () const
     
     operator TYPE & () const
     
    TYPEoperator-> () const
     
    TYPE *const * operator& () const
     
    TYPERelease ()
     
    void Free ()
     
    void Assign (TYPE *p)
     

    Private Member Functions

    const AutoFree< TYPE > & operator= (const AutoFree< TYPE > &p)
     
     AutoFree (const AutoFree< TYPE > &p)
     

    Private Attributes

    TYPEptr
     

    Friends

    MAXON_ATTRIBUTE_FORCE_INLINE friend void operator% (const AutoFree< TYPE > &alloc, maxon::ThreadReferencedError &err)
     

    Constructor & Destructor Documentation

    ◆ AutoFree() [1/4]

    AutoFree ( const AutoFree< TYPE > &  p)
    private

    ◆ AutoFree() [2/4]

    AutoFree ( )

    Default constructor.

    ◆ AutoFree() [3/4]

    AutoFree ( AutoFree< TYPE > &&  src)

    ◆ AutoFree() [4/4]

    AutoFree ( TYPE p)
    explicit

    Stores the pointer p internally.

    Parameters
    [in]pA pointer to an object to be freed with TYPE::Free(p). The AutoFree instance takes over the ownership of the pointed object.

    ◆ ~AutoFree()

    ~AutoFree ( )

    Calls TYPE::Free(ptr), where ptr is the internally stored pointer.

    Member Function Documentation

    ◆ operator=()

    const AutoFree<TYPE>& operator= ( const AutoFree< TYPE > &  p)
    private

    ◆ MAXON_OPERATOR_MOVE_ASSIGNMENT()

    MAXON_OPERATOR_MOVE_ASSIGNMENT ( AutoFree< TYPE )

    ◆ Set()

    void Set ( TYPE p)

    Sets p as the internal pointer.

    Parameters
    [in]pA pointer to an object to be freed with TYPE::Free(p). The AutoFree instance takes over the ownership of the pointed object.

    ◆ operator TYPE *()

    operator TYPE * ( ) const

    Conversion to a raw pointer to TYPE. Makes it possible to pass the object directly to functions like Function(TYPE* t).

    Returns
    The internal pointer. The AutoFree instance owns the pointed object.

    ◆ operator TYPE &()

    operator TYPE & ( ) const

    Conversion to a reference to TYPE. Makes it possible to pass the object directly to functions like Function(TYPE& t).

    Note
    This dereferences the internal pointer. Hence, it must not be nullptr.
    Returns
    A reference to the pointed object.

    ◆ operator->()

    TYPE* operator-> ( ) const

    Used for calls like myauto->Function().

    Note
    This dereferences the internal pointer. Hence, it must not be nullptr.
    Returns
    The internal pointer. The AutoFree instance owns the pointed object.

    ◆ operator&()

    TYPE* const* operator& ( ) const

    Used for expressions like &myauto. Extracts a pointer to the internal pointer.

    Note
    This means that it is impossible to get the address of the actual AutoFree instance.
    Returns
    A pointer to the internal pointer. The AutoFree instance owns the pointed object.

    ◆ Release()

    TYPE* Release ( )

    Retrieves the internal pointer and then sets it to nullptr. Thus the ownership is transfered to the caller.

    Returns
    The internal pointer. The caller takes over the ownership of the pointed object.

    ◆ Free()

    void Free ( )

    Calls TYPE::Free(ptr) with the internal pointer and sets it to nullptr.

    ◆ Assign()

    void Assign ( TYPE p)

    Assigns p as the internal pointer.

    Parameters
    [in]pA pointer to an object to be freed with TYPE::Free(p). The AutoFree instance takes over the ownership of the pointed object.

    Friends And Related Function Documentation

    ◆ operator%

    MAXON_ATTRIBUTE_FORCE_INLINE friend void operator% ( const AutoFree< TYPE > &  alloc,
    maxon::ThreadReferencedError err 
    )
    friend

    Member Data Documentation

    ◆ ptr

    TYPE* ptr
    private