DCMTK Version 3.6.8
OFFIS DICOM Toolkit
|
OFunique_ptr is a smart pointer that retains sole ownership of an object through a pointer and destroys that object when the unique_ptr goes out of scope. More...
Public Types | |
typedef T * | pointer |
typedef of pointer type T* for template programmers. | |
typedef T | element_type |
T, the type of the object managed by this unique_ptr. | |
Public Member Functions | |
OFunique_ptr () | |
Constructs an empty OFunique_ptr. | |
OFunique_ptr (pointer p) | |
Constructs a OFunique_ptr which owns p. More... | |
OFunique_ptr (OFrvalue_ref(OFunique_ptr) rhs) | |
Move constructor. More... | |
OFunique_ptr & | operator= (OFrvalue_ref(OFunique_ptr) rhs) |
Move assignment operator. More... | |
~OFunique_ptr () | |
If get() == OFnullptr there are no effects – otherwise, the owned object is destroyed. | |
void | reset (pointer p=OFnullptr) |
Replaces the managed object. More... | |
pointer | release () |
Releases the ownership of the managed object if any. More... | |
pointer | get () const |
Returns a pointer to the managed object or OFnullptr if no object is owned. More... | |
operator bool () const | |
Checks whether *this owns an object, i.e. More... | |
bool | operator! () const |
Checks whether *this does NOT own an object, i.e. More... | |
T & | operator* () const |
Access the object owned by *this. More... | |
pointer | operator-> () const |
Access the object owned by *this. More... | |
Private Member Functions | |
OFunique_ptr (const OFunique_ptr &) | |
Disable copy construction. | |
OFunique_ptr & | operator= (const OFunique_ptr &) |
Disable copy assignment. | |
Private Attributes | |
pointer | m_pData |
The underlying (raw) pointer. | |
OFunique_ptr is a smart pointer that retains sole ownership of an object through a pointer and destroys that object when the unique_ptr goes out of scope.
No two unique_ptr instances can manage the same object.
The object is destroyed and its memory deallocated when either of the following happens:
A unique_ptr may also own no objects, in which case it is called empty.
OFunique_ptr is NOT CopyConstructible or CopyAssignable.
T | the type of the managed object, e.g. int for an OFunique_ptr behaving like an int*. |
|
inlineexplicit |
Constructs a OFunique_ptr which owns p.
p | the pointer that's going to be owned by this unique_ptr. |
OFunique_ptr< T >::OFunique_ptr | ( | OFrvalue_ref(OFunique_ptr< T >) | rhs | ) |
Move constructor.
The move constructor moves the ownership of the managed object from its parameter to the newly created OFunique_ptr object, effectively emptying the former OFunique_ptr object.
rhs | an rvalue reference to another OFunique_ptr object, e.g. obtained via OFmove. |
This example shows how to move the ownership of a managed object from one OFunique_ptr to another. Note that the ownership always remains unique in this example, even if an error occurred while reading the Dataset. Therefore no memory leaks are possible!
References OFrvalue_access().
|
inline |
Returns a pointer to the managed object or OFnullptr if no object is owned.
References OFunique_ptr< T >::m_pData.
|
inline |
Checks whether *this owns an object, i.e.
whether get() != OFnullptr.
References OFunique_ptr< T >::m_pData.
|
inline |
Checks whether *this does NOT own an object, i.e.
whether get() == OFnullptr.
References OFunique_ptr< T >::m_pData.
|
inline |
Access the object owned by *this.
References OFunique_ptr< T >::m_pData.
|
inline |
OFunique_ptr & OFunique_ptr< T >::operator= | ( | OFrvalue_ref(OFunique_ptr< T >) | rhs | ) |
Move assignment operator.
The move assignment operator moves the ownership of the managed object from its parameter to itself, effectively emptying the other OFunique_ptr object. See OFunique_ptr's move constructor for more information.
rhs | an rvalue reference to another OFunique_ptr object, e.g. obtained via OFmove. |
References OFunique_ptr< T >::m_pData, OFrvalue_access(), and OFunique_ptr< T >::reset().
|
inline |
Releases the ownership of the managed object if any.
Retrieves the owned object (if any) and lets the unique_ptr become empty.
References OFunique_ptr< T >::m_pData.
|
inline |
Replaces the managed object.
The previously owned object is deleted if the unique_ptr was not empty.
p | the new pointer to be owned, defaults to OFnullptr. |
References OFunique_ptr< T >::m_pData.
Referenced by OFunique_ptr< T >::operator=().