The Gaudi Framework  master (37c0b60a)
SmartRef< TYPE > Class Template Referencefinal

Kernel objects: SmartRef. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/SmartRef.h>

Collaboration diagram for SmartRef< TYPE >:

Public Types

enum  { VALID = StreamBuffer::VALID, INVALID = StreamBuffer::INVALID }
 
typedef TYPE entry_type
 Entry type definition. More...
 

Public Member Functions

 SmartRef (const TYPE *pObject=nullptr)
 Standard Constructor. More...
 
 SmartRef (const SmartRef &copy)
 Copy Constructor. More...
 
 SmartRef (long hint, long link, const TYPE *obj=nullptr)
 Constructor. More...
 
 SmartRef (const ContainedObject *pObj, long hint, long link, const TYPE *obj=nullptr)
 Constructor for references to contained objects passing environment. More...
 
 SmartRef (const DataObject *pObj, long hint, long link, const TYPE *obj=nullptr)
 Constructor for references to contained objects passing environment. More...
 
 SmartRef (const DataObject *pObj, long hint, const TYPE *obj=nullptr)
 Constructor for references to DataObjects passing environment. More...
 
bool shouldFollowLink (const DataObject *) const
 Check if link should be followed: link must be valid and object not yet loaded. More...
 
bool shouldFollowLink (const ContainedObject *) const
 Check if link should be followed: link must be valid and object not yet loaded. More...
 
long hintID () const
 Access hint id: More...
 
long linkID () const
 Access link id: More...
 
void set (DataObject *pObj, long hint_id, long link_id)
 Setup smart reference when reading. Must be allowed from external sources. More...
 
const std::type_infotype () const
 Access to embedded type. More...
 
TYPE * data ()
 Access to raw data pointer. More...
 
const TYPE * data () const
 
const TYPE * target () const
 Access to the object. More...
 
TYPE * target ()
 Access to the object. More...
 
const std::stringpath () const
 Return the path of the linked object inside the data store. More...
 
bool operator== (const SmartRef< TYPE > &c) const
 Equality operator. More...
 
bool operator!= (const SmartRef< TYPE > &c) const
 NON-Equality operator. More...
 
 operator bool () const
 explicit conversion to bool to check for object existence (will load object) More...
 
const SmartRef< TYPE > & _setEnvironment (const DataObject *pObj, const ContainedObject *pContd) const
 Set the environment (CONST) More...
 
SmartRef< TYPE > & _setEnvironment (const DataObject *pObj, const ContainedObject *pContd)
 Set the environment (CONST) More...
 
SmartRef< TYPE > & operator() (ContainedObject *pObj)
 operator(): assigns parent object for serialisation More...
 
const SmartRef< TYPE > & operator() (const ContainedObject *pObj) const
 operator() const: assigns parent object for serialisation More...
 
SmartRef< TYPE > & operator() (DataObject *pObj)
 operator(): assigns parent object for serialisation More...
 
const SmartRef< TYPE > & operator() (const DataObject *pObj) const
 operator() const: assigns parent object for serialisation More...
 
SmartRef< TYPE > & operator= (const SmartRef< TYPE > &c)
 Assignment. More...
 
SmartRef< TYPE > & operator= (const TYPE *pObject)
 Assignment. More...
 
TYPE & operator* ()
 Dereference operator. More...
 
const TYPE & operator* () const
 Dereference operator. More...
 
TYPE * operator-> ()
 Dereference operator. More...
 
const TYPE * operator-> () const
 Dereference operator to const object. More...
 
 operator const TYPE * () const
 Implicit type conversion to const object. More...
 
 operator TYPE * ()
 Implicit type conversion. More...
 
StreamBufferwriteRef (StreamBuffer &s) const
 Write the reference to the stream buffer (needed due to stupid G++ compiler) More...
 
StreamBufferreadRef (StreamBuffer &s)
 Read the reference from the stream buffer (needed due to stupid G++ compiler) More...
 

Private Attributes

SmartRefBase m_base
 
const TYPE * m_target = nullptr
 Pointer to target data object. More...
 

Friends

class SmartRefArray< TYPE >
 The container must be a friend. More...
 
