DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
dd4hep::Handle< T > Class Template Reference

Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects. More...

#include <Handle.h>

Inheritance diagram for dd4hep::Handle< T >:
dd4hep::Author dd4hep::CartesianGridUV dd4hep::CartesianGridXY dd4hep::CartesianGridXYZ dd4hep::CartesianGridXZ dd4hep::CartesianGridYZ dd4hep::CartesianStripX dd4hep::CartesianStripY dd4hep::CartesianStripZ dd4hep::CylindricalGridPhiZ dd4hep::GridPhiEta dd4hep::GridRPhiEta dd4hep::MultiSegmentation dd4hep::NoSegmentation dd4hep::PolarGridRPhi dd4hep::PolarGridRPhi2 dd4hep::sim::Geant4VolumeManager dd4hep::Solid_type< T > dd4hep::WaferGridXY

Public Types

typedef T Object
 Extern accessible definition of the contained element type. More...
 
typedef Handle< T > Base
 Self type: used by sub-classes. More...
 

Public Member Functions

 Handle ()=default
 Default constructor. More...
 
 Handle (Handle< T > &&element)=default
 Copy constructor. More...
 
 Handle (const Handle< T > &element)=default
 Copy constructor. More...
 
 Handle (T *element)
 Initializing constructor from pointer. More...
 
template<typename Q >
 Handle (Q *element)
 Initializing constructor from unrelated pointer with type checking. More...
 
template<typename Q >
 Handle (const Handle< Q > &element)
 Initializing constructor from unrelated handle with type checking. More...
 
Handle< T > & operator= (Handle< T > &&element)=default
 Assignment move operator. More...
 
Handle< T > & operator= (const Handle< T > &element)=default
 Assignment copy operator. More...
 
bool operator== (const Handle< T > &element) const
 Boolean operator == used for RB tree insertions. More...
 
bool operator< (const Handle< T > &element) const
 Boolean operator < used for RB tree insertions. More...
 
bool operator> (const Handle< T > &element) const
 Boolean operator > used for RB tree insertions. More...
 
bool isValid () const
 Check the validity of the object held by the handle. More...
 
bool operator! () const
 Check the validity of the object held by the handle. More...
 
Handle< T > & clear ()
 Release the object held by the handle. More...
 
T * operator-> () const
 Access the held object using the -> operator. More...
 
 operator T& () const
 Automatic type conversion to an object references. More...
 
T & operator* () const
 Access the held object using the * operator. More...
 
T * ptr () const
 Access to the held object. More...
 
template<typename Q >
Q * _ptr () const
 Access to an unrelated object type. More...
 
template<typename Q >
Q * data () const
 Access to an unrelated object type. More...
 
template<typename Q >
Q & object () const
 Access to an unrelated object type. More...
 
T * access () const
 Checked object access. Throws invalid handle runtime exception if invalid handle. More...
 
const char * name () const
 Access the object name (or "" if not supported by the object) More...
 
void assign (Object *n, const std::string &nam, const std::string &title)
 Assign a new named object. Note: object references must be managed by the user. More...
 
void destroy ()
 Destroy the underlying object (be careful here: things are not reference counted)! More...
 
void assign (_Segmentation *s, const std::string &n, const std::string &)
 
const char * name () const
 
const char * name () const
 
void assign (NamedObject *p, const std::string &n, const std::string &t)
 

Static Public Member Functions

static void bad_assignment (const std::type_info &from, const std::type_info &to)
 Helper routine called when unrelated types are assigned. More...
 

Public Attributes

T * m_element {nullptr}
 Single and only data member: Reference to the actual element. More...
 

Detailed Description

template<typename T>
class dd4hep::Handle< T >

Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects.

The Handle is the base class to access all objects in dd4hep. Objects, which consist ONLY of data, which are NEVER passed directly. They are ALWAYS passed using handles. Such handles are 'handy' ;-). Assignment is to and from different handles is possible using concrete type checking.

Real benefits can result from sophisticated handle subclasses, which can implement any desired user functionality with out compromising the object's data content. This leads to very flexible implementations, where the same data may be shared by many handle implementations providing different functionality to the clients.

In this sense, is the consequent use of handles to access data nothing else then the consequent application of component oriented programming using local objects from the heap.

Note: If you cannot live with this approach, it is better you get hands of this software package, because you will try to consequently fight the framework, which will frustrate you (and also me).

Author
M.Frank
Version
1.0

Definition at line 84 of file Handle.h.

Member Typedef Documentation

◆ Base

template<typename T >
typedef Handle<T> dd4hep::Handle< T >::Base

Self type: used by sub-classes.

Definition at line 90 of file Handle.h.

◆ Object

template<typename T >
typedef T dd4hep::Handle< T >::Object

Extern accessible definition of the contained element type.

Type definitions and class specific abbreviations and forward declarations

Definition at line 88 of file Handle.h.

Constructor & Destructor Documentation

◆ Handle() [1/6]

template<typename T >
dd4hep::Handle< T >::Handle ( )
default

Default constructor.

◆ Handle() [2/6]

template<typename T >
dd4hep::Handle< T >::Handle ( Handle< T > &&  element)
default

Copy constructor.

◆ Handle() [3/6]

template<typename T >
dd4hep::Handle< T >::Handle ( const Handle< T > &  element)
default

Copy constructor.

◆ Handle() [4/6]

