-
首页
-
C4D R23.110 C++ SDK
AutoAlloc< TYPE > Class Template Reference
#include <ge_autoptr.h>
详细描述
template<class TYPE>
class AutoAlloc< TYPE >
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:
{
AutoAlloc<BaseBitmap>
bitmap;
if
(!bitmap)
return
;
// ...
}
注意,
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:
AutoAlloc<VariableTag>
hermite(Thermite2d, 100);
-
警告
-
If it is ever needed to give away the allocated object to any other function
AutoAlloc
cannot be used. It will not release the ownership, the object will still be deleted when the scope is exited.
-
另请参阅
-
AutoNew AutoPtr
构造函数 & 析构函数文档编制
◆
AutoAlloc()
[1/6]
◆
AutoAlloc()
[2/6]
Calls
TYPE::Alloc()
and stores the returned pointer internally.
◆
AutoAlloc()
[3/6]
Calls
TYPE::Alloc(id)
and stores the returned pointer internally.
-
参数
-
◆
AutoAlloc()
[4/6]
Calls
TYPE::Alloc(p1, p2)
and stores the returned pointer internally.
-
参数
-
[in]
|
p1
|
The first parameter.
|
[in]
|
p2
|
The second parameter.
|
◆
AutoAlloc()
[5/6]
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.
|
◆
AutoAlloc()
[6/6]
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)
,其中
ptr
is the internally stored pointer.
成员函数文档编制
◆
operator=()
◆
MAXON_OPERATOR_MOVE_ASSIGNMENT()
◆
operator const TYPE *()
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)
.
-
返回
-
The internal pointer. The
AutoAlloc
instance owns the pointed object.
◆
operator TYPE *()
◆
operator const TYPE &()
operator const
TYPE
&
|
(
|
|
)
|
const
|
Conversion to a reference to
TYPE
. Makes it possible to pass the object directly to functions like
Function(TYPE& t)
.
-
注意
-
This dereferences the internal pointer. Hence, it must not be
nullptr
.
-
返回
-
A reference to the pointed object.
◆
operator TYPE &()
◆
operator->()
[1/2]
const
TYPE
* operator->
|
(
|
|
)
|
const
|
Used for calls like
myauto->Function()
.
-
注意
-
This dereferences the internal pointer. Hence, it must not be
nullptr
.
-
返回
-
The internal pointer. The
AutoAlloc
instance owns the pointed object.
◆
operator->()
[2/2]
◆
operator&()
[1/2]
const
TYPE
* const* operator&
|
(
|
|
)
|
const
|
Used for expressions like
&myauto
. Extracts a pointer to the internal pointer.
-
注意
-
This means that it is impossible to get the address of the actual
AutoAlloc
instance.
-
返回
-
A pointer to the internal pointer. The
AutoAlloc
instance owns the pointed object.
◆
operator&()
[2/2]
TYPE
* const* operator&
|
(
|
|
)
|
|
◆
Release()
Retrieves the internal pointer and then sets it to
nullptr
. Thus the ownership is transfered to the caller.
-
返回
-
The internal pointer. The caller takes over the ownership of the pointed object.
◆
Free()
Calls
TYPE::Free(ptr)
with the internal pointer and sets it to
nullptr
.
◆
Assign()
Assigns
p
as the internal pointer.
-
参数
-
[in]
|
p
|
A pointer to an object allocated with
TYPE::Alloc()
。
AutoAlloc
instance takes over the ownership of the pointed object.
|
Friends And Related Function Documentation
◆
operator%
Member Data Documentation
◆
ptr