A simple smart pointer providing strict ownership semantics. More...
#include "murl_auto_pointer.h"
Public Types | |
using | ValueType = Type1 |
The template parameter value type. | |
Public Member Functions | |
AutoPointer () | |
The default constructor. More... | |
AutoPointer (Type1 *pointer) | |
Constructor taking ownership of a memory location. More... | |
AutoPointer (const AutoPointer &autoPointer) | |
Copy constructor. More... | |
template<class Type2 > | |
AutoPointer (const AutoPointer< Type2 > &autoPointer) | |
Constructor for automatic downcast. More... | |
AutoPointer & | operator= (const AutoPointer &autoPointer) |
Assignment operator. More... | |
template<class Type2 > | |
AutoPointer & | operator= (const AutoPointer< Type2 > &autoPointer) |
Assignment operator for an object of different type. More... | |
~AutoPointer () | |
The destructor. More... | |
Bool | IsNull () const |
Check if the memory pointer is null. More... | |
Type1 & | operator* () const |
Indirection operator. More... | |
Type1 * | operator-> () const |
Dereference operator. More... | |
Type1 * | Get () const |
Get the pointer to the memory. More... | |
Type1 * | Release () |
Release the memory pointer. More... | |
void | Reset (Type1 *pointer=nullptr) |
Take ownership of a memory location. More... | |
template<class Type2 > | |
operator AutoPointer< Type2 > () | |
Conversion operator. More... | |
AutoPointer (AutoPointerRef< Type1 > autoPointerRef) | |
Automatic conversions. More... | |
Detailed Description
template<class Type1>
class Murl::AutoPointer< Type1 >
A simple smart pointer providing strict ownership semantics.
An AutoPointer owns the object it holds a pointer to. Copying an AutoPointer copies the pointer and transfers ownership to the destination. If more than one AutoPointer owns the same object at the same time the behavior of the program is undefined.
The uses of AutoPointer include providing passing ownership of dynamically allocated memory to a function and returning dynamically allocated memory from a function.
Constructor & Destructor Documentation
◆ AutoPointer() [1/5]
|
inlineexplicit |
The default constructor.
Set a null pointer.
◆ AutoPointer() [2/5]
|
inlineexplicit |
Constructor taking ownership of a memory location.
- Parameters
-
pointer The memory to take the ownership from.
◆ AutoPointer() [3/5]
|
inline |
Copy constructor.
Release() the memory pointer in the const autoPointer.
- Parameters
-
autoPointer The AutoPointer object to transfer.
◆ AutoPointer() [4/5]
|
inlineexplicit |
Constructor for automatic downcast.
Release() the memory pointer in the const autoPointer.
- Parameters
-
autoPointer The AutoPointer object to transfer.
◆ ~AutoPointer()
|
inline |
The destructor.
Free (delete) the memory.
◆ AutoPointer() [5/5]
|
inline |
Automatic conversions.
These operations convert an AutoPointer into and from an AutoPointerRef automatically as needed. This allows constructs such as:
- Parameters
-
autoPointerRef The AutoPointer object to transfer.
Member Function Documentation
◆ operator=() [1/2]
|
inline |
Assignment operator.
Release() the memory pointer in the const autoPointer.
- Parameters
-
autoPointer The AutoPointer object to transfer.
- Returns
- The object itself.
References Murl::AutoPointer< Type1 >::Release(), and Murl::AutoPointer< Type1 >::Reset().
◆ operator=() [2/2]
|
inline |
Assignment operator for an object of different type.
Release() the memory pointer in the const autoPointer.
- Parameters
-
autoPointer The AutoPointer object to transfer.
- Returns
- The object itself.
References Murl::AutoPointer< Type1 >::Release(), and Murl::AutoPointer< Type1 >::Reset().
◆ IsNull()
|
inline |
Check if the memory pointer is null.
- Returns
- True if pointer to memory is null.
◆ operator*()
|
inline |
Indirection operator.
- Returns
- The reference to the memory.
◆ operator->()
|
inline |
Dereference operator.
- Returns
- The pointer to the memory.
◆ Get()
|
inline |
Get the pointer to the memory.
- Returns
- The pointer to the memory.
◆ Release()
|
inline |
Release the memory pointer.
The receiver of the memory returned takes the ownership. The memory pointer of this object is set to 0.
- Returns
- The pointer to the memory.
Referenced by Murl::AutoPointer< Type1 >::operator AutoPointer< Type2 >(), and Murl::AutoPointer< Type1 >::operator=().
◆ Reset()
|
inline |
Take ownership of a memory location.
If the object already owns a memory, the memory is deleted.
- Parameters
-
pointer The memory to take the ownership from.
Referenced by Murl::AutoPointer< Type1 >::operator=().
◆ operator AutoPointer< Type2 >()
|
inline |
Conversion operator.
Transfer the memory ownership to an object of different type.
- Returns
- The Object of differen type.
References Murl::AutoPointer< Type1 >::Release().
The documentation for this class was generated from the following file:
- murl_auto_pointer.h