class SmartRefList< TYPE >
 
class SmartRefMap< TYPE >
 
bool operator== (const SmartRef< TYPE > &ref, std::nullptr_t)
 
bool operator== (std::nullptr_t, const SmartRef< TYPE > &ref)
 Friend helper to check for object existence (will load object) More...
 
bool operator!= (const SmartRef< TYPE > &ref, std::nullptr_t)
 
bool operator!= (std::nullptr_t, const SmartRef< TYPE > &ref)
 Friend helper to check for object existence (will load object) More...
 
StreamBufferoperator<< (StreamBuffer &_s, const SmartRef< TYPE > &ptr)
 Output Streamer operator. More...
 
StreamBufferoperator>> (StreamBuffer &_s, SmartRef< TYPE > &ptr)
 Input Streamer operator. More...
 

Detailed Description

template<class TYPE>
class SmartRef< TYPE >

Kernel objects: SmartRef.

Description: The SmartRef class allows transparent handling of object links within the data store. Links are unloaded a priori and will only be loaded "on demand", i.e. when dereferenced.

SmartRefs should behave in the same way as normal pointers; The SmartRef object in fact is a smart pointer construct intercepting the dereference operators.

When loading, the executed code resides in the non templated base class. This ensures, that the templated code is minimized and code blow up is inhibited.

Using SmartRefs StreamBuffers are able to also save the references on data conversion requests.

Base Class: SmartRefBase

Dependencies:

History :

+---------+----------------------------------------------+--------+
|    Date |                 Comment                      | Who    |
+---------+----------------------------------------------+--------+
| 21/04/99| Initial version.                             | MF     |
| 16/01/04| Move base class into aggregation.            | MF     |
+---------+----------------------------------------------+--------+

Author: M.Frank Version: 1.0

Definition at line 76 of file SmartRef.h.

Member Typedef Documentation

◆ entry_type

template<class TYPE >
typedef TYPE SmartRef< TYPE >::entry_type

Entry type definition.

Definition at line 89 of file SmartRef.h.

Member Enumeration Documentation

◆ anonymous enum

template<class TYPE >
anonymous enum
Enumerator
VALID 
INVALID 

Definition at line 87 of file SmartRef.h.

Constructor & Destructor Documentation

◆ SmartRef() [1/6]

template<class TYPE >
SmartRef< TYPE >::SmartRef ( const TYPE *  pObject = nullptr)
inline

Standard Constructor.

Definition at line 92 of file SmartRef.h.

92  {
95  m_target = pObject;
96  _setEnvironment( nullptr, nullptr );
97  }

◆ SmartRef() [2/6]

template<class TYPE >
SmartRef< TYPE >::SmartRef ( const SmartRef< TYPE > &  copy)
inline

Copy Constructor.

Definition at line 99 of file SmartRef.h.

99  {
100  m_base.m_hintID = copy.m_base.m_hintID;
101  m_base.m_linkID = copy.m_base.m_linkID;
102  m_target = copy.m_target;
103  _setEnvironment( copy.m_base.m_data, copy.m_base.m_contd );
104  }

◆ SmartRef() [3/6]

template<class TYPE >
SmartRef< TYPE >::SmartRef ( long  hint,
long  link,
const TYPE *  obj = nullptr 
)
inline

Constructor.

Definition at line 106 of file SmartRef.h.

106  {
107  m_base.m_hintID = hint;
108  m_base.m_linkID = link;
109  m_target = obj;
110  _setEnvironment( nullptr, nullptr );
111  }

◆ SmartRef() [4/6]

template<class TYPE >
SmartRef< TYPE >::SmartRef ( const ContainedObject pObj,
long  hint,
long  link,
const TYPE *  obj = nullptr 
)
inline

Constructor for references to contained objects passing environment.

Definition at line 113 of file SmartRef.h.

113  {
114  m_base.m_hintID = hint;
115  m_base.m_linkID = link;
116  m_target = obj;
117  const DataObject* src = ( pObj ? pObj->parent() : nullptr );
118  _setEnvironment( src, pObj );
119  }

◆ SmartRef() [5/6]

