| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

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>
55 class SmartRefVector : public std::vector<SmartRef<TYPE>>
56 {
57 protected:
59 typedef SmartRef<TYPE> _Entry;
61 typedef std::vector<_Entry> _Base;
62 typedef typename std::vector<_Entry>::const_iterator _BaseConstIter;
63 typedef typename std::vector<_Entry>::value_type _BaseValueType;
64
66 mutable const DataObject* m_data;
68 mutable const ContainedObject* m_contd;
69
71 void _setEnvironment( const DataObject* pObj, const ContainedObject* pContd ) const
72 {
73 m_data = pObj;
74 m_contd = pContd;
75 for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) {
76 ( *i )._setEnvironment( pObj, pContd );
77 }
78 }
79
80 public:
82 SmartRefVector()
83 {
84 m_contd = 0;
85 m_data = 0;
86 }
88 template <class ITERATOR>
89 SmartRefVector( ITERATOR first, ITERATOR last )
90 : std::vector<SmartRef<TYPE>>( first, last ), m_data( 0 ), m_contd( 0 )
91 {
92 }
94 SmartRefVector( const SmartRefVector& copy ) : std::vector<SmartRef<TYPE>>( copy ) { *this = copy; }
96 // virtual ~SmartRefVector() {
97 //}
98
100 SmartRefVector<TYPE>& operator()( ContainedObject* pObj )
101 {
102 _setEnvironment( ( 0 == pObj ) ? 0 : pObj->parent(), pObj );
103 return *this;
104 }
106 const SmartRefVector<TYPE>& operator()( const ContainedObject* pObj ) const
107 {
108 _setEnvironment( ( 0 == pObj ) ? 0 : pObj->parent(), pObj );
109 return *this;
110 }
112 SmartRefVector<TYPE>& operator()( DataObject* pObj )
113 {
114 _setEnvironment( pObj, 0 );
115 return *this;
116 }
118 const SmartRefVector<TYPE>& operator()( const DataObject* pObj ) const
119 {
120 _setEnvironment( pObj, 0 );
121 return *this;
122 }
124 SmartRefVector<TYPE>& operator=( const SmartRefVector<TYPE>& copy )
125 {
126 _Base::operator=( copy );
127 // Harms.... MF
128 // on copy we MUST make a 1 to 1 copy
129 // _setEnvironment( copy.m_data, copy.m_contd );
130 // use instead:
131 m_data = copy.m_data;
132 m_contd = copy.m_contd;
133 return *this;
134 }
136 const std::type_info* type() const { return &typeid( TYPE ); }
138 StreamBuffer& readRefs( StreamBuffer& s );
140 StreamBuffer& writeRefs( StreamBuffer& s ) const;
142 // MCl: it is "_s" instead of the most common "s" to avoid a fake icc remark #1599
143 friend StreamBuffer& operator<<( StreamBuffer& _s, const SmartRefVector<TYPE>& ptr ) { return ptr.writeRefs( _s ); }
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 ) { return ptr.readRefs( _s ); }
147 };
148
149 template <class TYPE>
150 inline StreamBuffer& SmartRefVector<TYPE>::writeRefs( StreamBuffer& s ) const
151 {
152 long len = _Base::size();
153 s << len;
154 for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) {
155 ( *i )._setEnvironment( m_data, m_contd );
156 ( *i ).writeRef( s );
157 }
158 return s;
159 }
160
161 template <class TYPE>
162 inline StreamBuffer& SmartRefVector<TYPE>::readRefs( StreamBuffer& s )
163 {
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
SmartRefVector::_BaseValueType
std::vector< _Entry >::value_type _BaseValueType
Definition: SmartRefVector.h:63
std::vector::operator=
T operator=(T...args)
SmartRefVector::type
const std::type_info * type() const
Access to embedded type.
Definition: SmartRefVector.h:136
StreamBuffer
The stream buffer is a small object collecting object data.
Definition: StreamBuffer.h:41
SmartRefVector::operator()
SmartRefVector< TYPE > & operator()(ContainedObject *pObj)
Standard destructor.
Definition: SmartRefVector.h:100
std
STL namespace.
SmartRef
Kernel objects: SmartRef.
Definition: SmartRef.h:66
std::vector::end
T end(T...args)
SmartRefVector::SmartRefVector
SmartRefVector()
Standard Constructor.
Definition: SmartRefVector.h:82
SmartRefVector::m_contd
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Definition: SmartRefVector.h:68
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:52
std::type_info
SmartRefVector
Kernel objects: SmartRefVector.
Definition: SmartRefVector.h:55
SmartRefVector::operator()
SmartRefVector< TYPE > & operator()(DataObject *pObj)
operator(): assigns parent object for serialisation
Definition: SmartRefVector.h:112
std::vector::push_back
T push_back(T...args)
SmartRefVector::_BaseConstIter
std::vector< _Entry >::const_iterator _BaseConstIter
Definition: SmartRefVector.h:62
std::vector::erase
T erase(T...args)
SmartRefVector::SmartRefVector
SmartRefVector(const SmartRefVector &copy)
Copy Constructor.
Definition: SmartRefVector.h:94
SmartRefVector::readRefs
StreamBuffer & readRefs(StreamBuffer &s)
Helper to read references.
Definition: SmartRefVector.h:162
ContainedObject
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
Definition: ContainedObject.h:31
std::vector::size
T size(T...args)
std::vector
STL class.
SmartRefVector::SmartRefVector
SmartRefVector(ITERATOR first, ITERATOR last)
templated Constructor
Definition: SmartRefVector.h:89
std::vector::begin
T begin(T...args)
SmartRefVector::operator()
const SmartRefVector< TYPE > & operator()(const DataObject *pObj) const
operator() const: assigns parent object for serialisation
Definition: SmartRefVector.h:118
SmartRef.h
SmartRefVector::_Base
std::vector< _Entry > _Base
Object types: typedef myself as Base.
Definition: SmartRefVector.h:61
gaudirun.s
string s
Definition: gaudirun.py:253
SmartRefVector::operator>>
friend StreamBuffer & operator>>(StreamBuffer &_s, SmartRefVector< TYPE > &ptr)
Input Streamer operator.
Definition: SmartRefVector.h:146
SmartRefVector::m_data
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
Definition: SmartRefVector.h:66
SmartRefVector::_setEnvironment
void _setEnvironment(const DataObject *pObj, const ContainedObject *pContd) const
Set the environment for the vector and all contained objects references.
Definition: SmartRefVector.h:71
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
SmartRefVector::_Entry
SmartRef< TYPE > _Entry
That&#39;s the type of crap I am hosting.
Definition: SmartRefVector.h:59
SmartRefVector::operator()
const SmartRefVector< TYPE > & operator()(const ContainedObject *pObj) const
operator() const: assigns parent object for serialisation
Definition: SmartRefVector.h:106
SmartRefVector::writeRefs
StreamBuffer & writeRefs(StreamBuffer &s) const
Helper to write references.
Definition: SmartRefVector.h:150
SmartRefVector::operator=
SmartRefVector< TYPE > & operator=(const SmartRefVector< TYPE > &copy)
Assignment.
Definition: SmartRefVector.h:124