Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ObjectList.h
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/ObjectList.h,v 1.10 2008/10/09 16:46:49 marcocle Exp $
2 #ifndef GAUDIKERNEL_OBJECTLIST_H
3 #define GAUDIKERNEL_OBJECTLIST_H
4 
5 
6 // Include files
7 #include "GaudiKernel/Kernel.h"
8 #include "GaudiKernel/ClassID.h"
11 
12 #include <list>
13 #include <iomanip>
14 
15 
16 // Definition of the CLID for this class defined in ClassID.h
17 // static const CLID CLID_ObjectList = (1<<18); // ObjectList (bit 18 set)
18 
37 template <class TYPE>
38 class ObjectList : public ObjectContainerBase {
39 
40 public:
41  typedef TYPE contained_type;
43 
46 
49 
52 
53 #ifdef _WIN32
54  typedef typename std::vector<TYPE*>::_Tptr pointer;
56 #else
59 #endif
60 
61 public:
64  : m_list(0) { }
65  ObjectList( const char* name )
66  : m_list(0) { }
68  ObjectList( const ObjectList<TYPE>& value )
69  : m_list(value.m_list) { }
70 
72  virtual ~ObjectList() {
73  clear();
74  }
75 
77  virtual const CLID& clID() const {
79  }
80  static const CLID& classID() {
81  static CLID clid = TYPE::classID() + CLID_ObjectList;
82  return clid;
83  }
84 
87  this->processingVersion = right.m_processingVersion;
88  this->detectorDataObject = right.m_detectorDataObject;
89  m_list = right.m_list;
90  return *this;
91  }
92 
95  return m_list.begin();
96  }
97 
100  return m_list.begin();
101  }
102 
105  return m_list.end();
106  }
107 
110  return m_list.end();
111  }
112 
116  return m_list.rbegin();
117  }
118 
121  return m_list.rbegin();
122  }
123 
126  return m_list.rend();
127  }
128 
131  return m_list.rend();
132  }
133 
136  typename ObjectList<TYPE>::size_type size () const {
137  return m_list.size();
138  }
140  virtual typename ObjectList<TYPE>::size_type numberOfObjects() const {
141  return m_list.size();
142  }
143 
146  return m_list.max_size();
147  }
148 
150  bool empty () const {
151  return m_list.empty();
152  }
153 
156  return m_list.front();
157  }
158 
161  return m_list.front();
162  }
163 
166  return m_list.back();
167  }
168 
171  return m_list.back();
172  }
173 
176  if( 0 != value->parent() ) {
177  const_cast<ObjectContainerBase*>(value->parent())->remove(value);
178  }
179  value->setParent(this);
180  m_list.push_back(value);
181  }
182 
184  virtual long add(ContainedObject* pObject) {
185  try {
186  typename ObjectList<TYPE>::value_type ptr =
187  dynamic_cast<typename ObjectList<TYPE>::value_type>(pObject);
188  if ( 0 != ptr ) {
189  push_back(ptr);
190  return m_list.size()-1;
191  }
192  }
193  catch(...) {
194  }
195  return -1;
196  }
197 
200  void pop_back () {
201  typename ObjectList<TYPE>::value_type position = m_list.back();
202  // Set the back pointer to 0 to avoid repetitional searching
203  // for the object in the container, and deleting the object
204  position->setParent (0);
205  delete position;
206  // Removing from the container itself
207  m_list.pop_back();
208  }
209 
212  virtual long remove(ContainedObject* value) {
213  // Find the object of value value
214  long idx = 0;
215  typename ObjectList<TYPE>::iterator iter;
216  for( iter = begin(); iter != end(); iter++, idx++ ) {
217  if( value == *iter ) {
218  break;
219  }
220  }
221  if( end() == iter ) {
222  // Object cannot be released from the conatiner,
223  // as it is not contained in it
224  return -1;
225  }
226  else {
227  // Set the back pointer to 0 to avoid repetitional searching
228  // for the object in the container and deleting the object
229  (*iter)->setParent (0);
230  erase(iter);
231  return idx;
232  }
233  }
234 
237  typename ObjectList<TYPE>::const_reference value ) {
238  value->setParent(this);
239  typename ObjectList<TYPE>::iterator i = m_list.insert(position, value);
240  return i;
241  }
242 
244  void erase( typename ObjectList<TYPE>::iterator position ) {
245  if( 0 != (*position)->parent() ) {
246  // Set the back pointer to 0 to avoid repetitional searching
247  // for the object in the container, and deleting the object
248  (*position)->setParent (0);
249  delete *position;
250  }
251  // Removing from the container itself
252  m_list.erase(position);
253  }
254 
256  void erase( typename ObjectList<TYPE>::iterator first,
257  typename ObjectList<TYPE>::iterator last ) {
258  for( typename ObjectList<TYPE>::iterator iter = first; iter != last; iter++ ) {
259  // Set the back pointer to 0 to avoid repetitional searching
260  // for the object in the container, and deleting the object
261  (*iter)->setParent (0);
262  delete *iter;
263  }
264  // Removing from the container itself
265  m_list.erase(first, last);
266  }
267 
269  void clear() {
270  erase(begin(), end());
271  }
272 
275  virtual long index( const ContainedObject* obj ) const {
276  long i = 0;
277  typename ObjectList<TYPE>::const_iterator iter;
278  for( iter = begin(); iter != end(); iter++ ) {
279  if( *iter == obj ) {
280  return i;
281  }
282  i++;
283  }
284  return -1;
285  }
286 
288  virtual ContainedObject* containedObject( long dist ) const {
289  long i = 0;
290  typename ObjectList<TYPE>::const_iterator iter;
291  for( iter = begin(); iter != end(); iter++ ) {
292  if( dist == i ) {
293  return *iter;
294  }
295  i++;
296  }
297  return 0;
298  }
299 
301  virtual std::ostream& fillStream( std::ostream& s ) const {
302  s << "class ObjectList : size = "
303  << std::setw(12)
304  << size() << "\n";
305  // Output the base class
306  //ObjectContainerBase::fillStream(s);
307  if ( 0 != size() ) {
308  s << "\nContents of the STL list :";
309  long count = 0;
310  typename ObjectList<TYPE>::const_iterator iter;
311  for( iter = m_list.begin(); iter != m_list.end(); iter++, count++ ) {
312  s << "\nIndex "
313  << std::setw(12)
314  << count
315  << " of object of type "<< **iter;
316  }
317  }
318  return s;
319  }
320 
321 private:
322 
325 };
326 
327 
328 #endif // GAUDI_OBJECTLIST_H

Generated at Wed Nov 28 2012 12:17:14 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004