template<class TYPE >
SmartRef< TYPE >::SmartRef ( const DataObject pObj,
long  hint,
long  link,
const TYPE *  obj = nullptr 
)
inline

Constructor for references to contained objects passing environment.

Definition at line 121 of file SmartRef.h.

121  {
122  m_base.m_hintID = hint;
123  m_base.m_linkID = link;
124  m_target = obj;
125  _setEnvironment( pObj, nullptr );
126  }

◆ SmartRef() [6/6]

template<class TYPE >
SmartRef< TYPE >::SmartRef ( const DataObject pObj,
long  hint,
const TYPE *  obj = nullptr 
)
inline

Constructor for references to DataObjects passing environment.

Definition at line 128 of file SmartRef.h.

128  {
129  m_base.m_hintID = hint;
131  m_target = obj;
132  _setEnvironment( pObj, nullptr );
133  }

Member Function Documentation

◆ _setEnvironment() [1/2]

template<class TYPE >
SmartRef<TYPE>& SmartRef< TYPE >::_setEnvironment ( const DataObject pObj,
const ContainedObject pContd 
)
inline

Set the environment (CONST)

Definition at line 194 of file SmartRef.h.

194  {
195  m_base.m_data = pObj;
196  m_base.m_contd = pContd;
198  return *this;
199  }

◆ _setEnvironment() [2/2]

template<class TYPE >
const SmartRef<TYPE>& SmartRef< TYPE >::_setEnvironment ( const DataObject pObj,
const ContainedObject pContd 
) const
inline

Set the environment (CONST)

Definition at line 187 of file SmartRef.h.

187  {
188  m_base.m_data = pObj;
189  m_base.m_contd = pContd;
191  return *this;
192  }

◆ data() [1/2]

template<class TYPE >
TYPE* SmartRef< TYPE >::data ( )
inline

Access to raw data pointer.

Definition at line 149 of file SmartRef.h.

149 { return const_cast<TYPE*>( m_target ); }

◆ data() [2/2]

template<class TYPE >
const TYPE* SmartRef< TYPE >::data ( ) const
inline

Definition at line 150 of file SmartRef.h.

150 { return m_target; }

◆ hintID()

template<class TYPE >
long SmartRef< TYPE >::hintID ( ) const
inline

Access hint id:

Definition at line 141 of file SmartRef.h.

141 { return m_base.m_hintID; }

◆ linkID()

template<class TYPE >
long SmartRef< TYPE >::linkID ( ) const
inline

Access link id:

Definition at line 143 of file SmartRef.h.

143 { return m_base.m_linkID; }

◆ operator bool()

template<class TYPE >
SmartRef< TYPE >::operator bool ( ) const
inlineexplicit

explicit conversion to bool to check for object existence (will load object)

Definition at line 184 of file SmartRef.h.

184 { return target() != nullptr; }

◆ operator const TYPE *()

template<class TYPE >
SmartRef< TYPE >::operator const TYPE * ( ) const
inline

Implicit type conversion to const object.

Definition at line 237 of file SmartRef.h.

237 { return SmartRef<TYPE>::target(); }

◆ operator TYPE *()

template<class TYPE >
SmartRef< TYPE >::operator TYPE * ( )
inline

Implicit type conversion.

Definition at line 239 of file SmartRef.h.

239 { return SmartRef<TYPE>::target(); }

◆ operator!=()

template<class TYPE >
bool SmartRef< TYPE >::operator!= ( const SmartRef< TYPE > &  c) const
inline

NON-Equality operator.

Definition at line 176 of file SmartRef.h.

176 { return !( this->operator==( c ) ); }

◆ operator()() [1/4]

template<class TYPE >
const SmartRef<TYPE>& SmartRef< TYPE >::operator() ( const ContainedObject pObj) const
inline

operator() const: assigns parent object for serialisation

Definition at line 206 of file SmartRef.h.

206  {
207  const DataObject* src = ( pObj ? pObj->parent() : nullptr );
208  return _setEnvironment( src, pObj );
209  }

◆ operator()() [2/4]

template<class TYPE >
const SmartRef<TYPE>& SmartRef< TYPE >::operator() ( const DataObject pObj) const
inline

