DCMTK Version 3.7.0 OFFIS DICOM Toolkit

Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
OFshared_ptr< T > Class Template Reference

OFshared_ptr is a smart pointer that retains shared ownership of an object through a pointer. More...

## Classes
class | Data
| Helper class containing the reference to the managed object and the reference counter. More...

## Public Member Functions
| OFshared_ptr (T *const pt=OFnullptr)
| Constructs a shared_ptr with pt as the managed object. More...
| OFshared_ptr (const OFshared_ptr &other)
| Constructs a shared_ptr which shares ownership of the object managed by other. More...
OFshared_ptr & | operator= (const OFshared_ptr &other)
| Replaces the managed object with the one managed by other. More...
| ~OFshared_ptr ()
| If *this owns an object and it is the last shared_ptr owning it, the object is destroyed. More...
| operator OFBool () const
| Checks if *this manages an object, i.e. More...
OFBool | operator! () const
| Checks if *this does not manage an object, i.e. More...
T & | operator* () const
| Dereferences pointer to the managed object. More...
T * | operator-> () const
| Dereferences pointer to the managed object. More...
T * | get () const
| Returns a pointer to the managed object. More...
void | reset (T *const pt=OFnullptr)
| Replaces the managed object with an object pointed to by pt. More...

## Private Member Functions
void | destroy ()
| decrement the reference counter, destroy the managed object and the counter if the counter reached zero.

## Private Attributes
Data * | m_pData
| A pointer to the management data structure containing the actual reference to the managed object and the reference counter.

## Detailed Description

### template<typename T>
class OFshared_ptr< T >

OFshared_ptr is a smart pointer that retains shared ownership of an object through a pointer.

Several OFshared_ptr objects may own the same object; the object is destroyed when the last remaining OFshared_ptr referring to it is destroyed or reset.

An OFshared_ptr may also own no objects, in which case it is called empty.

OFshared_ptr meets the requirements of CopyConstructible and CopyAssignable.

Template Parameters

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

Note
  this implementation is meant to be a subset of the c++11's std::shared_ptr that lacks the following features: swap support, support for weak references, atomic access to the managed object, custom deleters and some functions like comparing OFshared_ptrs or read access to the reference counter. see http://en.cppreference.com/w/cpp/memory/shared_ptr to compare OFshared_ptr against std::shared_ptr.

## Constructor & Destructor Documentation

## ◆ OFshared_ptr() [1/2]

template<typename T >

OFshared_ptr< T >::OFshared_ptr | ( | T *const | pt = `OFnullptr` | ) |
| inline

Constructs a shared_ptr with pt as the managed object.

Parameters

  pt | the managed object that this shared_ptr takes the ownership to.

## ◆ OFshared_ptr() [2/2]

template<typename T >

OFshared_ptr< T >::OFshared_ptr | ( | const OFshared_ptr< T > & | other | ) |
| inline

Constructs a shared_ptr which shares ownership of the object managed by other.

If other manages no object, *this manages no object too.

Parameters

  other | another shared_ptr that this one will be copy constructed from.

References OFshared_ptr< T >::Data::increment_count(), and OFshared_ptr< T >::m_pData.

## ◆ ~OFshared_ptr()

template<typename T >

OFshared_ptr< T >::~OFshared_ptr | ( |  | ) |
| inline

If *this owns an object and it is the last shared_ptr owning it, the object is destroyed.

Otherwise does nothing.

References OFshared_ptr< T >::destroy().

## Member Function Documentation

## ◆ get()

template<typename T >

T* OFshared_ptr< T >::get | ( |  | ) | const
| inline

Returns a pointer to the managed object.

Returns
  a pointer to the managed object.

References OFshared_ptr< T >::m_pData, and OFshared_ptr< T >::Data::pointer().

## ◆ operator OFBool()

template<typename T >

OFshared_ptr< T >::operator OFBool | ( |  | ) | const
| inline

Checks if *this manages an object, i.e.

whether get() != 0.

Returns
  OFTrue if *this manages an object, OFFalse otherwise.

## ◆ operator!()

template<typename T >

OFBool OFshared_ptr< T >::operator! | ( |  | ) | const
| inline

Checks if *this does not manage an object, i.e.

whether get() == 0.

Returns
  OFFalse if *this manages an object, OFTrue otherwise.

References OFshared_ptr< T >::m_pData, and OFshared_ptr< T >::Data::pointer().

## ◆ operator*()

template<typename T >

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

Dereferences pointer to the managed object.

Returns
  a reference to the managed object.

References OFshared_ptr< T >::m_pData, and OFshared_ptr< T >::Data::pointer().

## ◆ operator->()

template<typename T >

T* OFshared_ptr< T >::operator-> | ( |  | ) | const
| inline

Dereferences pointer to the managed object.

Returns
  a pointer to the managed object.

References OFshared_ptr< T >::m_pData, and OFshared_ptr< T >::Data::pointer().

## ◆ operator=()

template<typename T >

OFshared_ptr& OFshared_ptr< T >::operator= | ( | const OFshared_ptr< T > & | other | ) |
| inline

Replaces the managed object with the one managed by other.

Parameters

  other | another shared_ptr that this one will be copy assigned from.

References OFshared_ptr< T >::destroy(), OFshared_ptr< T >::Data::increment_count(), and OFshared_ptr< T >::m_pData.

## ◆ reset()

template<typename T >

void OFshared_ptr< T >::reset | ( | T *const | pt = `OFnullptr` | ) |
| inline

Replaces the managed object with an object pointed to by pt.

Parameters

  pt | pointer to an object to acquire ownership of.

References OFshared_ptr< T >::destroy(), and OFshared_ptr< T >::m_pData.

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

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

Generated on Mon Dec 15 2025 for DCMTK Version 3.7.0 by Doxygen 1.9.1