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

In This Package:

SmartRefVector.h

Go to the documentation of this file.
00001 //      ====================================================================
00002 //      SmartRefVector.h
00003 //      --------------------------------------------------------------------
00004 //
00005 //      Package   : Kernel
00006 //
00007 //      Author    : Markus Frank
00008 //
00009 //      ====================================================================
00010 #ifndef KERNEL_SMARTREFVECTOR_H
00011 #define KERNEL_SMARTREFVECTOR_H 1
00012 
00013 // STL include files
00014 #include <vector>
00015 
00016 // Include files
00017 #include "GaudiKernel/SmartRef.h"
00018 
00054 template <class TYPE> class SmartRefVector : public std::vector < SmartRef<TYPE> >   {
00055 protected:
00057   typedef SmartRef<TYPE>          _Entry;
00059   typedef std::vector <_Entry>    _Base;
00060   typedef typename std::vector<_Entry>::const_iterator    _BaseConstIter;
00061   typedef typename std::vector<_Entry>::value_type        _BaseValueType;
00062 
00064   mutable const DataObject*      m_data;
00066   mutable const ContainedObject* m_contd;
00067 
00069   void _setEnvironment(const DataObject* pObj, const ContainedObject* pContd)  const  {
00070     m_data  = pObj;
00071     m_contd = pContd;
00072     for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ )   {
00073       (*i)._setEnvironment(pObj, pContd);
00074     }
00075   }
00076 public:
00078   SmartRefVector()  {
00079     m_contd  = 0;
00080     m_data   = 0;
00081   }
00083   template <class ITERATOR>
00084   SmartRefVector( ITERATOR first , ITERATOR last ) 
00085     :  std::vector< SmartRef<TYPE> >( first , last ) 
00086     , m_data  ( 0 ) 
00087     , m_contd ( 0 ) 
00088   {
00089    
00090   }
00092   SmartRefVector(const SmartRefVector& copy) 
00093     :  std::vector< SmartRef<TYPE> >(copy) {
00094     *this = copy;
00095   }
00097   //virtual ~SmartRefVector()                  {
00098   //}
00099 
00101   SmartRefVector<TYPE>& operator() (ContainedObject* pObj)    {
00102     _setEnvironment((0==pObj) ? 0 : pObj->parent(), pObj);
00103     return *this;
00104   }
00106   const SmartRefVector<TYPE>& operator() (const ContainedObject* pObj)  const  {
00107     _setEnvironment((0==pObj) ? 0 : pObj->parent(), pObj);
00108     return *this;
00109   }
00111   SmartRefVector<TYPE>& operator() (DataObject* pObj)    {
00112     _setEnvironment(pObj,0);
00113     return *this;
00114   }
00116   const SmartRefVector<TYPE>& operator() (const DataObject* pObj)  const  {
00117     _setEnvironment(pObj,0);
00118     return *this;
00119   }
00121   SmartRefVector<TYPE>& operator=(const SmartRefVector<TYPE>& copy)  {
00122     _Base::operator=(copy);
00123     // Harms.... MF 
00124     // on copy we MUST make a 1 to 1 copy
00125     // _setEnvironment( copy.m_data, copy.m_contd );
00126     // use instead:
00127     m_data  = copy.m_data;
00128     m_contd = copy.m_contd;
00129     return *this;
00130   }
00132   const std::type_info* type()  const   {
00133     return &typeid(TYPE);
00134   }
00136   StreamBuffer& readRefs(StreamBuffer& s);
00138   StreamBuffer& writeRefs(StreamBuffer& s)  const;
00140   friend StreamBuffer& operator<< (StreamBuffer& s, const SmartRefVector<TYPE>& ptr)   {
00141     return ptr.writeRefs(s);
00142   }
00144   friend StreamBuffer& operator>> (StreamBuffer& s, SmartRefVector<TYPE>& ptr)     {
00145     return ptr.readRefs(s);
00146   }
00147 };
00148 
00149 template <class TYPE> inline
00150 StreamBuffer& SmartRefVector<TYPE>::writeRefs(StreamBuffer& s)  const  {
00151   long len = _Base::size();
00152   s << len;
00153   for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ )   {
00154     (*i)._setEnvironment(m_data, m_contd);
00155     (*i).writeRef(s);
00156   }
00157   return s;
00158 }
00159 
00160 template <class TYPE> inline
00161 StreamBuffer& SmartRefVector<TYPE>::readRefs(StreamBuffer& s)    {
00162   long len;
00163   _Base::erase( _Base::begin(), _Base::end() );
00164   s >> len;
00165   for ( long i = 0; i < len; i++ )    {
00166     _BaseValueType entry;
00167     entry._setEnvironment(m_data, m_contd);
00168     entry.readRef(s);
00169     _Base::push_back( entry );
00170   }
00171   return s;
00172 }
00173 
00174 #endif // KERNEL_SMARTREFVECTOR_H
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:56:58 2011 for GaudiKernel by doxygen 1.4.7