operator() const: assigns parent object for serialisation

Definition at line 213 of file SmartRef.h.

213 { return _setEnvironment( pObj, nullptr ); }

◆ operator()() [3/4]

template<class TYPE >
SmartRef<TYPE>& SmartRef< TYPE >::operator() ( ContainedObject pObj)
inline

operator(): assigns parent object for serialisation

Definition at line 201 of file SmartRef.h.

201  {
202  const DataObject* src = ( pObj ? pObj->parent() : nullptr );
203  return _setEnvironment( src, pObj );
204  }

◆ operator()() [4/4]

template<class TYPE >
SmartRef<TYPE>& SmartRef< TYPE >::operator() ( DataObject pObj)
inline

operator(): assigns parent object for serialisation

Definition at line 211 of file SmartRef.h.

211 { return _setEnvironment( pObj, nullptr ); }

◆ operator*() [1/2]

template<class TYPE >
TYPE& SmartRef< TYPE >::operator* ( )
inline

Dereference operator.

Definition at line 229 of file SmartRef.h.

229 { return *SmartRef<TYPE>::target(); }

◆ operator*() [2/2]

template<class TYPE >
const TYPE& SmartRef< TYPE >::operator* ( ) const
inline

Dereference operator.

Definition at line 231 of file SmartRef.h.

231 { return *SmartRef<TYPE>::target(); }

◆ operator->() [1/2]

template<class TYPE >
TYPE* SmartRef< TYPE >::operator-> ( )
inline

Dereference operator.

Definition at line 233 of file SmartRef.h.

233 { return SmartRef<TYPE>::target(); }

◆ operator->() [2/2]

template<class TYPE >
const TYPE* SmartRef< TYPE >::operator-> ( ) const
inline

Dereference operator to const object.

Definition at line 235 of file SmartRef.h.

235 { return SmartRef<TYPE>::target(); }

◆ operator=() [1/2]

template<class TYPE >
SmartRef<TYPE>& SmartRef< TYPE >::operator= ( const SmartRef< TYPE > &  c)
inline

Assignment.

Definition at line 215 of file SmartRef.h.

215  {
216  m_target = c.m_target;
217  m_base.m_hintID = c.m_base.m_hintID;
218  m_base.m_linkID = c.m_base.m_linkID;
219  return _setEnvironment( c.m_base.m_data, c.m_base.m_contd );
220  }

◆ operator=() [2/2]

template<class TYPE >
SmartRef<TYPE>& SmartRef< TYPE >::operator= ( const TYPE *  pObject)
inline

Assignment.

Definition at line 222 of file SmartRef.h.

222  {
223  m_target = pObject;
226  return *this;
227  }

◆ operator==()

template<class TYPE >
bool SmartRef< TYPE >::operator== ( const SmartRef< TYPE > &  c) const
inline

Equality operator.

Definition at line 164 of file SmartRef.h.

164  {
165  if ( m_target && c.m_target ) return m_target == c.m_target;
166  if ( !m_target && !c.m_target ) return m_base.isEqual( m_target, c.m_base );
167  if ( m_target && !c.m_target ) return m_base.isEqualEx( m_target, c.m_base );
168  if ( !m_target && c.m_target ) return c.m_base.isEqualEx( c.m_target, m_base );
169  return false;
170  }

◆ path()

template<class TYPE >
const std::string& SmartRef< TYPE >::path ( ) const
inline

Return the path of the linked object inside the data store.

Definition at line 162 of file SmartRef.h.

162 { return m_base.path(); }

◆ readRef()

template<class TYPE >
StreamBuffer& SmartRef< TYPE >::readRef ( StreamBuffer s)
inline

Read the reference from the stream buffer (needed due to stupid G++ compiler)

Definition at line 246 of file SmartRef.h.

246  {
247  m_target = dynamic_cast<const TYPE*>( m_base.readObject( m_target, s ) );
248  return s;
249  }

◆ set()

template<class TYPE >
void SmartRef< TYPE >::set ( DataObject pObj,
long  hint_id,
long  link_id 
)
inline

Setup smart reference when reading. Must be allowed from external sources.

