| The Gaudi Framework v32r1 (f65d50dc)

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 protected:
58 typedef SmartRef<TYPE> _Entry;
60 typedef std::vector<_Entry> _Base;
61 typedef typename std::vector<_Entry>::const_iterator _BaseConstIter;
62 typedef typename std::vector<_Entry>::value_type _BaseValueType;
63
65 mutable const DataObject* m_data;
67 mutable const ContainedObject* m_contd;
68
70 void _setEnvironment( const DataObject* pObj, const ContainedObject* pContd ) const {
71 m_data = pObj;
72 m_contd = pContd;
73 for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) { ( *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 ), m_data( 0 ), m_contd( 0 ) {}
87 SmartRefVector( const SmartRefVector& copy ) : std::vector<SmartRef<TYPE>>( copy ) { *this = copy; }
89 // virtual ~SmartRefVector() {
90 //}
91
93 SmartRefVector<TYPE>& operator()( ContainedObject* pObj ) {
94 _setEnvironment( ( 0 == pObj ) ? 0 : pObj->parent(), pObj );
95 return *this;
96 }
98 const SmartRefVector<TYPE>& operator()( const ContainedObject* pObj ) const {
99 _setEnvironment( ( 0 == pObj ) ? 0 : pObj->parent(), pObj );
100 return *this;
101 }
103 SmartRefVector<TYPE>& operator()( DataObject* pObj ) {
104 _setEnvironment( pObj, 0 );
105 return *this;
106 }
108 const SmartRefVector<TYPE>& operator()( const DataObject* pObj ) const {
109 _setEnvironment( pObj, 0 );
110 return *this;
111 }
113 SmartRefVector<TYPE>& operator=( const SmartRefVector<TYPE>& copy ) {
114 _Base::operator=( copy );
115 // Harms.... MF
116 // on copy we MUST make a 1 to 1 copy
117 // _setEnvironment( copy.m_data, copy.m_contd );
118 // use instead:
119 m_data = copy.m_data;
120 m_contd = copy.m_contd;
121 return *this;
122 }
124 const std::type_info* type() const { return &typeid( TYPE ); }
126 StreamBuffer& readRefs( StreamBuffer& s );
128 StreamBuffer& writeRefs( StreamBuffer& s ) const;
130 // MCl: it is "_s" instead of the most common "s" to avoid a fake icc remark #1599
131 friend StreamBuffer& operator<<( StreamBuffer& _s, const SmartRefVector<TYPE>& ptr ) { return ptr.writeRefs( _s ); }
133 // MCl: it is "_s" instead of the most common "s" to avoid a fake icc remark #1599
134 friend StreamBuffer& operator>>( StreamBuffer& _s, SmartRefVector<TYPE>& ptr ) { return ptr.readRefs( _s ); }
135 };
136
137 template <class TYPE>
138 inline StreamBuffer& SmartRefVector<TYPE>::writeRefs( StreamBuffer& s ) const {
139 long len = _Base::size();
140 s << len;
141 for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) {
142 ( *i )._setEnvironment( m_data, m_contd );
143 ( *i ).writeRef( s );
144 }
145 return s;
146 }
147
148 template <class TYPE>
149 inline StreamBuffer& SmartRefVector<TYPE>::readRefs( StreamBuffer& s ) {
150 long len;
151 _Base::erase( _Base::begin(), _Base::end() );
152 s >> len;
153 for ( long i = 0; i < len; i++ ) {
154 _BaseValueType entry;
155 entry._setEnvironment( m_data, m_contd );
156 entry.readRef( s );
157 _Base::push_back( entry );
158 }
159 return s;
160 }
161
162 #endif // KERNEL_SMARTREFVECTOR_H
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:14
SmartRefVector::_BaseValueType
std::vector< _Entry >::value_type _BaseValueType
Definition: SmartRefVector.h:62
std::vector::operator=
T operator=(T... args)
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:93
SmartRefVector::operator<<
friend StreamBuffer & operator<<(StreamBuffer &_s, const SmartRefVector< TYPE > &ptr)
Output Streamer operator.
Definition: SmartRefVector.h:131
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:78
Gaudi::Functional::details::details2::push_back
void push_back(Container &c, const Value &v, std::true_type)
Definition: FunctionalDetails.h:184
SmartRefVector::type
const std::type_info * type() const
Access to embedded type.
Definition: SmartRefVector.h:124
SmartRefVector::m_contd
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Definition: SmartRefVector.h:67
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:103
SmartRefVector::writeRefs
StreamBuffer & writeRefs(StreamBuffer &s) const
Helper to write references.
Definition: SmartRefVector.h:138
SmartRefVector::_BaseConstIter
std::vector< _Entry >::const_iterator _BaseConstIter
Definition: SmartRefVector.h:61
SmartRefVector::operator()
const SmartRefVector< TYPE > & operator()(const DataObject *pObj) const
operator() const: assigns parent object for serialisation
Definition: SmartRefVector.h:108
SmartRefVector::SmartRefVector
SmartRefVector(const SmartRefVector &copy)
Copy Constructor.
Definition: SmartRefVector.h:87
IOTest.end
def end
Definition: IOTest.py:112
SmartRefVector::readRefs
StreamBuffer & readRefs(StreamBuffer &s)
Helper to read references.
Definition: SmartRefVector.h:149
ContainedObject
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
Definition: ContainedObject.h:31
std::vector
STL class.
SmartRefVector::SmartRefVector
SmartRefVector(ITERATOR first, ITERATOR last)
templated Constructor
Definition: SmartRefVector.h:84
std::vector::begin
T begin(T... args)
SmartRef.h
SmartRefVector::_Base
std::vector< _Entry > _Base
Object types: typedef myself as Base.
Definition: SmartRefVector.h:60
gaudirun.s
string s
Definition: gaudirun.py:316
SmartRefVector::operator>>
friend StreamBuffer & operator>>(StreamBuffer &_s, SmartRefVector< TYPE > &ptr)
Input Streamer operator.
Definition: SmartRefVector.h:134
SmartRefVector::m_data
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
Definition: SmartRefVector.h:65
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:51
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:120
SmartRefVector::operator()
const SmartRefVector< TYPE > & operator()(const ContainedObject *pObj) const
operator() const: assigns parent object for serialisation
Definition: SmartRefVector.h:98
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:70
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's the type of crap I am hosting.
Definition: SmartRefVector.h:58
SmartRefVector::operator=
SmartRefVector< TYPE > & operator=(const SmartRefVector< TYPE > &copy)
Assignment.
Definition: SmartRefVector.h:113