The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
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.
 

Public Member Functions

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

Private Attributes

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

Friends

class SmartRefArray< TYPE >
 The container must be a friend.
 
class SmartRefList< TYPE >
 
class SmartRefMap< TYPE >
 
bool operator== (SmartRef< TYPE > &lhs, TYPE *rhs)
 
bool operator== (const SmartRef< TYPE > &lhs, const TYPE *rhs)
 
StreamBufferoperator<< (StreamBuffer &_s, const SmartRef< TYPE > &ptr)
 Output Streamer operator.
 
StreamBufferoperator>> (StreamBuffer &_s, SmartRef< TYPE > &ptr)
 Input Streamer operator.
 

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 64 of file SmartRef.h.

Member Typedef Documentation

◆ entry_type

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

Entry type definition.

Definition at line 77 of file SmartRef.h.

Member Enumeration Documentation

◆ anonymous enum

template<class TYPE>
anonymous enum
Enumerator
VALID 
INVALID 

Definition at line 75 of file SmartRef.h.

Kernel objects: SmartRef.
Definition SmartRef.h:64
@ INVALID
Definition SmartRef.h:75

Constructor & Destructor Documentation

◆ SmartRef() [1/6]

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

Standard Constructor.

Definition at line 80 of file SmartRef.h.

80 {
81 m_base.m_hintID = INVALID;
82 m_base.m_linkID = INVALID;
84 _setEnvironment( nullptr, nullptr );
85 }
SmartRefBase m_base
Definition SmartRef.h:70
const TYPE * m_target
Pointer to target data object.
Definition SmartRef.h:72
const SmartRef< TYPE > & _setEnvironment(const DataObject *pObj, const ContainedObject *pContd) const
Set the environment (CONST)
Definition SmartRef.h:168

◆ SmartRef() [2/6]

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

Copy Constructor.

Definition at line 87 of file SmartRef.h.

87 {
88 m_base.m_hintID = copy.m_base.m_hintID;
89 m_base.m_linkID = copy.m_base.m_linkID;
92 }
long m_linkID
Object data: ID of the object within the identifiable container (if any)
long m_hintID
Object data: ID of the link hint to the identifiable object.
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.

◆ SmartRef() [3/6]

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

Constructor.

Definition at line 94 of file SmartRef.h.

94 {
95 m_base.m_hintID = hint;
96 m_base.m_linkID = link;
97 m_target = obj;
98 _setEnvironment( nullptr, nullptr );
99 }

◆ 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 101 of file SmartRef.h.

101 {
102 m_base.m_hintID = hint;
103 m_base.m_linkID = link;
104 m_target = obj;
105 const DataObject* src = ( pObj ? pObj->parent() : nullptr );
107 }

◆ 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 109 of file SmartRef.h.

109 {
110 m_base.m_hintID = hint;
111 m_base.m_linkID = link;
112 m_target = obj;
113 _setEnvironment( pObj, nullptr );
114 }

◆ 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 116 of file SmartRef.h.

116 {
117 m_base.m_hintID = hint;
118 m_base.m_linkID = INVALID;
119 m_target = obj;
120 _setEnvironment( pObj, nullptr );
121 }

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 175 of file SmartRef.h.

175 {
176 m_base.m_data = pObj;
177 m_base.m_contd = pContd;
178 m_base.setObjectType( data() );
179 return *this;
180 }
TYPE * data()
Access to raw data pointer.
Definition SmartRef.h:137

◆ _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 168 of file SmartRef.h.

168 {
169 m_base.m_data = pObj;
170 m_base.m_contd = pContd;
171 m_base.setObjectType( data() );
172 return *this;
173 }

◆ data() [1/2]

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

Access to raw data pointer.

Definition at line 137 of file SmartRef.h.

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

◆ data() [2/2]

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

Definition at line 138 of file SmartRef.h.

138{ return m_target; }

◆ hintID()

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

Access hint id:

Definition at line 129 of file SmartRef.h.

129{ return m_base.m_hintID; }

◆ linkID()

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

Access link id:

Definition at line 131 of file SmartRef.h.

