| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

SmartRef< TYPE > Class Template Reference

Kernel objects: SmartRef. More...

#include <SmartRef.h>

Inheritance diagram for SmartRef< TYPE >:

[legend]
Collaboration diagram for SmartRef< TYPE >:
[legend]
List of all members.

Public Types

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

Public Member Functions

 SmartRef ()
 Standard Constructor.
 SmartRef (TYPE *pObject)
 Standard Constructor with initialisation.
 SmartRef (const TYPE *pObject)
 Standard Constructor with initialisation from const object.
 SmartRef (const SmartRef &copy)
 Copy Constructor.
 SmartRef (long hint, long link, TYPE *obj=0)
 Constructor.
 SmartRef (const ContainedObject *pObj, long hint, long link, TYPE *obj=0)
 Constructor for references to contained objects passing environment.
 SmartRef (const DataObject *pObj, long hint, long link, TYPE *obj=0)
 Constructor for references to contained objects passing environment.
 SmartRef (const DataObject *pObj, long hint, TYPE *obj=0)
 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!= (const SmartRef< TYPE > &c) const
 NON-Equality operator.
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= (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).

Protected Attributes

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

Friends

class SmartRefArray< TYPE >
 The container must be a friend.
class SmartRefList< TYPE >
class SmartRefMap< TYPE >
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 62 of file SmartRef.h.


Member Typedef Documentation

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

Entry type definition.

Definition at line 71 of file SmartRef.h.


Member Enumeration Documentation

template<class TYPE>
anonymous enum

Enumerator:
VALID 
INVALID 

Definition at line 69 of file SmartRef.h.


Constructor & Destructor Documentation

template<class TYPE>
SmartRef< TYPE >::SmartRef (  )  [inline]

Standard Constructor.

Definition at line 79 of file SmartRef.h.

00079               {
00080     m_base.m_hintID = INVALID; 
00081     m_base.m_linkID = INVALID;
00082     m_target = 0;
00083     _setEnvironment(0, 0);
00084   }

template<class TYPE>
SmartRef< TYPE >::SmartRef ( TYPE *  pObject  )  [inline]

Standard Constructor with initialisation.

Definition at line 86 of file SmartRef.h.

00086                            {
00087     m_base.m_hintID = INVALID; 
00088     m_base.m_linkID = INVALID;
00089     m_target = pObject;
00090     _setEnvironment(0, 0);
00091   }

template<class TYPE>
SmartRef< TYPE >::SmartRef ( const TYPE *  pObject  )  [inline]

Standard Constructor with initialisation from const object.

Definition at line 93 of file SmartRef.h.

00093                                  {
00094     m_base.m_hintID = INVALID; 
00095     m_base.m_linkID = INVALID;
00096     m_target = const_cast<TYPE*>(pObject);
00097     _setEnvironment(0, 0);
00098   }

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

Copy Constructor.

Definition at line 100 of file SmartRef.h.

00100                                    {
00101     m_base.m_hintID = copy.m_base.m_hintID;
00102     m_base.m_linkID = copy.m_base.m_linkID;
00103     m_target = copy.m_target;
00104     _setEnvironment(copy.m_base.m_data, copy.m_base.m_contd);
00105   }

template<class TYPE>
SmartRef< TYPE >::SmartRef ( long  hint,
long  link,
TYPE *  obj = 0 
) [inline]

Constructor.

Definition at line 107 of file SmartRef.h.

00107                                                   {
00108     m_base.m_hintID = hint;
00109     m_base.m_linkID = link;
00110     m_target = obj;
00111     _setEnvironment(0, 0);
00112   }

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

Constructor for references to contained objects passing environment.

Definition at line 114 of file SmartRef.h.

00114                                                                                {
00115     m_base.m_hintID = hint;
00116     m_base.m_linkID = link;
00117     m_target = obj;
00118     const DataObject* src = (0==pObj) ? 0 : pObj->parent();
00119     _setEnvironment(src, pObj);
00120   }

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

Constructor for references to contained objects passing environment.

Definition at line 122 of file SmartRef.h.

00122                                                                           {
00123     m_base.m_hintID = hint;
00124     m_base.m_linkID = link;
00125     m_target = obj;
00126     _setEnvironment(pObj, 0);
00127   }

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

Constructor for references to DataObjects passing environment.

Definition at line 129 of file SmartRef.h.

00129                                                                {
00130     m_base.m_hintID = hint;
00131     m_base.m_linkID = INVALID;
00132     m_target = obj;
00133     _setEnvironment(pObj, 0);
00134   }


Member Function Documentation

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

00139                                                              {
00140     return (0 == m_target && m_base.m_hintID != INVALID );
00141   }

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

00143                                                                   {
00144     return (0 == m_target && m_base.m_hintID != INVALID && m_base.m_linkID != INVALID );
00145   }

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

Access hint id:.

Definition at line 147 of file SmartRef.h.

00147                           {
00148     return m_base.m_hintID;
00149   }

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

Access link id:.

Definition at line 151 of file SmartRef.h.

00151                           {
00152     return m_base.m_linkID;
00153   }

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

00155                                                          {
00156      m_base.set(pObj, hint_id, link_id);
00157   }

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

Access to embedded type.

Definition at line 159 of file SmartRef.h.

00159                                       {
00160     return &typeid(TYPE);
00161   }

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

Access to raw data pointer.

Definition at line 163 of file SmartRef.h.

00163                   {
00164     return const_cast<TYPE*>(m_target);
00165   }

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

Definition at line 166 of file SmartRef.h.

00166                               {
00167     return m_target;
00168   }

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

