List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
utl::ShadowPtr< T, DereferenceCheck > Class Template Reference

pointer with built-in initialization, deletion, deep copying More...

#include <ShadowPtr.h>

Inherited by utl::InitializedShadowPtr< ns1::Foo >, utl::InitializedShadowPtr< utl::FFTDataContainer >, utl::InitializedShadowPtr< utl::MultiTabulatedFunctionErrors >, utl::InitializedShadowPtr< utl::MultiTimeDistributionD >, utl::InitializedShadowPtr< utl::MultiTimeDistributionI >, utl::InitializedShadowPtr< utl::MultiTraceD >, utl::InitializedShadowPtr< utl::MultiTraceI >, utl::InitializedShadowPtr< utl::TraceV3D >, and utl::InitializedShadowPtr< T, DereferenceCheck >.

Public Member Functions

T * Get ()
 
const T * Get () const
 
 operator bool () const
 
bool operator!= (const ShadowPtr &sp) const
 
bool operator!= (const T *const p) const
 
T & operator* ()
 
const T & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
ShadowPtroperator= (const ShadowPtr &sp)
 
ShadowPtroperator= (ShadowPtr &&sp)
 
ShadowPtroperator= (T *const p)
 shallow assignment: transfer ownership More...
 
bool operator== (const ShadowPtr &sp) const
 
bool operator== (const T *const p) const
 
 ShadowPtr ()
 
 ShadowPtr (T *const p)
 
 ShadowPtr (const ShadowPtr &sp)
 
 ShadowPtr (ShadowPtr &&sp) noexcept
 
void Swap (ShadowPtr &sp)
 
 ~ShadowPtr () noexcept
 

Protected Member Functions

void DeepCopy (const T *const p)
 

Protected Attributes

T * fPtr = nullptr
 

Private Member Functions

void Delete () noexcept
 

Detailed Description

template<typename T, class DereferenceCheck>
class utl::ShadowPtr< T, DereferenceCheck >

pointer with built-in initialization, deletion, deep copying

This class should behave exactly as a simple pointer to a phantom class T except in this cases: -> empty ctor initializes it to nullptr -> dtor deletes phantom -> operator= deletes current phantom and makes a deep copy of the phantom argument

Author
Darko Veberic and Lukas Nellen

Motivation: In Offline the event hierarchy (evt::Event) has a simple tree-like structure with data leaves and optional branches containing additional substructures (e.g. starting at the top, evt::Event contains header data evt::Header and several branches (sevt::SEvent, fevt::FEvent etc.)). In general an event may not contain all the branches. For instance, a pure SD event will not contain any of the FD parts. That is why in the parent class the branches are implemented as pointers to the child classes, (should be) initialized to zero if the specific part of the event is missing. Although this is the best of the possible solutions, having pointers in the body of the parent class introduces several drawbacks:

To remedy this highly unmanageable code bloat a templated ShadowPtr class is wrapped around the bare C++ pointers. The InitializedShadowPtr variant also initializes the pointer with new copy of the object by calling the default constructor. Ensuring that the Offline classes contain only data members and shadow pointers there is no need to write default constructors, copy constructors, and operator=. In this way we get rid of a lot of highly unmaintainable and error-prone code that repeats itself only with slight variations in all of the Offline classes. Based on the template definition of the ShadowPtr the compiler will (usually more correctly) generate it for free.

Definition at line 163 of file ShadowPtr.h.

Constructor & Destructor Documentation

template<typename T, class DereferenceCheck>
utl::ShadowPtr< T, DereferenceCheck >::ShadowPtr ( )
inline

Definition at line 166 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
utl::ShadowPtr< T, DereferenceCheck >::ShadowPtr ( T *const  p)
inlineexplicit

Definition at line 169 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
utl::ShadowPtr< T, DereferenceCheck >::ShadowPtr ( const ShadowPtr< T, DereferenceCheck > &  sp)
inline

Definition at line 172 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
utl::ShadowPtr< T, DereferenceCheck >::ShadowPtr ( ShadowPtr< T, DereferenceCheck > &&  sp)
inlinenoexcept

Definition at line 174 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
utl::ShadowPtr< T, DereferenceCheck >::~ShadowPtr ( )
inlinenoexcept

Definition at line 176 of file ShadowPtr.h.

Member Function Documentation

template<typename T, class DereferenceCheck>
void utl::ShadowPtr< T, DereferenceCheck >::DeepCopy ( const T *const  p)
inlineprotected
template<typename T, class DereferenceCheck>
void utl::ShadowPtr< T, DereferenceCheck >::Delete ( )
inlineprivatenoexcept
template<typename T, class DereferenceCheck>
T* utl::ShadowPtr< T, DereferenceCheck >::Get ( )
inline

Definition at line 201 of file ShadowPtr.h.

Referenced by atm::MeasuredDBMieModel::ToggleVAODPtr().

template<typename T, class DereferenceCheck>
const T* utl::ShadowPtr< T, DereferenceCheck >::Get ( ) const
inline

Definition at line 202 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
utl::ShadowPtr< T, DereferenceCheck >::operator bool ( ) const
inlineexplicit

Definition at line 215 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
bool utl::ShadowPtr< T, DereferenceCheck >::operator!= ( const ShadowPtr< T, DereferenceCheck > &  sp) const
inline

Definition at line 211 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
bool utl::ShadowPtr< T, DereferenceCheck >::operator!= ( const T *const  p) const
inline

Definition at line 213 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
T& utl::ShadowPtr< T, DereferenceCheck >::operator* ( )
inline

Definition at line 204 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
const T& utl::ShadowPtr< T, DereferenceCheck >::operator* ( ) const
inline

Definition at line 205 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
T* utl::ShadowPtr< T, DereferenceCheck >::operator-> ( )
inline

Definition at line 207 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
const T* utl::ShadowPtr< T, DereferenceCheck >::operator-> ( ) const
inline

Definition at line 208 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
ShadowPtr& utl::ShadowPtr< T, DereferenceCheck >::operator= ( const ShadowPtr< T, DereferenceCheck > &  sp)
inline

Definition at line 180 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
ShadowPtr& utl::ShadowPtr< T, DereferenceCheck >::operator= ( ShadowPtr< T, DereferenceCheck > &&  sp)
inline

Definition at line 190 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
ShadowPtr& utl::ShadowPtr< T, DereferenceCheck >::operator= ( T *const  p)
inline

shallow assignment: transfer ownership

Definition at line 199 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
bool utl::ShadowPtr< T, DereferenceCheck >::operator== ( const ShadowPtr< T, DereferenceCheck > &  sp) const
inline

Definition at line 210 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
bool utl::ShadowPtr< T, DereferenceCheck >::operator== ( const T *const  p) const
inline

Definition at line 212 of file ShadowPtr.h.

template<typename T, class DereferenceCheck>
void utl::ShadowPtr< T, DereferenceCheck >::Swap ( ShadowPtr< T, DereferenceCheck > &  sp)
inline

Definition at line 217 of file ShadowPtr.h.

Referenced by utl::swap().

Member Data Documentation

template<typename T, class DereferenceCheck>
T* utl::ShadowPtr< T, DereferenceCheck >::fPtr = nullptr
protected

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

, generated on Tue Sep 26 2023.