#include <ge_autoptr.h>
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.
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 | |
TYPE * | operator-> () const |
TYPE *const * | operator& () const |
TYPE * | Release () |
void | Free () |
void | Assign (TYPE *p) |
Private Member Functions | |
const AutoFree< TYPE > & | operator= (const AutoFree< TYPE > &p) |
AutoFree (const AutoFree< TYPE > &p) | |
Private Attributes | |
TYPE * | ptr |
Friends | |
MAXON_ATTRIBUTE_FORCE_INLINE friend void | operator% (const AutoFree< TYPE > &alloc, maxon::ThreadReferencedError &err) |
AutoFree | ( | ) |
Default constructor.
Stores the pointer p internally.
[in] | p | A pointer to an object to be freed with TYPE::Free(p) . The AutoFree instance takes over the ownership of the pointed object. |
~AutoFree | ( | ) |
Calls TYPE::Free(ptr)
, where ptr
is the internally stored pointer.
void Set | ( | TYPE * | p | ) |
Sets p as the internal pointer.
[in] | p | A pointer to an object to be freed with TYPE::Free(p) . The AutoFree instance takes over the ownership of the pointed object. |
operator TYPE * | ( | ) | const |
Conversion to a raw pointer to TYPE
. Makes it possible to pass the object directly to functions like Function(TYPE* t)
.
operator TYPE & | ( | ) | const |
Conversion to a reference to TYPE
. Makes it possible to pass the object directly to functions like Function(TYPE& t)
.
TYPE* operator-> | ( | void | ) | const |
Used for calls like myauto->Function()
.
TYPE* const* operator& | ( | ) | const |
TYPE* Release | ( | void | ) |
Retrieves the internal pointer and then sets it to nullptr. Thus the ownership is transfered to the caller.
void Free | ( | void | ) |
Calls TYPE::Free(ptr)
with the internal pointer and sets it to nullptr.
void Assign | ( | TYPE * | p | ) |
Assigns p as the internal pointer.
[in] | p | A pointer to an object to be freed with TYPE::Free(p) . The AutoFree instance takes over the ownership of the pointed object. |
|
friend |
|
private |