| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# SmartRef< TYPE > Class Template Reference

`#include <SmartRef.h>`

Collaboration diagram for SmartRef< TYPE >:

[legend]
List of all members.

## 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:

- Base class: GaudiKernel/SmartRefBase.h

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

## Public Types
enum | { VALID = StreamBuffer::VALID, INVALID = StreamBuffer::INVALID }
typedef TYPE | entry_type
| Entry type definition.
## 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.
StreamBuffer & | writeRef (StreamBuffer &s) const
| Write the reference to the stream buffer (needed due to stupid G++ compiler).
StreamBuffer & | readRef (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 >
StreamBuffer & | operator<< (StreamBuffer &s, const SmartRef< TYPE > &ptr)
| Output Streamer operator.
StreamBuffer & | operator>> (StreamBuffer &s, SmartRef< TYPE > &ptr)
| Input Streamer operator.

## Member Typedef Documentation

template<class TYPE>

typedef TYPE SmartRef< TYPE >::entry_type

Entry type definition.

Definition at line 69 of file SmartRef.h.

## Member Enumeration Documentation

template<class TYPE>

anonymous enum

Enumerator:

  VALID |
  INVALID |

Definition at line 67 of file SmartRef.h.

    00067 { VALID = StreamBuffer::VALID, INVALID = StreamBuffer::INVALID };

## Constructor & Destructor Documentation

template<class TYPE>

SmartRef< TYPE >::SmartRef | ( |  | ) | `[inline]`

Standard Constructor.

Definition at line 77 of file SmartRef.h.

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

template<class TYPE>

SmartRef< TYPE >::SmartRef | ( | TYPE * | pObject | ) | `[inline]`

Standard Constructor with initialisation.

Definition at line 84 of file SmartRef.h.

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

template<class TYPE>

SmartRef< TYPE >::SmartRef | ( | const TYPE * | pObject | ) | `[inline]`

Standard Constructor with initialisation from const object.

Definition at line 91 of file SmartRef.h.

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

template<class TYPE>

SmartRef< TYPE >::SmartRef | ( | const SmartRef< TYPE > & | copy | ) | `[inline]`

Copy Constructor.

Definition at line 98 of file SmartRef.h.

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

template<class TYPE>

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

Constructor.

Definition at line 105 of file SmartRef.h.

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

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

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

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

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

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

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

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

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

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

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

template<class TYPE>

long SmartRef< TYPE >::hintID | ( |  | ) | const`[inline]`

Access hint id:.

Definition at line 145 of file SmartRef.h.

Referenced by RefTable1to1< FROM, TO >::insert(), and PoolDbIOHandler< T >::put().

    00145                           {
    00146     return m_base.m_hintID;
    00147   }

template<class TYPE>

long SmartRef< TYPE >::linkID | ( |  | ) | const`[inline]`

Access link id:.

Definition at line 149 of file SmartRef.h.

Referenced by PoolDbIOHandler< T >::put().

    00149                           {
    00150     return m_base.m_linkID;
    00151   }

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

    00153                                                          {
    00154      m_base.set(pObj, hint_id, link_id);
    00155   }

template<class TYPE>

const std::type_info* SmartRef< TYPE >::type | ( |  | ) | const`[inline]`

Access to embedded type.

Definition at line 157 of file SmartRef.h.

    00157                                       {
    00158     return &typeid(TYPE);
    00159   }

template<class TYPE>

TYPE* SmartRef< TYPE >::data | ( |  | ) | `[inline]`

Access to raw data pointer.

Definition at line 161 of file SmartRef.h.

Referenced by SmartRef< KeyType >::_setEnvironment(), RefTable1to1< FROM, TO >::insert(), and PoolDbIOHandler< T >::put().

    00161                   {
    00162     return const_cast<TYPE*>(m_target);
    00163   }

template<class TYPE>

const TYPE* SmartRef< TYPE >::data | ( |  | ) | const`[inline]`

Definition at line 164 of file SmartRef.h.

    00164                               {
    00165     return m_target;
    00166   }

template<class TYPE>

const TYPE * SmartRef< TYPE >::target | ( |  | ) | const`[inline]`

Access to the object.

Definition at line 284 of file SmartRef.h.

References SmartRefBase::accessData(), SmartRef< TYPE >::m_base, and SmartRef< TYPE >::m_target.

Referenced by RefTable1to1< FROM, TO >::isReferenced(), SmartRef< KeyType >::operator *(), SmartRef< TYPE >::operator const TYPE *(), SmartRef< TYPE >::operator TYPE *(), and SmartRef< KeyType >::operator->().

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

template<class TYPE>

TYPE * SmartRef< TYPE >::target | ( |  | ) | `[inline]`

Access to the object.

Definition at line 275 of file SmartRef.h.

References SmartRefBase::accessData(), SmartRef< TYPE >::m_base, and SmartRef< TYPE >::m_target.

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

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

    00172 { return m_base.path(); }

template<class TYPE>

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

Equality operator.

Definition at line 174 of file SmartRef.h.

Referenced by SmartRef< KeyType >::operator!=().

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

template<class TYPE>

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

NON-Equality operator.

Definition at line 190 of file SmartRef.h.

    00190                                                      {
    00191     return !(this->operator==(c));
    00192   }

template<class TYPE>

const SmartRef<TYPE>& SmartRef< TYPE >::_setEnvironment | ( | const DataObject * | pObj,
|  | const ContainedObject * | pContd |
| ) |  |  | const`[inline]`

Set the environment (CONST).

Definition at line 194 of file SmartRef.h.

Referenced by SmartRef< KeyType >::operator()(), SmartRef< KeyType >::operator=(), SmartRefVector< TYPE >::readRefs(), and SmartRef< KeyType >::SmartRef().

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

template<class TYPE>

SmartRef<TYPE>& SmartRef< TYPE >::_setEnvironment | ( | const DataObject * | pObj,
|  | const ContainedObject * | pContd |
| ) |  |  | `[inline]`

Set the environment (CONST).

Definition at line 201 of file SmartRef.h.

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

template<class TYPE>

SmartRef<TYPE>& SmartRef< TYPE >::operator() | ( | ContainedObject * | pObj | ) | `[inline]`

operator(): assigns parent object for serialisation

Definition at line 208 of file SmartRef.h.

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

template<class TYPE>

const SmartRef<TYPE>& SmartRef< TYPE >::operator() | ( | const ContainedObject * | pObj | ) | const`[inline]`

operator() const: assigns parent object for serialisation

Definition at line 213 of file SmartRef.h.

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

template<class TYPE>

SmartRef<TYPE>& SmartRef< TYPE >::operator() | ( | DataObject * | pObj | ) | `[inline]`

operator(): assigns parent object for serialisation

Definition at line 218 of file SmartRef.h.

    00218                                                    {
    00219     return _setEnvironment(pObj,0);
    00220   }

template<class TYPE>

const SmartRef<TYPE>& SmartRef< TYPE >::operator() | ( | const DataObject * | pObj | ) | const`[inline]`

operator() const: assigns parent object for serialisation

Definition at line 222 of file SmartRef.h.

    00222                                                                     {
    00223     return _setEnvironment(pObj,0);
    00224   }

template<class TYPE>

SmartRef<TYPE>& SmartRef< TYPE >::operator= | ( | const SmartRef< TYPE > & | c | ) | `[inline]`

Assignment.

Definition at line 226 of file SmartRef.h.

    00226                                                       {
    00227     m_target = c.m_target;
    00228     m_base.m_hintID = c.m_base.m_hintID;
    00229     m_base.m_linkID = c.m_base.m_linkID;
    00230     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 232 of file SmartRef.h.

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

template<class TYPE>

TYPE& SmartRef< TYPE >::operator * | ( |  | ) | `[inline]`

Dereference operator.

Definition at line 239 of file SmartRef.h.

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

template<class TYPE>

const TYPE& SmartRef< TYPE >::operator * | ( |  | ) | const`[inline]`

Dereference operator.

Definition at line 241 of file SmartRef.h.

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

template<class TYPE>

TYPE* SmartRef< TYPE >::operator-> | ( |  | ) | `[inline]`

Dereference operator.

Definition at line 243 of file SmartRef.h.

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

template<class TYPE>

const TYPE* SmartRef< TYPE >::operator-> | ( |  | ) | const`[inline]`

Dereference operator to const object.

Definition at line 245 of file SmartRef.h.

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

template<class TYPE>

SmartRef< TYPE >::operator const TYPE * | ( |  | ) | const`[inline]`

Implicit type conversion to const object.

Definition at line 247 of file SmartRef.h.

References SmartRef< TYPE >::target().

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

template<class TYPE>

SmartRef< TYPE >::operator TYPE * | ( |  | ) | `[inline]`

Implicit type conversion.

Definition at line 249 of file SmartRef.h.

References SmartRef< TYPE >::target().

    00249 {  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 293 of file SmartRef.h.

References SmartRef< TYPE >::m_base, SmartRef< TYPE >::m_target, Gaudi::Units::s, and SmartRefBase::writeObject().

    00293                                                                   {
    00294   m_base.writeObject(m_target, s);
    00295   return s;
    00296 }

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

References SmartRef< TYPE >::m_base, SmartRef< TYPE >::m_target, SmartRefBase::readObject(), and Gaudi::Units::s.

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

## Friends And Related Function Documentation

template<class TYPE>

friend class SmartRefArray< TYPE >`[friend]`

The container must be a friend.

Definition at line 62 of file SmartRef.h.

template<class TYPE>

friend class SmartRefList< TYPE >`[friend]`

Definition at line 63 of file SmartRef.h.

template<class TYPE>

friend class SmartRefMap< TYPE >`[friend]`

Definition at line 64 of file SmartRef.h.

template<class TYPE>

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

Output Streamer operator.

Definition at line 255 of file SmartRef.h.

    00255                                                                                 {
    00256     return ptr.writeRef(s);
    00257   }

template<class TYPE>

StreamBuffer& operator>> | ( | StreamBuffer & | s,
|  | SmartRef< TYPE > & | ptr |
| ) |  |  | `[friend]`

Input Streamer operator.

Definition at line 259 of file SmartRef.h.

    00259                                                                             {
    00260     return ptr.readRef(s);
    00261   }

## Member Data Documentation

template<class TYPE>

SmartRefBase SmartRef< TYPE >::m_base`[protected]`

Definition at line 71 of file SmartRef.h.

Referenced by SmartRef< KeyType >::_setEnvironment(), SmartRef< KeyType >::hintID(), SmartRef< KeyType >::linkID(), SmartRef< KeyType >::operator=(), SmartRef< KeyType >::operator==(), SmartRef< KeyType >::path(), SmartRef< TYPE >::readRef(), SmartRef< KeyType >::set(), SmartRef< KeyType >::shouldFollowLink(), SmartRef< KeyType >::SmartRef(), SmartRef< TYPE >::target(), and SmartRef< TYPE >::writeRef().

template<class TYPE>

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

Pointer to target data object.

Definition at line 73 of file SmartRef.h.

Referenced by SmartRef< KeyType >::data(), SmartRef< KeyType >::operator=(), SmartRef< KeyType >::operator==(), SmartRef< TYPE >::readRef(), SmartRef< KeyType >::shouldFollowLink(), SmartRef< KeyType >::SmartRef(), SmartRef< TYPE >::target(), and SmartRef< TYPE >::writeRef().

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiKernel/v25r2/GaudiKernel/SmartRef.h