| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SmartRefVector.h
Go to the documentation of this file.
1 // ====================================================================
2 // SmartRefVector.h
3 // --------------------------------------------------------------------
4 //
5 // Package : Kernel
6 //
7 // Author : Markus Frank
8 //
9 // ====================================================================
10 #ifndef KERNEL_SMARTREFVECTOR_H
11 #define KERNEL_SMARTREFVECTOR_H 1
12
13 // STL include files
14 #include <vector>
15
16 // Include files
17 #include "GaudiKernel/SmartRef.h"
18
54 template <class TYPE> class SmartRefVector : public std::vector < SmartRef<TYPE> > {
55 protected:
57 typedef SmartRef<TYPE> _Entry;
59 typedef std::vector <_Entry> _Base;
60 typedef typename std::vector<_Entry>::const_iterator _BaseConstIter;
61 typedef typename std::vector<_Entry>::value_type _BaseValueType;
62
64 mutable const DataObject* m_data;
66 mutable const ContainedObject* m_contd;
67
69 void _setEnvironment(const DataObject* pObj, const ContainedObject* pContd) const {
70 m_data = pObj;
71 m_contd = pContd;
72 for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) {
73 (*i)._setEnvironment(pObj, pContd);
74 }
75 }
76 public:
78 SmartRefVector() {
79 m_contd = 0;
80 m_data = 0;
81 }
83 template <class ITERATOR>
84 SmartRefVector( ITERATOR first , ITERATOR last )
85 : std::vector< SmartRef<TYPE> >( first , last )
86 , m_data ( 0 )
87 , m_contd ( 0 )
88 {
89
90 }
92 SmartRefVector(const SmartRefVector& copy)
93 : std::vector< SmartRef<TYPE> >(copy) {
94 *this = copy;
95 }
97 //virtual ~SmartRefVector() {
98 //}
99
101 SmartRefVector<TYPE>& operator() (ContainedObject* pObj) {
102 _setEnvironment((0==pObj) ? 0 : pObj->parent(), pObj);
103 return *this;
104 }
106 const SmartRefVector<TYPE>& operator() (const ContainedObject* pObj) const {
107 _setEnvironment((0==pObj) ? 0 : pObj->parent(), pObj);
108 return *this;
109 }
111 SmartRefVector<TYPE>& operator() (DataObject* pObj) {
112 _setEnvironment(pObj,0);
113 return *this;
114 }
116 const SmartRefVector<TYPE>& operator() (const DataObject* pObj) const {
117 _setEnvironment(pObj,0);
118 return *this;
119 }
121 SmartRefVector<TYPE>& operator=(const SmartRefVector<TYPE>& copy) {
122 _Base::operator=(copy);
123 // Harms.... MF
124 // on copy we MUST make a 1 to 1 copy
125 // _setEnvironment( copy.m_data, copy.m_contd );
126 // use instead:
127 m_data = copy.m_data;
128 m_contd = copy.m_contd;
129 return *this;
130 }
132 const std::type_info* type() const {
133 return &typeid(TYPE);
134 }
136 StreamBuffer& readRefs(StreamBuffer& s);
138 StreamBuffer& writeRefs(StreamBuffer& s) const;
140 // MCl: it is "_s" instead of the most common "s" to avoid a fake icc remark #1599
141 friend StreamBuffer& operator<< (StreamBuffer& _s, const SmartRefVector<TYPE>& ptr) {
142 return ptr.writeRefs(_s);
143 }
145 // MCl: it is "_s" instead of the most common "s" to avoid a fake icc remark #1599
146 friend StreamBuffer& operator>> (StreamBuffer& _s, SmartRefVector<TYPE>& ptr) {
147 return ptr.readRefs(_s);
148 }
149 };
150
151 template <class TYPE> inline
152 StreamBuffer& SmartRefVector<TYPE>::writeRefs(StreamBuffer& s) const {
153 long len = _Base::size();
154 s << len;
155 for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) {
156 (*i)._setEnvironment(m_data, m_contd);
157 (*i).writeRef(s);
158 }
159 return s;
160 }
161
162 template <class TYPE> inline
163 StreamBuffer& SmartRefVector<TYPE>::readRefs(StreamBuffer& s) {
164 long len;
165 _Base::erase( _Base::begin(), _Base::end() );
166 s >> len;
167 for ( long i = 0; i < len; i++ ) {
168 _BaseValueType entry;
169 entry._setEnvironment(m_data, m_contd);
170 entry.readRef(s);
171 _Base::push_back( entry );
172 }
173 return s;
174 }
175
176 #endif // KERNEL_SMARTREFVECTOR_H