|
libUTL++
|
A "smart" pointer that can also be dumb. More...
#include <AutoPtr.h>
Public Member Functions | |
| AutoPtr () | |
| Constructor. More... | |
| AutoPtr (T *ptr, bool owner=true) | |
| Constructor. More... | |
| AutoPtr (AutoPtr< T > &&rhs) noexcept | |
| Move constructor (moving AutoPtr<T>). More... | |
| template<typename NonT > | |
| AutoPtr (AutoPtr< NonT > &&rhs) noexcept | |
| Move constructor (moving AutoPtr<NonT>). More... | |
| ~AutoPtr () | |
| Destructor. More... | |
Misc. Accessors | |
| T * | get () const |
| Get the pointer. More... | |
| bool | isNull () const |
| Determine whether the pointer is nullptr. More... | |
| bool | isOwner () const |
| Get owner flag. More... | |
Manipulation | |
| void | clear () |
| Delete the pointee if the owner flag is true. More... | |
| T * | release () |
| Release ownership (while keeping the pointer). More... | |
| void | set (T *ptr, bool owner=true) |
| Set new pointer and ownership flag. More... | |
| template<typename NonT > | |
| void | setNonT (NonT *ptr, bool owner=true) |
| Set new pointer and ownership flag. More... | |
Assignment Operators | |
| void | steal (AutoPtr< T > &rhs) |
| Steal from AutoPtr<T>. More... | |
| template<typename NonT > | |
| void | stealNonT (AutoPtr< NonT > &rhs) |
| Steal from AutoPtr<NonT>. More... | |
| AutoPtr< T > & | operator= (AutoPtr< T > &&rhs) noexcept |
| Move assignment from AutoPtr<T>. More... | |
| template<typename NonT > | |
| AutoPtr< T > & | operator= (const AutoPtr< NonT > &&rhs) noexcept |
| Move assignment from AutoPtr<NonT>. More... | |
| AutoPtr< T > & | operator= (T *ptr) |
| Assignment operator from T*. More... | |
| template<typename NonT > | |
| AutoPtr< T > & | operator= (NonT *ptr) |
| Assignment operator from NonT*. More... | |
Pointer Dereference and Conversion Operators | |
| T & | operator* () const |
| Pointer dereference operator. More... | |
| T * | operator-> () const |
| Member access operator. More... | |
| operator T* () const | |
| Conversion to pointer. More... | |
A "smart" pointer that can also be dumb.
AutoPtr is similar to std::unique_ptr<>, but it attaches an ownership flag to the underlying pointer, instead of always being responsible for deleting the referenced object.
AutoPtr assumes ownership in all cases except these:
AutoPtr<> isn't really in competition with std::unique_ptr<>, because the ability to act like a "dumb/regular" pointer is either helpful or not helpful in each case. When it's not helpful, there's no reason to consider the use of AutoPtr<>.
|
inline |
|
inline |
Constructor.
| ptr | pointer |
| owner | owner flag |
Definition at line 46 of file AutoPtr.h.
References utl::init().
|
inlinenoexcept |
Move constructor (moving AutoPtr<T>).
Definition at line 53 of file AutoPtr.h.
References utl::init().
|
inlinenoexcept |
Move constructor (moving AutoPtr<NonT>).
Definition at line 61 of file AutoPtr.h.
References utl::init().
|
inline |
|
inline |
Get the pointer.
Definition at line 77 of file AutoPtr.h.
Referenced by utl::AutoPtr< T >::operator T*(), utl::AutoPtr< T >::steal(), and utl::AutoPtr< T >::stealNonT().
|
inline |
|
inline |
Get owner flag.
Definition at line 91 of file AutoPtr.h.
Referenced by utl::AutoPtr< T >::steal(), and utl::AutoPtr< T >::stealNonT().
|
inline |
|
inline |
Release ownership (while keeping the pointer).
Definition at line 116 of file AutoPtr.h.
Referenced by utl::AutoPtr< T >::steal(), and utl::AutoPtr< T >::stealNonT().
|
inline |
|
inline |
|
inline |
Steal from AutoPtr<T>.
Definition at line 148 of file AutoPtr.h.
References utl::AutoPtr< T >::get(), utl::AutoPtr< T >::isOwner(), and utl::AutoPtr< T >::release().
|
inline |
Steal from AutoPtr<NonT>.
Definition at line 157 of file AutoPtr.h.
References utl::AutoPtr< T >::get(), utl::AutoPtr< T >::isOwner(), and utl::AutoPtr< T >::release().
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Conversion to pointer.
Definition at line 209 of file AutoPtr.h.
References ASSERTD, utl::deInit(), utl::AutoPtr< T >::get(), and utl::init().