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 ()
  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 * ()
  operator const TYPE & () const
  operator TYPE & ()
const TYPE operator-> () const
TYPE operator-> ()
const TYPE *const *  operator& () const
TYPE *const *  operator& ()
TYPE 发行 ()
void  Free ()
void  赋值 ( TYPE *p)

私有成员函数

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() [1/6]

AutoAlloc ( const AutoAlloc < TYPE > &  p )
private

◆  AutoAlloc() [2/6]

AutoAlloc ( )

Calls TYPE::Alloc() and stores the returned pointer internally.

◆  AutoAlloc() [3/6]

AutoAlloc ( Int32   id )
explicit

Calls TYPE::Alloc(id) and stores the returned pointer internally.

参数
[in] id The parameter.

◆  AutoAlloc() [4/6]

AutoAlloc ( Int32   p1 ,
Int32   p2  
)

Calls TYPE::Alloc(p1, p2) and stores the returned pointer internally.

参数
[in] p1 The first parameter.
[in] p2 The second parameter.

◆  AutoAlloc() [5/6]

AutoAlloc ( TYPE initptr )
explicit

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]

AutoAlloc ( AutoAlloc < TYPE > &&  other )

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()

~ AutoAlloc ( )

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

成员函数文档编制

◆  operator=()

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

◆  MAXON_OPERATOR_MOVE_ASSIGNMENT()

MAXON_OPERATOR_MOVE_ASSIGNMENT ( AutoAlloc < TYPE )

◆  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 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 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]

TYPE * operator-> ( )

◆  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()

TYPE * 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()

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.

参数
[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%

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

Member Data Documentation

◆  ptr

TYPE * ptr
private
AutoAlloc
定义: ge_autoptr.h:36