Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ObjectVector.h
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/ObjectVector.h,v 1.11 2008/10/09 16:46:49 marcocle Exp $
2 #ifndef GAUDIKERNEL_OBJECTVECTOR_H
3 #define GAUDIKERNEL_OBJECTVECTOR_H
4 
5 
6 // Include files
7 #include "GaudiKernel/Kernel.h"
8 #include "GaudiKernel/ClassID.h"
11 
12 #include <vector>
13 #include <iomanip>
14 
15 
16 // Definition of the CLID for this class defined in ClassID.h
17 //static const CLID CLID_ObjectList = (1<<17); // ObjectVector (bit 17 set)
18 
38 template <class TYPE>
39 class ObjectVector : public ObjectContainerBase {
40 
41 public:
42  typedef TYPE contained_type;
44 
47 
50 
53 #ifdef _WIN32
54  typedef typename std::vector<TYPE*>::_Tptr pointer;
56 #else
59 #endif
60 
61 public:
64  : m_vector(0) { }
65  ObjectVector( const char* /* name */ )
66  : m_vector(0) { }
69  : ObjectContainerBase(), m_vector(value.m_vector) { }
70 
72  virtual ~ObjectVector() {
73  for( typename ObjectVector<TYPE>::iterator i = begin(); i != end(); i++ ) {
74  // Set the back pointer to 0 to avoid repetitional searching
75  // for the object in the container, and deleting the object
76  (*i)->setParent (0);
77  delete *i;
78  }
79  }
80 
82  virtual const CLID& clID() const {
84  }
86  static const CLID& classID() {
87  static CLID clid = TYPE::classID() + CLID_ObjectVector;
88  return clid;
89  }
90 
93  m_vector = right.m_vector;
94  return *this;
95  }
96 
99  return m_vector.begin();
100  }
101 
104  return m_vector.begin();
105  }
106 
109  return m_vector.end();
110  }
111 
114  return m_vector.end();
115  }
116 
119  return m_vector.rbegin();
120  }
121 
125  return m_vector.rbegin();
126  }
127 
130  return m_vector.rend();
131  }
132 
135  return m_vector.rend();
136  }
137 
143  return m_vector.size();
144  }
145 
148  return m_vector.size();
149  }
150 
153  return m_vector.max_size();
154  }
155 
159  return m_vector.capacity();
160  }
161 
169  void reserve( typename ObjectVector<TYPE>::size_type value ) {
170  m_vector.reserve( value );
171  }
172 
174  bool empty () const {
175  return m_vector.empty();
176  }
177 
180  return m_vector.front();
181  }
182 
185  return m_vector.front();
186  }
187 
190  return m_vector.back();
191  }
192 
195  return m_vector.back();
196  }
197 
200  if( 0 != value->parent() ) {
201  const_cast<ObjectContainerBase*>(value->parent())->remove(value);
202  }
203  value->setParent(this);
204  m_vector.push_back(value);
205  }
206 
208  virtual long add(ContainedObject* pObject) {
209  try {
210  typename ObjectVector<TYPE>::value_type ptr =
211  dynamic_cast<typename ObjectVector<TYPE>::value_type>(pObject);
212  if ( 0 != ptr ) {
213  push_back(ptr);
214  return m_vector.size()-1;
215  }
216  }
217  catch(...) {
218  }
219  return -1;
220  }
221 
224  void pop_back () {
225  typename ObjectVector<TYPE>::value_type position = m_vector.back();
226  // Set the back pointer to 0 to avoid repetitional searching
227  // for the object in the container, and deleting the object
228  position->setParent (0);
229  delete position;
230  // Removing from the container itself
231  m_vector.pop_back();
232  }
233 
236  virtual long remove(ContainedObject* value) {
237  // Find the object of the value value
239  for( i = begin(); i != end(); i++ ) {
240  if( value == *i ) {
241  break;
242  }
243  }
244  if( end() == i ) {
245  // Object cannot be released from the conatiner,
246  // as it is not contained in it
247  return StatusCode::FAILURE;
248  }
249  else {
250  // Set the back pointer to 0 to avoid repetitional searching
251  // for the object in the container and deleting the object
252  (*i)->setParent (0);
253  erase(i);
254  return StatusCode::SUCCESS;
255  }
256  }
257 
260  typename ObjectVector<TYPE>::const_reference value ) {
261  value->setParent(this);
262  typename ObjectVector<TYPE>::iterator i = m_vector.insert(position, value);
263  return i;
264  }
265 
267  void erase( typename ObjectVector<TYPE>::iterator position ) {
268  if( 0 != (*position)->parent() ) {
269  // Set the back pointer to 0 to avoid repetitional searching
270  // for the object in the container, and deleting the object
271  (*position)->setParent (0);
272  delete *position;
273  }
274  // Removing from the container itself
275  m_vector.erase(position);
276  }
277 
279  void erase( typename ObjectVector<TYPE>::iterator first,
280  typename ObjectVector<TYPE>::iterator last ) {
281  for(typename ObjectVector<TYPE>::iterator i = first; i != last; i++ ) {
282  // Set the back pointer to 0 to avoid repetitional searching
283  // for the object in the container, and deleting the object
284  (*i)->setParent(0);
285  delete *i;
286  }
287  // Removing from the container itself
288  m_vector.erase(first, last);
289  }
290 
292  void clear() {
293  erase(begin(), end());
294  }
295 
299  return m_vector[n];
300  }
301 
305  return m_vector[n];
306  }
307 
311  virtual long index( const ContainedObject* obj ) const {
312  long i;
313  for( i = 0; i < (long)m_vector.size(); i++ ) {
314  if( m_vector[i] == obj ) {
315  return i;
316  }
317  }
318  return -1;
319  }
320 
322  virtual ContainedObject* containedObject( long dist ) const {
323  return m_vector[dist];
324  }
325 
327  virtual std::ostream& fillStream( std::ostream& s ) const {
328  s << "class ObjectVector : size = "
329  << std::setw(12)
330  << size() << "\n";
331  // Output the base class
332  //ObjectContainerBase::fillStream(s);
333  if ( 0 != size() ) {
334  s << "\nContents of the STL vector :";
335  long count = 0;
337  for( iter = m_vector.begin(); iter != m_vector.end(); iter++, count++ ) {
338  s << "\nIndex "
339  << std::setw(12)
340  << count
341  << " of object of type " << **iter;
342  }
343  }
344  return s;
345  }
346 
347 private:
350 };
351 
352 #endif // GAUDIKERNEL_OBJECTVECTOR_H
353 

Generated at Mon Feb 17 2014 14:37:43 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004