The Gaudi Framework  v33r1 (b1225454)
SmartRefVector.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ====================================================================
12 // SmartRefVector.h
13 // --------------------------------------------------------------------
14 //
15 // Package : Kernel
16 //
17 // Author : Markus Frank
18 //
19 // ====================================================================
20 #ifndef KERNEL_SMARTREFVECTOR_H
21 #define KERNEL_SMARTREFVECTOR_H 1
22 
23 // STL include files
24 #include <vector>
25 
26 // Include files
27 #include "GaudiKernel/SmartRef.h"
28 
64 template <class TYPE>
65 class SmartRefVector : public std::vector<SmartRef<TYPE>> {
66 protected:
73 
75  mutable const DataObject* m_data;
77  mutable const ContainedObject* m_contd;
78 
80  void _setEnvironment( const DataObject* pObj, const ContainedObject* pContd ) const {
81  m_data = pObj;
82  m_contd = pContd;
83  for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) { ( *i )._setEnvironment( pObj, pContd ); }
84  }
85 
86 public:
89  m_contd = 0;
90  m_data = 0;
91  }
93  template <class ITERATOR>
94  SmartRefVector( ITERATOR first, ITERATOR last )
95  : std::vector<SmartRef<TYPE>>( first, last ), m_data( 0 ), m_contd( 0 ) {}
97  SmartRefVector( const SmartRefVector& copy ) : std::vector<SmartRef<TYPE>>( copy ) { *this = copy; }
99  // virtual ~SmartRefVector() {
100  //}
101 
104  _setEnvironment( ( 0 == pObj ) ? 0 : pObj->parent(), pObj );
105  return *this;
106  }
108  const SmartRefVector<TYPE>& operator()( const ContainedObject* pObj ) const {
109  _setEnvironment( ( 0 == pObj ) ? 0 : pObj->parent(), pObj );
110  return *this;
111  }
114  _setEnvironment( pObj, 0 );
115  return *this;
116  }
118  const SmartRefVector<TYPE>& operator()( const DataObject* pObj ) const {
119  _setEnvironment( pObj, 0 );
120  return *this;
121  }
124  _Base::operator=( copy );
125  // Harms.... MF
126  // on copy we MUST make a 1 to 1 copy
127  // _setEnvironment( copy.m_data, copy.m_contd );
128  // use instead:
129  m_data = copy.m_data;
130  m_contd = copy.m_contd;
131  return *this;
132  }
134  const std::type_info* type() const { return &typeid( TYPE ); }
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 ) { return ptr.writeRefs( _s ); }
143  // MCl: it is "_s" instead of the most common "s" to avoid a fake icc remark #1599
144  friend StreamBuffer& operator>>( StreamBuffer& _s, SmartRefVector<TYPE>& ptr ) { return ptr.readRefs( _s ); }
145 };
146 
147 template <class TYPE>
149  long len = _Base::size();
150  s << len;
151  for ( _BaseConstIter i = _Base::begin(); i != _Base::end(); i++ ) {
152  ( *i )._setEnvironment( m_data, m_contd );
153  ( *i ).writeRef( s );
154  }
155  return s;
156 }
157 
158 template <class TYPE>
160  long len;
161  _Base::erase( _Base::begin(), _Base::end() );
162  s >> len;
163  for ( long i = 0; i < len; i++ ) {
164  _BaseValueType entry;
165  entry._setEnvironment( m_data, m_contd );
166  entry.readRef( s );
167  _Base::push_back( entry );
168  }
169  return s;
170 }
171 
172 #endif // KERNEL_SMARTREFVECTOR_H
constexpr auto size(const T &, Args &&...) noexcept
std::vector< _Entry >::value_type _BaseValueType
T operator=(T... args)
The stream buffer is a small object collecting object data.
Definition: StreamBuffer.h:51
SmartRefVector< TYPE > & operator()(ContainedObject *pObj)
Standard destructor.
friend StreamBuffer & operator<<(StreamBuffer &_s, const SmartRefVector< TYPE > &ptr)
Output Streamer operator.
STL namespace.
Kernel objects: SmartRef.
Definition: SmartRef.h:76
T end(T... args)
SmartRefVector()
Standard Constructor.
const std::type_info * type() const
Access to embedded type.
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Kernel objects: SmartRefVector.
void push_back(Container &c, const Value &v, std::true_type)
SmartRefVector< TYPE > & operator()(DataObject *pObj)
operator(): assigns parent object for serialisation
StreamBuffer & writeRefs(StreamBuffer &s) const
Helper to write references.
std::vector< _Entry >::const_iterator _BaseConstIter
const SmartRefVector< TYPE > & operator()(const DataObject *pObj) const
operator() const: assigns parent object for serialisation
SmartRefVector(const SmartRefVector &copy)
Copy Constructor.
def end
Definition: IOTest.py:123
StreamBuffer & readRefs(StreamBuffer &s)
Helper to read references.
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
STL class.
SmartRefVector(ITERATOR first, ITERATOR last)
templated Constructor
T begin(T... args)
std::vector< _Entry > _Base
Object types: typedef myself as Base.
string s
Definition: gaudirun.py:328
friend StreamBuffer & operator>>(StreamBuffer &_s, SmartRefVector< TYPE > &ptr)
Input Streamer operator.
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
const ObjectContainerBase * parent() const
Access to parent object.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
const SmartRefVector< TYPE > & operator()(const ContainedObject *pObj) const
operator() const: assigns parent object for serialisation
void _setEnvironment(const DataObject *pObj, const ContainedObject *pContd) const
Set the environment for the vector and all contained objects references.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40
SmartRef< TYPE > _Entry
That's the type of crap I am hosting.
SmartRefVector< TYPE > & operator=(const SmartRefVector< TYPE > &copy)
Assignment.