DCMTK Version 3.6.9 OFFIS DICOM Toolkit

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
OFunique_ptr< T > Class Template Reference

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.
| OFunique_ptr (OFrvalue_ref(OFunique_ptr) rhs)
| Move constructor.
OFunique_ptr & | operator= (OFrvalue_ref(OFunique_ptr) rhs)
| Move assignment operator.
| ~OFunique_ptr ()
| If get() == OFnullptr there are no effects – otherwise, the owned object is destroyed.
void | reset (pointer p=OFnullptr)
| Replaces the managed object.
pointer | release ()
| Releases the ownership of the managed object if any.
pointer | get () const
| Returns a pointer to the managed object or OFnullptr if no object is owned.
| operator bool () const
| Checks whether *this owns an object, i.e.
bool | operator! () const
| Checks whether *this does NOT own an object, i.e.
T & | operator* () const
| Access the object owned by *this.
pointer | operator-> () const
| Access the object owned by *this.

## 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.

## Detailed Description

template<typename T>
class OFunique_ptr< T >

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:

- unique_ptr managing the object is destroyed
- unique_ptr managing the object is assigned another pointer via reset().

A unique_ptr may also own no objects, in which case it is called empty.

OFunique_ptr is NOT CopyConstructible or CopyAssignable.

Template Parameters

  T | the type of the managed object, e.g. int for an OFunique_ptr behaving like an int*.

Note
  this implementation is meant to be a subset of the c++11's std::unique_ptr that lacks the following features: swap support, custom deleters, specialized handling of pointers to arrays and some functions like comparing OFunique_ptrs or creating a hash key. see http://en.cppreference.com/w/cpp/memory/unique_ptr to compare OFunique_ptr against std::unique_ptr.

## Constructor & Destructor Documentation

## ◆ OFunique_ptr() [1/2]

template<typename T>

OFunique_ptr< T >::OFunique_ptr | ( | pointer | p | ) |
| inline explicit

Constructs a OFunique_ptr which owns p.

Parameters

  p | the pointer that's going to be owned by this unique_ptr.

References m_pData.

## ◆ OFunique_ptr() [2/2]

template<typename T>

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.

Parameters

  rhs | an rvalue reference to another OFunique_ptr object, e.g. obtained via OFmove.

### Example

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!

void consumeDataset( OFunique_ptr<DcmDataset> pDataset )
. . .
OFunique_ptr<DcmDataset> pDataset( new DcmDataset );
if( pDataset && pDataset->read( ... ).good() )
{
// Error: copy constructor not available, as it would
// compromise the unique ownership principle
// consumeDataset( pDataset );
// OFmove allows us to 'tell' OFunique_ptr we want
// to give away the ownership.
consumeDataset( OFmove( pDataset ) );
}
DcmDataset
a class handling the DICOM dataset format (files without meta header)
Definition dcdatset.h:42
OFunique_ptr::OFunique_ptr
OFunique_ptr()
Constructs an empty OFunique_ptr.
Definition ofmem.h:300
OFmove
OFconstexpr xvalue OFmove(T< unspecified > t)
Obtains an rvalue reference to its argument and converts it to an xvalue.

References OFunique_ptr(), and OFrvalue_access().

## Member Function Documentation

## ◆ get()

template<typename T>

pointer OFunique_ptr< T >::get | ( |  | ) | const
| inline

Returns a pointer to the managed object or OFnullptr if no object is owned.

Returns
  Pointer to the managed object or OFnullptr if no object is owned.

References m_pData.

## ◆ operator bool()

template<typename T>

OFunique_ptr< T >::operator bool | ( |  | ) | const
| inline

Checks whether *this owns an object, i.e.

whether get() != OFnullptr.

Returns
  get() != OFnullptr.

References m_pData.

## ◆ operator!()

template<typename T>

bool OFunique_ptr< T >::operator! | ( |  | ) | const
| inline

Checks whether *this does NOT own an object, i.e.

whether get() == OFnullptr.

Returns
  get() == OFnullptr.

References m_pData.

## ◆ operator*()

template<typename T>

T & OFunique_ptr< T >::operator* | ( |  | ) | const
| inline

Access the object owned by *this.

Returns
  the object owned by *this, i.e. *get().

References m_pData.

## ◆ operator->()

template<typename T>

pointer OFunique_ptr< T >::operator-> | ( |  | ) | const
| inline

Access the object owned by *this.

Returns
  same as get().

References m_pData.

## ◆ operator=()

template<typename T>

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.

Parameters

  rhs | an rvalue reference to another OFunique_ptr object, e.g. obtained via OFmove.

References OFunique_ptr(), m_pData, OFrvalue_access(), and reset().

## ◆ release()

template<typename T>

pointer OFunique_ptr< T >::release | ( |  | ) |
| inline

Releases the ownership of the managed object if any.

Retrieves the owned object (if any) and lets the unique_ptr become empty.

Returns
  same as get().

References m_pData.

## ◆ reset()

template<typename T>

void OFunique_ptr< T >::reset | ( | pointer | p = OFnullptr | ) |
| inline

Replaces the managed object.

The previously owned object is deleted if the unique_ptr was not empty.

Parameters

  p | the new pointer to be owned, defaults to OFnullptr.

References m_pData.

Referenced by operator=().

The documentation for this class was generated from the following file:

- ofstd/include/dcmtk/ofstd/ofmem.h

Generated on Sat Mar 1 2025 for DCMTK Version 3.6.9 by Doxygen 1.13.2