| The Gaudi Framework v27r1

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

- File List
- File Members

ObjectVector.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_OBJECTVECTOR_H
2 #define GAUDIKERNEL_OBJECTVECTOR_H
3
4
5 // Include files
6 #include "GaudiKernel/Kernel.h"
7 #include "GaudiKernel/ClassID.h"
8 #include "GaudiKernel/StreamBuffer.h"
9 #include "GaudiKernel/ObjectContainerBase.h"
10
11 #include <vector>
12 #include <iomanip>
13
14
15 // Definition of the CLID for this class defined in ClassID.h
16 //static const CLID CLID_ObjectList = (1<<17); // ObjectVector (bit 17 set)
17
37 template <class TYPE>
38 class ObjectVector : public ObjectContainerBase {
39
40 public:
41 typedef TYPE contained_type;
42 typedef typename std::vector<TYPE*>::value_type value_type;
43
44 typedef typename std::vector<TYPE*>::reference reference;
45 typedef typename std::vector<TYPE*>::const_reference const_reference;
46
47 typedef typename std::vector<TYPE*>::iterator iterator;
48 typedef typename std::vector<TYPE*>::const_iterator const_iterator;
49
50 typedef typename std::vector<TYPE*>::reverse_iterator reverse_iterator;
51 typedef typename std::vector<TYPE*>::const_reverse_iterator const_reverse_iterator;
52 #ifdef _WIN32
53 typedef typename std::vector<TYPE*>::_Tptr pointer;
54 typedef typename std::vector<TYPE*>::_Ctptr const_pointer;
55 #else
56 typedef typename std::vector<TYPE*>::pointer pointer;
57 typedef typename std::vector<TYPE*>::const_pointer const_pointer;
58 #endif
59
60 public:
62 ObjectVector()
63 : m_vector(0) { }
64 ObjectVector( const char* /* name */ )
65 : m_vector(0) { }
66
67 ObjectVector( const ObjectVector<TYPE>& ) = delete;
68 ObjectVector& operator=( const ObjectVector<TYPE>& ) = delete;
69
71 virtual ~ObjectVector() {
72 for( auto& i : m_vector ) {
73 // Set the back pointer to 0 to avoid repetitional searching
74 // for the object in the container, and deleting the object
75 i->setParent (nullptr);
76 delete i;
77 }
78 }
79
81 virtual const CLID& clID() const {
82 return ObjectVector<TYPE>::classID();
83 }
85 static const CLID& classID() {
86 static const CLID clid = TYPE::classID() + CLID_ObjectVector;
87 return clid;
88 }
89
90
92 typename ObjectVector<TYPE>::iterator begin () {
93 return m_vector.begin();
94 }
95
97 typename ObjectVector<TYPE>::const_iterator begin () const {
98 return m_vector.begin();
99 }
100
102 typename ObjectVector<TYPE>::iterator end () {
103 return m_vector.end();
104 }
105
107 typename ObjectVector<TYPE>::const_iterator end () const {
108 return m_vector.end();
109 }
110
112 typename ObjectVector<TYPE>::reverse_iterator rbegin () {
113 return m_vector.rbegin();
114 }
115
118 typename ObjectVector<TYPE>::const_reverse_iterator rbegin () const {
119 return m_vector.rbegin();
120 }
121
123 typename ObjectVector<TYPE>::reverse_iterator rend () {
124 return m_vector.rend();
125 }
126
128 typename ObjectVector<TYPE>::const_reverse_iterator rend () const {
129 return m_vector.rend();
130 }
131
136 typename ObjectVector<TYPE>::size_type size () const {
137 return m_vector.size();
138 }
139
141 virtual typename ObjectVector<TYPE>::size_type numberOfObjects() const {
142 return m_vector.size();
143 }
144
146 typename ObjectVector<TYPE>::size_type max_size () const {
147 return m_vector.max_size();
148 }
149
152 typename ObjectVector<TYPE>::size_type capacity () const {
153 return m_vector.capacity();
154 }
155
163 void reserve( typename ObjectVector<TYPE>::size_type value ) {
164 m_vector.reserve( value );
165 }
166
168 bool empty () const {
169 return m_vector.empty();
170 }
171
173 typename ObjectVector<TYPE>::reference front () {
174 return m_vector.front();
175 }
176
178 typename ObjectVector<TYPE>::const_reference front () const {
179 return m_vector.front();
180 }
181
183 typename ObjectVector<TYPE>::reference back () {
184 return m_vector.back();
185 }
186
188 typename ObjectVector<TYPE>::const_reference back () const {
189 return m_vector.back();
190 }
191
193 void push_back( typename ObjectVector<TYPE>::const_reference value ) {
194 if( value->parent() ) {
195 const_cast<ObjectContainerBase*>(value->parent())->remove(value);
196 }
197 value->setParent(this);
198 m_vector.push_back(value);
199 }
200
202 virtual long add(ContainedObject* pObject) {
203 try {
204 auto ptr = dynamic_cast<typename ObjectVector<TYPE>::value_type>(pObject);
205 if ( ptr ) {
206 push_back(ptr);
207 return m_vector.size()-1;
208 }
209 }
210 catch(...) {
211 }
212 return -1;
213 }
214
217 void pop_back () {
218 auto position = m_vector.back();
219 // Set the back pointer to 0 to avoid repetitional searching
220 // for the object in the container, and deleting the object
221 position->setParent(nullptr);
222 delete position;
223 // Removing from the container itself
224 m_vector.pop_back();
225 }
226
229 virtual long remove(ContainedObject* value) {
230 // Find the object of the value value
231 auto i = std::find_if( begin(), end(), [&](const ContainedObject* j) { return j==value; } );
232 if( i == end() ) {
233 // Object cannot be released from the conatiner,
234 // as it is not contained in it
235 return StatusCode::FAILURE;
236 }
237 // Set the back pointer to 0 to avoid repetitional searching
238 // for the object in the container and deleting the object
239 (*i)->setParent (nullptr);
240 erase(i);
241 return StatusCode::SUCCESS;
242 }
243
245 typename ObjectVector<TYPE>::iterator insert( typename ObjectVector<TYPE>::iterator position,
246 typename ObjectVector<TYPE>::const_reference value ) {
247 value->setParent(this);
248 return m_vector.insert(position, value);
249 }
250
252 void erase( typename ObjectVector<TYPE>::iterator position ) {
253 if( (*position)->parent() ) {
254 // Set the back pointer to 0 to avoid repetitional searching
255 // for the object in the container, and deleting the object
256 (*position)->setParent (nullptr);
257 delete *position;
258 }
259 // Removing from the container itself
260 m_vector.erase(position);
261 }
262
264 void erase( typename ObjectVector<TYPE>::iterator first,
265 typename ObjectVector<TYPE>::iterator last ) {
266 for(auto i = first; i != last; i++ ) {
267 // Set the back pointer to 0 to avoid repetitional searching
268 // for the object in the container, and deleting the object
269 (*i)->setParent(nullptr);
270 delete *i;
271 }
272 // Removing from the container itself
273 m_vector.erase(first, last);
274 }
275
277 void clear() {
278 erase(begin(), end());
279 }
280
282 typename ObjectVector<TYPE>::reference
283 operator[] (typename ObjectVector<TYPE>::size_type n) {
284 return m_vector[n];
285 }
286
288 typename ObjectVector<TYPE>::const_reference
289 operator[] (typename ObjectVector<TYPE>::size_type n) const {
290 return m_vector[n];
291 }
292
296 virtual long index( const ContainedObject* obj ) const {
297 auto i = std::find_if( begin(), end(), [&](const ContainedObject *o)
298 { return o == obj; } );
299 return i!=end() ? std::distance( begin(), i ) : -1 ;
300 }
301
303 virtual ContainedObject* containedObject( long dist ) const {
304 return m_vector[dist];
305 }
306
308 virtual std::ostream& fillStream( std::ostream& s ) const {
309 s << "class ObjectVector : size = "
310 << std::setw(12)
311 << size() << "\n";
312 // Output the base class
313 //ObjectContainerBase::fillStream(s);
314 if ( !empty() ) {
315 s << "\nContents of the STL vector :";
316 long count = 0;
317 for(const auto& i : m_vector) {
318 s << "\nIndex "
319 << std::setw(12)
320 << count++
321 << " of object of type " << *i;
322 }
323 }
324 return s;
325 }
326
327 private:
329 std::vector<TYPE*> m_vector;
330 };
331
332 #endif // GAUDIKERNEL_OBJECTVECTOR_H
ObjectVector::end
ObjectVector< TYPE >::iterator end()
Return an iterator pointing to the end of the container.
Definition: ObjectVector.h:102
ClassID.h
Kernel.h
ObjectVector::clear
void clear()
Clear the entire content of the container and delete all contained objects.
Definition: ObjectVector.h:277
ObjectVector::index
virtual long index(const ContainedObject *obj) const
Return distance of a given object from the beginning of its container It correcponds to the "index" (...
Definition: ObjectVector.h:296
std::vector::empty
T empty(T...args)
std::distance
T distance(T...args)
ObjectContainerBase::size_type
size_t size_type
size_type, to conform the STL container interface
Definition: ObjectContainerBase.h:32
ObjectVector::add
virtual long add(ContainedObject *pObject)
Add an object to the container.
Definition: ObjectVector.h:202
ObjectVector::back
ObjectVector< TYPE >::reference back()
Return reference to the last element.
Definition: ObjectVector.h:183
ObjectVector::begin
ObjectVector< TYPE >::iterator begin()
Return an iterator pointing to the beginning of the container.
Definition: ObjectVector.h:92
ObjectVector::ObjectVector
ObjectVector(const char *)
Definition: ObjectVector.h:64
std::vector::rend
T rend(T...args)
std::vector::front
T front(T...args)
ObjectVector::erase
void erase(typename ObjectVector< TYPE >::iterator position)
Erase the object at "position" from the container. The removed object will be deleted.
Definition: ObjectVector.h:252
ObjectVector::rbegin
ObjectVector< TYPE >::reverse_iterator rbegin()
Return a reverse_iterator pointing to the beginning of the reversed container.
Definition: ObjectVector.h:112
ObjectVector::begin
ObjectVector< TYPE >::const_iterator begin() const
Return a const_iterator pointing to the beginning of the container.
Definition: ObjectVector.h:97
ObjectVector::const_iterator
std::vector< TYPE * >::const_iterator const_iterator
Definition: ObjectVector.h:48
ObjectVector::m_vector
std::vector< TYPE * > m_vector
The STL vector itself.
Definition: ObjectVector.h:329
ObjectVector::push_back
void push_back(typename ObjectVector< TYPE >::const_reference value)
push_back = append = insert a new element at the end of the container
Definition: ObjectVector.h:193
ObjectVector
ObjectVector is one of the basic Gaudi container classes capable of being registered in Data Stores...
Definition: ContainedObject.h:11
ObjectContainerBase.h
ObjectVector::erase
void erase(typename ObjectVector< TYPE >::iterator first, typename ObjectVector< TYPE >::iterator last)
Erase the range [first, last) from the container. The removed object will be deleted.
Definition: ObjectVector.h:264
ObjectVector::const_reference
std::vector< TYPE * >::const_reference const_reference
Definition: ObjectVector.h:45
ObjectVector::rend
ObjectVector< TYPE >::const_reverse_iterator rend() const
Return a const_reverse_iterator pointing to the end of the reversed container.
Definition: ObjectVector.h:128
std::vector::end
T end(T...args)
ObjectVector::const_pointer
std::vector< TYPE * >::const_pointer const_pointer
Definition: ObjectVector.h:57
ObjectVector::~ObjectVector
virtual ~ObjectVector()
Destructor.
Definition: ObjectVector.h:71
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
ObjectVector::numberOfObjects
virtual ObjectVector< TYPE >::size_type numberOfObjects() const
The same as size(), return number of objects in the container.
Definition: ObjectVector.h:141
StreamBuffer.h
std::setw
T setw(T...args)
ObjectVector::const_reverse_iterator
std::vector< TYPE * >::const_reverse_iterator const_reverse_iterator
Definition: ObjectVector.h:51
ObjectVector::front
ObjectVector< TYPE >::reference front()
Return reference to the first element.
Definition: ObjectVector.h:173
ObjectVector::operator=
ObjectVector & operator=(const ObjectVector< TYPE > &)=delete
std::vector::push_back
T push_back(T...args)
ObjectVector::front
ObjectVector< TYPE >::const_reference front() const
Return const_reference to the first element.
Definition: ObjectVector.h:178
ObjectVector::reverse_iterator
std::vector< TYPE * >::reverse_iterator reverse_iterator
Definition: ObjectVector.h:50
ObjectVector::containedObject
virtual ContainedObject * containedObject(long dist) const
Return const pointer to an object of a given distance (index)
Definition: ObjectVector.h:303
ObjectVector::operator[]
ObjectVector< TYPE >::reference operator[](typename ObjectVector< TYPE >::size_type n)
Return the reference to the n'th object in the container.
Definition: ObjectVector.h:283
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
ObjectVector::capacity
ObjectVector< TYPE >::size_type capacity() const
Return number of elements for which memory has been allocated It is always greater than or equal to s...
Definition: ObjectVector.h:152
std::vector::erase
T erase(T...args)
std::vector::pop_back
T pop_back(T...args)
std::vector::capacity
T capacity(T...args)
ObjectVector::iterator
std::vector< TYPE * >::iterator iterator
Definition: ObjectVector.h:47
ObjectVector::empty
bool empty() const
Return true if the size of the container is 0.
Definition: ObjectVector.h:168
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
ObjectVector::reserve
void reserve(typename ObjectVector< TYPE >::size_type value)
Reserve place for "value" objects in the container.
Definition: ObjectVector.h:163
ObjectVector::rbegin
ObjectVector< TYPE >::const_reverse_iterator rbegin() const
Return a const_reverse_iterator pointing to the beginning of the reversed container.
Definition: ObjectVector.h:118
ObjectVector::reference
std::vector< TYPE * >::reference reference
Definition: ObjectVector.h:44
ObjectVector::insert
ObjectVector< TYPE >::iterator insert(typename ObjectVector< TYPE >::iterator position, typename ObjectVector< TYPE >::const_reference value)
Insert "value" before "position".
Definition: ObjectVector.h:245
std::vector::insert
T insert(T...args)
ContainedObject
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
Definition: ContainedObject.h:29
std::find_if
T find_if(T...args)
std::vector::size
T size(T...args)
ObjectVector::max_size
ObjectVector< TYPE >::size_type max_size() const
Return the largest possible size of the container.
Definition: ObjectVector.h:146
std::vector
STL class.
ObjectVector::back
ObjectVector< TYPE >::const_reference back() const
Return const_reference to the last element.
Definition: ObjectVector.h:188
ObjectVector::ObjectVector
ObjectVector()
Constructors.
Definition: ObjectVector.h:62
ObjectVector::value_type
std::vector< TYPE * >::value_type value_type
Definition: ObjectVector.h:42
std::vector::begin
T begin(T...args)
ObjectVector::fillStream
virtual std::ostream & fillStream(std::ostream &s) const
Fill the output stream (ASCII)
Definition: ObjectVector.h:308
ObjectVector::pointer
std::vector< TYPE * >::pointer pointer
Definition: ObjectVector.h:56
ObjectVector::clID
virtual const CLID & clID() const
Retrieve class ID.
Definition: ObjectVector.h:81
std::vector::max_size
T max_size(T...args)
std::vector::back
T back(T...args)
gaudirun.s
string s
Definition: gaudirun.py:245
ObjectVector::contained_type
TYPE contained_type
Definition: ObjectVector.h:41
ObjectContainerBase
ObjectContainerBase is the base class for Gaudi container classes.
Definition: ObjectContainerBase.h:19
ObjectVector::rend
ObjectVector< TYPE >::reverse_iterator rend()
Return a reverse_iterator pointing to the end of the reversed container.
Definition: ObjectVector.h:123
ana.i
list i
Definition: ana.py:128
ObjectVector::size
ObjectVector< TYPE >::size_type size() const
Return the size of the container.
Definition: ObjectVector.h:136
ObjectVector::end
ObjectVector< TYPE >::const_iterator end() const
Return a const_iterator pointing to the end of the container.
Definition: ObjectVector.h:107
std::ostream
STL class.
ObjectVector::classID
static const CLID & classID()
Retrieve class ID.
Definition: ObjectVector.h:85
ObjectVector::pop_back
void pop_back()
pop_back = remove the last element from the container The removed object will be deleted (see the met...
Definition: ObjectVector.h:217
std::vector::reserve
T reserve(T...args)
std::vector::rbegin
T rbegin(T...args)