131{ 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 165 of file SmartRef.h.

165{ return target() != nullptr; }
const TYPE * target() const
Access to the object.
Definition SmartRef.h:140

◆ operator const TYPE *()

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

Implicit type conversion to const object.

Definition at line 218 of file SmartRef.h.

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

◆ operator TYPE *()

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

Implicit type conversion.

Definition at line 220 of file SmartRef.h.

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

◆ 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 187 of file SmartRef.h.

187 {
188 const DataObject* src = ( pObj ? pObj->parent() : nullptr );
189 return _setEnvironment( src, pObj );
190 }

◆ 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 194 of file SmartRef.h.

194{ 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 182 of file SmartRef.h.

182 {
183 const DataObject* src = ( pObj ? pObj->parent() : nullptr );
184 return _setEnvironment( src, pObj );
185 }

◆ operator()() [4/4]

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

operator(): assigns parent object for serialisation

Definition at line 192 of file SmartRef.h.

192{ return _setEnvironment( pObj, nullptr ); }

◆ operator*() [1/2]

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

Dereference operator.

Definition at line 210 of file SmartRef.h.

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

◆ operator*() [2/2]

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

Dereference operator.

Definition at line 212 of file SmartRef.h.

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

◆ operator->() [1/2]

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

Dereference operator.

Definition at line 214 of file SmartRef.h.

214{ 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 216 of file SmartRef.h.

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

◆ operator=() [1/2]

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

Assignment.

Definition at line 196 of file SmartRef.h.

196 {
198 m_base.m_hintID = c.m_base.m_hintID;
199 m_base.m_linkID = c.m_base.m_linkID;
201 }

◆ operator=() [2/2]

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

Assignment.

Definition at line 203 of file SmartRef.h.

203 {
205 m_base.m_hintID = INVALID;
206 m_base.m_linkID = INVALID;
207 return *this;
208 }

◆ operator==() [1/2]

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

Equality operator.

Definition at line 152 of file SmartRef.h.

152 {
153 if ( m_target && c.m_target ) return m_target == c.m_target;
154 if ( !m_target && !c.m_target ) return m_base.isEqual( m_target, c.m_base );
155 if ( m_target && !c.m_target ) return m_base.isEqualEx( m_target, c.m_base );
156 if ( !m_target && c.m_target ) return c.m_base.isEqualEx( c.m_target, m_base );
157 return false;
158 }
bool isEqualEx(const DataObject *pObj, const SmartRefBase &c) const
Extended equality check.

◆ operator==() [2/2]

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

Definition at line 159 of file SmartRef.h.

159{ return std::as_const( *this ) == std::as_const( rhs ); }

◆ 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 150 of file SmartRef.h.

150{ 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 227 of file SmartRef.h.

227 {
228 m_target = dynamic_cast<const TYPE*>( m_base.readObject( m_target, s ) );
229 return s;
230 }

◆ 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 133 of file SmartRef.h.

133{ 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 125 of file SmartRef.h.

125 {
126 return !m_target && m_base.m_hintID != INVALID && m_base.m_linkID != INVALID;
127 }

◆ 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 123 of file SmartRef.h.

123{ 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 145 of file SmartRef.h.

145 {
146 if ( !m_target ) { m_target = dynamic_cast<const TYPE*>( m_base.accessData( m_target ) ); }
147 return const_cast<TYPE*>( m_target );
148 }

◆ target() [2/2]

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

Access to the object.

Definition at line 140 of file SmartRef.h.

140 {
141 if ( !m_target ) { m_target = dynamic_cast<const TYPE*>( m_base.accessData( m_target ) ); }
142 return m_target;
143 }

◆ type()

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

Access to embedded type.

Definition at line 135 of file SmartRef.h.

135{ 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 222 of file SmartRef.h.

222 {
223 m_base.writeObject( m_target, s );
224 return s;
225 }

Friends And Related Symbol Documentation

◆ operator<<

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

Output Streamer operator.

Definition at line 233 of file SmartRef.h.

233{ return ptr.writeRef( _s ); }
StreamBuffer & writeRef(StreamBuffer &s) const
Write the reference to the stream buffer (needed due to stupid G++ compiler)
Definition SmartRef.h:222

◆ operator== [1/2]

template<class TYPE>
bool operator== ( const SmartRef< TYPE > & lhs,
const TYPE * rhs )
friend

Definition at line 162 of file SmartRef.h.

162{ return lhs.target() == rhs; }

◆ operator== [2/2]

template<class TYPE>
bool operator== ( SmartRef< TYPE > & lhs,
TYPE * rhs )
friend

Definition at line 161 of file SmartRef.h.

161{ return lhs.target() == rhs; }

◆ operator>>

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

Input Streamer operator.

Definition at line 236 of file SmartRef.h.

236{ return ptr.readRef( _s ); }
StreamBuffer & readRef(StreamBuffer &s)
Read the reference from the stream buffer (needed due to stupid G++ compiler)
Definition SmartRef.h:227

◆ SmartRefArray< TYPE >

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

The container must be a friend.

Definition at line 64 of file SmartRef.h.

◆ SmartRefList< TYPE >

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

Definition at line 64 of file SmartRef.h.

◆ SmartRefMap< TYPE >

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

Definition at line 64 of file SmartRef.h.

Member Data Documentation

◆ m_base

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

Definition at line 70 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 72 of file SmartRef.h.


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