template<typename T >
dd4hep::Handle< T >::Handle ( T *  element)
inline

Initializing constructor from pointer.

Definition at line 102 of file Handle.h.

◆ Handle() [5/6]

template<typename T >
template<typename Q >
dd4hep::Handle< T >::Handle ( Q *  element)
inline

Initializing constructor from unrelated pointer with type checking.

Definition at line 104 of file Handle.h.

◆ Handle() [6/6]

template<typename T >
template<typename Q >
dd4hep::Handle< T >::Handle ( const Handle< Q > &  element)
inline

Initializing constructor from unrelated handle with type checking.

Definition at line 108 of file Handle.h.

Member Function Documentation

◆ _ptr()

template<typename T >
template<typename Q >
Q* dd4hep::Handle< T >::_ptr ( ) const
inline

Access to an unrelated object type.

Definition at line 157 of file Handle.h.

◆ access()

template<typename T >
T* dd4hep::Handle< T >::access ( ) const

Checked object access. Throws invalid handle runtime exception if invalid handle.

Very compact way to check the validity of a handle with exception thrown.

◆ assign() [1/3]

void dd4hep::Handle< _Segmentation >::assign ( _Segmentation s,
const std::string &  n,
const std::string &   
)

Definition at line 383 of file Handle.cpp.

◆ assign() [2/3]

void dd4hep::Handle< NamedObject >::assign ( NamedObject p,
const std::string &  n,
const std::string &  t 
)

Definition at line 24 of file NamedObject.cpp.

◆ assign() [3/3]

template<typename T >
void dd4hep::Handle< T >::assign ( Object n,
const std::string &  nam,
const std::string &  title 
)

Assign a new named object. Note: object references must be managed by the user.

◆ bad_assignment()

template<typename T >
static void dd4hep::Handle< T >::bad_assignment ( const std::type_info &  from,
const std::type_info &  to 
)
static

Helper routine called when unrelated types are assigned.

◆ clear()

template<typename T >
Handle<T>& dd4hep::Handle< T >::clear ( )
inline

Release the object held by the handle.

Definition at line 136 of file Handle.h.

◆ data()

template<typename T >
template<typename Q >
Q* dd4hep::Handle< T >::data ( ) const
inline

Access to an unrelated object type.

Definition at line 161 of file Handle.h.

◆ destroy()

template<typename T >
void dd4hep::Handle< T >::destroy ( )

Destroy the underlying object (be careful here: things are not reference counted)!

◆ isValid()

template<typename T >
bool dd4hep::Handle< T >::isValid ( ) const
inline

Check the validity of the object held by the handle.

Definition at line 128 of file Handle.h.

◆ name() [1/3]

const char * dd4hep::Handle< NamedObject >::name ( ) const

Definition at line 20 of file NamedObject.cpp.

◆ name() [2/3]

template<typename T >
const char* dd4hep::Handle< T >::name ( ) const

Access the object name (or "" if not supported by the object)

◆ name() [3/3]

const char * dd4hep::Handle< _Segmentation >::name ( ) const

Definition at line 387 of file Handle.cpp.

◆ object()

template<typename T >
template<typename Q >
Q& dd4hep::Handle< T >::object ( ) const
inline

Access to an unrelated object type.

Definition at line 165 of file Handle.h.

◆ operator T&()

template<typename T >
dd4hep::Handle< T >::operator T& ( ) const
inline

Automatic type conversion to an object references.

Definition at line 145 of file Handle.h.

◆ operator!()

template<typename T >
bool dd4hep::Handle< T >::operator! ( ) const
inline

Check the validity of the object held by the handle.

Definition at line 132 of file Handle.h.

◆ operator*()

template<typename T >
T& dd4hep::Handle< T >::operator* ( ) const
inline

Access the held object using the * operator.

Definition at line 149 of file Handle.h.

◆ operator->()

template<typename T >
T* dd4hep::Handle< T >::operator-> ( ) const
inline

Access the held object using the -> operator.

Definition at line 141 of file Handle.h.

◆ operator<()

template<typename T >
bool dd4hep::Handle< T >::operator< ( const Handle< T > &  element) const
inline

Boolean operator < used for RB tree insertions.

Definition at line 120 of file Handle.h.

◆ operator=() [1/2]

template<typename T >
Handle<T>& dd4hep::Handle< T >::operator= ( const Handle< T > &  element)
default

Assignment copy operator.

◆ operator=() [2/2]

template<typename T >
Handle<T>& dd4hep::Handle< T >::operator= ( Handle< T > &&  element)
default

Assignment move operator.

◆ operator==()

template<typename T >
bool dd4hep::Handle< T >::operator== ( const Handle< T > &  element) const
inline

Boolean operator == used for RB tree insertions.

Definition at line 116 of file Handle.h.

◆ operator>()

template<typename T >
bool dd4hep::Handle< T >::operator> ( const Handle< T > &  element) const
inline

Boolean operator > used for RB tree insertions.

Definition at line 124 of file Handle.h.

◆ ptr()

template<typename T >
T* dd4hep::Handle< T >::ptr ( ) const
inline

Access to the held object.

Definition at line 153 of file Handle.h.

Member Data Documentation

◆ m_element

template<typename T >
T* dd4hep::Handle< T >::m_element {nullptr}

Single and only data member: Reference to the actual element.

Definition at line 93 of file Handle.h.


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