Definition at line 145 of file SmartRef.h.

145 { m_base.set( pObj, hint_id, link_id ); }

◆ shouldFollowLink() [1/2]

template<class TYPE >
bool SmartRef< TYPE >::shouldFollowLink ( const ContainedObject ) const
inline

Check if link should be followed: link must be valid and object not yet loaded.

Definition at line 137 of file SmartRef.h.

137  {
138  return !m_target && m_base.m_hintID != INVALID && m_base.m_linkID != INVALID;
139  }

◆ shouldFollowLink() [2/2]

template<class TYPE >
bool SmartRef< TYPE >::shouldFollowLink ( const DataObject ) const
inline

Check if link should be followed: link must be valid and object not yet loaded.

Definition at line 135 of file SmartRef.h.

135 { return !m_target && m_base.m_hintID != INVALID; }

◆ target() [1/2]

template<class TYPE >
TYPE* SmartRef< TYPE >::target ( )
inline

Access to the object.

Definition at line 157 of file SmartRef.h.

157  {
158  if ( !m_target ) { m_target = dynamic_cast<const TYPE*>( m_base.accessData( m_target ) ); }
159  return const_cast<TYPE*>( m_target );
160  }

◆ target() [2/2]

template<class TYPE >
const TYPE* SmartRef< TYPE >::target ( ) const
inline

Access to the object.

Definition at line 152 of file SmartRef.h.

152  {
153  if ( !m_target ) { m_target = dynamic_cast<const TYPE*>( m_base.accessData( m_target ) ); }
154  return m_target;
155  }

◆ type()

template<class TYPE >
const std::type_info* SmartRef< TYPE >::type ( ) const
inline

Access to embedded type.

Definition at line 147 of file SmartRef.h.

147 { return &typeid( TYPE ); }

◆ writeRef()

template<class TYPE >
StreamBuffer& SmartRef< TYPE >::writeRef ( StreamBuffer s) const
inline

Write the reference to the stream buffer (needed due to stupid G++ compiler)

Definition at line 241 of file SmartRef.h.

241  {
243  return s;
244  }

Friends And Related Function Documentation

◆ operator!= [1/2]

template<class TYPE >
bool operator!= ( const SmartRef< TYPE > &  ref,
std::nullptr_t   
)
friend

Definition at line 178 of file SmartRef.h.

178 { return ref.target() != nullptr; }

◆ operator!= [2/2]

template<class TYPE >
bool operator!= ( std::nullptr_t  ,
const SmartRef< TYPE > &  ref 
)
friend

Friend helper to check for object existence (will load object)

Definition at line 181 of file SmartRef.h.

181 { return ref.target() != nullptr; }

◆ operator<<

template<class TYPE >
StreamBuffer& operator<< ( StreamBuffer _s,
const SmartRef< TYPE > &  ptr 
)
friend

Output Streamer operator.

Definition at line 252 of file SmartRef.h.

252 { return ptr.writeRef( _s ); }

◆ operator== [1/2]

template<class TYPE >
bool operator== ( const SmartRef< TYPE > &  ref,
std::nullptr_t   
)
friend

Definition at line 171 of file SmartRef.h.

171 { return ref.target() == nullptr; }

◆ operator== [2/2]

template<class TYPE >
bool operator== ( std::nullptr_t  ,
const SmartRef< TYPE > &  ref 
)
friend

Friend helper to check for object existence (will load object)

Definition at line 174 of file SmartRef.h.

174 { return ref.target() == nullptr; }

◆ operator>>

template<class TYPE >
StreamBuffer& operator>> ( StreamBuffer _s,
SmartRef< TYPE > &  ptr 
)
friend

Input Streamer operator.

Definition at line 255 of file SmartRef.h.

255 { return ptr.readRef( _s ); }

◆ SmartRefArray< TYPE >

template<class TYPE >
friend class SmartRefArray< TYPE >
friend

The container must be a friend.

Definition at line 1 of file SmartRef.h.

◆ SmartRefList< TYPE >

template<class TYPE >
friend class SmartRefList< TYPE >
friend

Definition at line 1 of file SmartRef.h.

