| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Public Types | Public Member Functions | Protected Attributes | Friends

# SmartRef< TYPE > Class Template Reference

Kernel objects: SmartRef. More...

`#include <SmartRef.h>`

Collaboration diagram for SmartRef< TYPE >:
[legend]

List of all members.

## 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
| Standard destructor.
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.

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

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

## Constructor & Destructor Documentation

template<class TYPE>

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

Standard Constructor.

Definition at line 79 of file SmartRef.h.

                  {
        m_base.m_hintID = INVALID;
        m_base.m_linkID = INVALID;
        m_target = 0;
        _setEnvironment(0, 0);
      }

template<class TYPE>

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

Standard Constructor with initialisation.

Definition at line 86 of file SmartRef.h.

                               {
        m_base.m_hintID = INVALID;
        m_base.m_linkID = INVALID;
        m_target = pObject;
        _setEnvironment(0, 0);
      }

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.

                                     {
        m_base.m_hintID = INVALID;
        m_base.m_linkID = INVALID;
        m_target = const_cast<TYPE*>(pObject);
        _setEnvironment(0, 0);
      }

template<class TYPE>

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

Copy Constructor.

Definition at line 100 of file SmartRef.h.

                                       {
        m_base.m_hintID = copy.m_base.m_hintID;
        m_base.m_linkID = copy.m_base.m_linkID;
        m_target = copy.m_target;
        _setEnvironment(copy.m_base.m_data, copy.m_base.m_contd);
      }

template<class TYPE>

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

Constructor.

Definition at line 107 of file SmartRef.h.

                                                      {
        m_base.m_hintID = hint;
        m_base.m_linkID = link;
        m_target = obj;
        _setEnvironment(0, 0);
      }

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.

                                                                                   {
        m_base.m_hintID = hint;
        m_base.m_linkID = link;
        m_target = obj;
        const DataObject* src = (0==pObj) ? 0 : pObj->parent();
        _setEnvironment(src, pObj);
      }

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.

                                                                              {
        m_base.m_hintID = hint;
        m_base.m_linkID = link;
        m_target = obj;
        _setEnvironment(pObj, 0);
      }

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.

                                                                   {
        m_base.m_hintID = hint;
        m_base.m_linkID = INVALID;
        m_target = obj;
        _setEnvironment(pObj, 0);
      }

## Member Function Documentation

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.

                                                                                                            {
        m_base.m_data  = pObj;
        m_base.m_contd = pContd;
        m_base.setObjectType(data());
        return *this;
      }

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.

                                                                                                {
        m_base.m_data  = pObj;
        m_base.m_contd = pContd;
        m_base.setObjectType(data());
        return *this;
      }

template<class TYPE>

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

Definition at line 166 of file SmartRef.h.

                                  {
        return m_target;
      }

template<class TYPE>

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

Access to raw data pointer.

Definition at line 163 of file SmartRef.h.

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

template<class TYPE>

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

Access hint id:

Definition at line 147 of file SmartRef.h.

                              {
        return m_base.m_hintID;
      }

template<class TYPE>

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

Access link id:

Definition at line 151 of file SmartRef.h.

                              {
        return m_base.m_linkID;
      }

template<class TYPE>

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

Implicit type conversion to const object.

Definition at line 249 of file SmartRef.h.

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

template<class TYPE>

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

Implicit type conversion.

Definition at line 251 of file SmartRef.h.

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

template<class TYPE>

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

NON-Equality operator.

Definition at line 192 of file SmartRef.h.

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

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.

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

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.

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

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.

                                                       {
        return _setEnvironment(pObj,0);
      }

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.

                                                                        {
        return _setEnvironment(pObj,0);
      }

template<class TYPE>

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

Dereference operator.

Definition at line 241 of file SmartRef.h.

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

template<class TYPE>

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

Dereference operator.

Definition at line 243 of file SmartRef.h.

    {  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.

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

template<class TYPE>

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

Dereference operator.

Definition at line 245 of file SmartRef.h.

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

template<class TYPE>

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

Assignment.

Definition at line 234 of file SmartRef.h.

                                                 {
        m_target = pObject;
        m_base.m_hintID = INVALID;
        m_base.m_linkID = INVALID;
        return *this;
      }

template<class TYPE>

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

Assignment.

Definition at line 228 of file SmartRef.h.

                                                          {
        m_target = c.m_target;
        m_base.m_hintID = c.m_base.m_hintID;
        m_base.m_linkID = c.m_base.m_linkID;
        return _setEnvironment(c.m_base.m_data, c.m_base.m_contd);  }

template<class TYPE>

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

Equality operator.

Definition at line 176 of file SmartRef.h.

                                                         {
        if ( 0 != m_target && 0 != c.m_target )   {
          return m_target == c.m_target;
        }
        else if ( 0 == m_target && 0 == c.m_target )    {
          return m_base.isEqual(m_target,c.m_base);
        }
        else if ( 0 != m_target && 0 == c.m_target )  {
          return m_base.isEqualEx(m_target, c.m_base);
        }
        else if ( 0 == m_target && 0 != c.m_target )  {
          return c.m_base.isEqualEx(c.m_target, m_base);
        }
        return false;
      }

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.

    { return m_base.path(); }

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

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

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.

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

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.

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

template<class TYPE>

bool SmartRef< TYPE >::shouldFollowLink | ( | const DataObject * | ) | const`[inline]`

Standard destructor.

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

Definition at line 139 of file SmartRef.h.

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

template<class TYPE >

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

Access to the object.

Access to the object (CONST)

Definition at line 288 of file SmartRef.h.

                                               {
      if ( 0 == m_target )    {
        m_target = dynamic_cast<const TYPE*>(m_base.accessData(m_target));
      }
      return m_target;
    }

template<class TYPE >

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

Access to the object.

Definition at line 279 of file SmartRef.h.

                                  {
      if ( 0 == m_target )    {
        m_target = dynamic_cast<const TYPE*>(m_base.accessData(m_target));
      }
      return const_cast<TYPE*>(m_target);
    }

template<class TYPE>

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

Access to embedded type.

Definition at line 159 of file SmartRef.h.

                                          {
        return &typeid(TYPE);
      }

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

                                                                      {
      m_base.writeObject(m_target, s);
      return s;
    }

## Friends And Related Function Documentation

template<class TYPE>

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

Output Streamer operator.

Definition at line 258 of file SmartRef.h.

                                                                                     {
        return ptr.writeRef(_s);
      }

template<class TYPE>

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

Input Streamer operator.

Definition at line 263 of file SmartRef.h.

                                                                                 {
        return ptr.readRef(_s);
      }

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.

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines