AutoFree< TYPE > Class Template Reference

#include <ge_autoptr.h>

详细描述

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.

另请参阅
AutoAlloc

公共成员函数

  AutoFree ()
  AutoFree ( AutoFree &&src)
  AutoFree ( TYPE *p)
  ~AutoFree ()
void  Set ( TYPE *p)
  operator TYPE * () const
  operator TYPE & () const
TYPE operator-> () const
TYPE *const *  operator& () const
TYPE 发行 ()
void  Free ()
void  赋值 ( TYPE *p)

私有成员函数

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

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

◆  ~AutoFree()

~ AutoFree ( )

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

成员函数文档编制

◆  operator=()

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

◆  Set()

void Set ( TYPE p )

Sets p as the internal pointer.

参数
[in] p A pointer to an object to be freed with TYPE::Free(p) 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) .

返回
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) .

注意
This dereferences the internal pointer. Hence, it must not be nullptr .
返回
A reference to the pointed object.

◆  operator->()

TYPE * operator-> ( ) const

Used for calls like myauto->Function() .

注意
This dereferences the internal pointer. Hence, it must not be nullptr .
返回
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.

注意
This means that it is impossible to get the address of the actual AutoFree instance.
返回
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.

返回
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 to be freed with TYPE::Free(p) 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