Access to the object.

Definition at line 286 of file SmartRef.h.

00286                                            {
00287   if ( 0 == m_target )    {
00288     m_target = dynamic_cast<const TYPE*>(m_base.accessData(m_target));
00289   }
00290   return m_target;
00291 }

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

Access to the object.

Definition at line 277 of file SmartRef.h.

00277                               {
00278   if ( 0 == m_target )    {
00279     m_target = dynamic_cast<const TYPE*>(m_base.accessData(m_target));
00280   }
00281   return const_cast<TYPE*>(m_target);
00282 }

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

00174 { return m_base.path(); }

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

Equality operator.

Definition at line 176 of file SmartRef.h.

00176                                                      {
00177     if ( 0 != m_target && 0 != c.m_target )   {
00178       return m_target == c.m_target;
00179     }
00180     else if ( 0 == m_target && 0 == c.m_target )    {
00181       return m_base.isEqual(m_target,c.m_base);
00182     }
00183     else if ( 0 != m_target && 0 == c.m_target )  {
00184       return m_base.isEqualEx(m_target, c.m_base);
00185     }
00186     else if ( 0 == m_target && 0 != c.m_target )  {
00187       return c.m_base.isEqualEx(c.m_target, m_base);
00188     }
00189     return false;
00190   }

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

NON-Equality operator.

Definition at line 192 of file SmartRef.h.

00192                                                      {
00193     return !(this->operator==(c));
00194   }

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

Set the environment (CONST).

Definition at line 196 of file SmartRef.h.

00196                                                                                                         {
00197     m_base.m_data  = pObj;
00198     m_base.m_contd = pContd;
00199     m_base.setObjectType(data());
00200     return *this;
00201   }

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

Set the environment (CONST).

Definition at line 203 of file SmartRef.h.

00203                                                                                             {
00204     m_base.m_data  = pObj;
00205     m_base.m_contd = pContd;
00206     m_base.setObjectType(data());
00207     return *this;
00208   }

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

operator(): assigns parent object for serialisation

Definition at line 210 of file SmartRef.h.

00210                                                         {
00211     const DataObject* src = (0==pObj) ? 0 : pObj->parent();
00212     return _setEnvironment(src, pObj);
00213   }

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

operator() const: assigns parent object for serialisation

Definition at line 215 of file SmartRef.h.

00215                                                                          {
00216     const DataObject* src = (0==pObj) ? 0 : pObj->parent();
00217     return _setEnvironment(src, pObj);
00218   }

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

operator(): assigns parent object for serialisation

Definition at line 220 of file SmartRef.h.

00220                                                    {
00221     return _setEnvironment(pObj,0);
00222   }

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

operator() const: assigns parent object for serialisation

Definition at line 224 of file SmartRef.h.

00224                                                                     {
00225     return _setEnvironment(pObj,0);
00226   }

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

Assignment.

Definition at line 228 of file SmartRef.h.

00228                                                       {
00229     m_target = c.m_target;
00230     m_base.m_hintID = c.m_base.m_hintID;
00231     m_base.m_linkID = c.m_base.m_linkID;
00232     return _setEnvironment(c.m_base.m_data, c.m_base.m_contd);  }

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

Assignment.

Definition at line 234 of file SmartRef.h.

00234                                              {  
00235     m_target = pObject;    
00236     m_base.m_hintID = INVALID;
00237     m_base.m_linkID = INVALID;
00238     return *this;  
00239   }

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

Dereference operator.

Definition at line 241 of file SmartRef.h.

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

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

Dereference operator.

Definition at line 243 of file SmartRef.h.

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

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

Dereference operator.

Definition at line 245 of file SmartRef.h.

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

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

Dereference operator to const object.

Definition at line 247 of file SmartRef.h.

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

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

Implicit type conversion to const object.

Definition at line 249 of file SmartRef.h.

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

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

Implicit type conversion.

Definition at line 251 of file SmartRef.h.

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

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

00295                                                                   {
00296   m_base.writeObject(m_target, s);
00297   return s;
00298 }

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

00302                                                         {
00303   m_target = dynamic_cast<TYPE*>( m_base.readObject(m_target, s) );
00304   return s;
00305 }


Friends And Related Function Documentation

template<class TYPE>
friend class SmartRefArray< TYPE > [friend]

The container must be a friend.

Definition at line 64 of file SmartRef.h.

template<class TYPE>
friend class SmartRefList< TYPE > [friend]

Definition at line 65 of file SmartRef.h.

template<class TYPE>
friend class SmartRefMap< TYPE > [friend]

Definition at line 66 of file SmartRef.h.

template<class TYPE>
StreamBuffer& operator<< ( StreamBuffer s,
const SmartRef< TYPE > &  ptr 
) [friend]

Output Streamer operator.

Definition at line 257 of file SmartRef.h.

00257                                                                                 {
00258     return ptr.writeRef(s);
00259   }

template<class TYPE>
StreamBuffer& operator>> ( StreamBuffer s,
SmartRef< TYPE > &  ptr 
) [friend]

Input Streamer operator.

Definition at line 261 of file SmartRef.h.

00261                                                                             {
00262     return ptr.readRef(s);
00263   }


Member Data Documentation

template<class TYPE>
SmartRefBase SmartRef< TYPE >::m_base [protected]

Definition at line 73 of file SmartRef.h.

template<class TYPE>
const TYPE* SmartRef< TYPE >::m_target [mutable, protected]

Pointer to target data object.

Definition at line 75 of file SmartRef.h.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:57:14 2011 for GaudiKernel by doxygen 1.4.7