◆ SmartRefMap< TYPE >

template<class TYPE >
friend class SmartRefMap< TYPE >
friend

Definition at line 1 of file SmartRef.h.

Member Data Documentation

◆ m_base

template<class TYPE >
SmartRefBase SmartRef< TYPE >::m_base
private

Definition at line 82 of file SmartRef.h.

◆ m_target

template<class TYPE >
const TYPE* SmartRef< TYPE >::m_target = nullptr
mutableprivate

Pointer to target data object.

Definition at line 84 of file SmartRef.h.


The documentation for this class was generated from the following file:
SmartRef::m_base
SmartRefBase m_base
Definition: SmartRef.h:82
SmartRef::m_target
const TYPE * m_target
Pointer to target data object.
Definition: SmartRef.h:84
SmartRef::VALID
@ VALID
Definition: SmartRef.h:87
gaudirun.s
string s
Definition: gaudirun.py:346
SmartRef::operator==
bool operator==(const SmartRef< TYPE > &c) const
Equality operator.
Definition: SmartRef.h:164
gaudirun.c
c
Definition: gaudirun.py:525
SmartRefBase::m_linkID
long m_linkID
Object data: ID of the object within the identifiable container (if any)
Definition: SmartRefBase.h:62
SmartRef::readRef
StreamBuffer & readRef(StreamBuffer &s)
Read the reference from the stream buffer (needed due to stupid G++ compiler)
Definition: SmartRef.h:246
SmartRefBase::readObject
DataObject * readObject(const DataObject *, StreamBuffer &s) const
Input streamer for DataObject like references.
Definition: SmartRefBase.h:96
SmartRefBase::writeObject
void writeObject(const DataObject *pObject, StreamBuffer &s) const
Output streamer for DataObject like references.
Definition: SmartRefBase.h:90
SmartRef::INVALID
@ INVALID
Definition: SmartRef.h:87
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:87
SmartRefBase::path
const std::string & path() const
Shortcut to access the path to the linked object.
Definition: SmartRefBase.cpp:93
std::copy
T copy(T... args)
SmartRefBase::m_data
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
Definition: SmartRefBase.h:64
SmartRefBase::set
void set(DataObject *pObj, long hint_id, long link_id)
Setup smart reference when reading. Must be allowed from external sources.
Definition: SmartRefBase.cpp:36
SmartRefBase::m_hintID
long m_hintID
Object data: ID of the link hint to the identifiable object.
Definition: SmartRefBase.h:60
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:63
SmartRefBase::setObjectType
void setObjectType(const ContainedObject *) const
Definition: SmartRefBase.h:107
SmartRef::_setEnvironment
const SmartRef< TYPE > & _setEnvironment(const DataObject *pObj, const ContainedObject *pContd) const
Set the environment (CONST)
Definition: SmartRef.h:187
SmartRefBase::m_contd
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Definition: SmartRefBase.h:66
StreamBuffer::VALID
@ VALID
Definition: StreamBuffer.h:121
DataObject
Definition: DataObject.h:36
SmartRefBase::accessData
const ContainedObject * accessData(const ContainedObject *typ) const
Load on demand of ContainedObject like references.
Definition: SmartRefBase.cpp:43
SmartRef::writeRef
StreamBuffer & writeRef(StreamBuffer &s) const
Write the reference to the stream buffer (needed due to stupid G++ compiler)
Definition: SmartRef.h:241
compareRootHistos.ref
ref
Definition: compareRootHistos.py:27
SmartRefBase::isEqualEx
bool isEqualEx(const DataObject *pObj, const SmartRefBase &c) const
Extended equality check.
Definition: SmartRefBase.cpp:71
SmartRef::data
TYPE * data()
Access to raw data pointer.
Definition: SmartRef.h:149
SmartRefBase::isEqual
bool isEqual(const ContainedObject *, const SmartRefBase &c) const
Equality operator for ContainedObject like references.
Definition: SmartRefBase.h:82
SmartRef::target
const TYPE * target() const
Access to the object.
Definition: SmartRef.h:152
StreamBuffer::INVALID
@ INVALID
Definition: StreamBuffer.h:121