#include <ge_autoptr.h>
This class handles automatic allocation and freeing of objects with static Alloc()
and Free
() functions. Most classes in the API with private constructors uses this scheme.
Through AutoAlloc it is possible to use these classes with a scope-based life time.
They are allocated when AutoAlloc is created and freed when the scope is exited and AutoAlloc is destroyed:
Note that the bitmap variable still needs to be checked. If the allocation fails then bitmap == nullptr. Otherwise the bitmap variable can be used just like any pointer.
It is possible to pass parameters to the Alloc()
function via AutoAlloc's constructor:
Public Member Functions | |
AutoAlloc () | |
AutoAlloc (Int32 id) | |
AutoAlloc (Int32 p1, Int32 p2) | |
AutoAlloc (TYPE *initptr) | |
AutoAlloc (AutoAlloc &&other) | |
MAXON_OPERATOR_MOVE_ASSIGNMENT (AutoAlloc) | |
~AutoAlloc () | |
operator const TYPE * () const | |
operator TYPE * () | |
const TYPE * | GetPointer () const |
TYPE * | GetPointer () |
operator const TYPE & () const | |
operator TYPE & () | |
const TYPE * | operator-> () const |
TYPE * | operator-> () |
const TYPE *const * | operator& () const |
TYPE *const * | operator& () |
TYPE * | Release () |
void | Free () |
void | Assign (TYPE *p) |
Private Member Functions | |
const AutoAlloc< TYPE > & | operator= (const AutoAlloc< TYPE > &p) |
AutoAlloc (const AutoAlloc< TYPE > &p) | |
Private Attributes | |
TYPE * | ptr |
Friends | |
MAXON_ATTRIBUTE_FORCE_INLINE friend void | operator% (const AutoAlloc< TYPE > &alloc, maxon::ThreadReferencedError &err) |
AutoAlloc | ( | ) |
Calls TYPE::Alloc()
and stores the returned pointer internally.
Calls TYPE::Alloc(id)
and stores the returned pointer internally.
[in] | id | The parameter. |
Calls TYPE::Alloc(p1, p2)
and stores the returned pointer internally.
[in] | p1 | The first parameter. |
[in] | p2 | The second parameter. |
Stores the returned pointer internally without calling TYPE::Alloc()
.
[in] | initptr | A pointer to an already allocated object. The AutoAlloc instance takes over the ownership of the pointed object. |
Moves the returned pointer internally without calling TYPE::Alloc()
.
[in] | other | A pointer to an already allocated object. The AutoAlloc instance takes over the ownership of the pointed object. |
~AutoAlloc | ( | ) |
Calls TYPE::Free(ptr)
, where ptr
is the internally stored pointer.
operator const 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 TYPE* GetPointer | ( | ) | const |
TYPE* GetPointer | ( | ) |
operator const TYPE & | ( | ) | const |
Conversion to a reference to TYPE
. Makes it possible to pass the object directly to functions like Function(TYPE& t)
.
operator TYPE & | ( | ) |
const TYPE* operator-> | ( | ) | const |
Used for calls like myauto->Function()
.
TYPE* operator-> | ( | ) |
const TYPE* const* operator& | ( | ) | const |
TYPE* const* operator& | ( | ) |
TYPE* Release | ( | ) |
Retrieves the internal pointer and then sets it to nullptr. Thus the ownership is transfered to the caller.
void Free | ( | ) |
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 allocated with TYPE::Alloc() . The AutoAlloc instance takes over the ownership of the pointed object. |
|
friend |
|
private |