Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 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) { }
66  ObjectList( const ObjectList<TYPE>& value )
67  : m_list(value.m_list) { }
68 
70  virtual ~ObjectList() {
71  clear();
72  }
73 
75  virtual const CLID& clID() const {
77  }
78  static const CLID& classID() {
79  static CLID clid = TYPE::classID() + CLID_ObjectList;
80  return clid;
81  }
82 
85  return m_list.begin();
86  }
87 
90  return m_list.begin();
91  }
92 
95  return m_list.end();
96  }
97 
100  return m_list.end();
101  }
102 
106  return m_list.rbegin();
107  }
108 
111  return m_list.rbegin();
112  }
113 
116  return m_list.rend();
117  }
118 
121  return m_list.rend();
122  }
123 
126  typename ObjectList<TYPE>::size_type size () const {
127  return m_list.size();
128  }
130  virtual typename ObjectList<TYPE>::size_type numberOfObjects() const {
131  return m_list.size();
132  }
133 
136  return m_list.max_size();
137  }
138 
140  bool empty () const {
141  return m_list.empty();
142  }
143 
146  return m_list.front();
147  }
148 
151  return m_list.front();
152  }
153 
156  return m_list.back();
157  }
158 
161  return m_list.back();
162  }
163 
166  if( 0 != value->parent() ) {
167  const_cast<ObjectContainerBase*>(value->parent())->remove(value);
168  }
169  value->setParent(this);
170  m_list.push_back(value);
171  }
172 
174  virtual long add(ContainedObject* pObject) {
175  try {
176  typename ObjectList<TYPE>::value_type ptr =
177  dynamic_cast<typename ObjectList<TYPE>::value_type>(pObject);
178  if ( 0 != ptr ) {
179  push_back(ptr);
180  return m_list.size()-1;
181  }
182  }
183  catch(...) {
184  }
185  return -1;
186  }
187 
190  void pop_back () {
191  typename ObjectList<TYPE>::value_type position = m_list.back();
192  // Set the back pointer to 0 to avoid repetitional searching
193  // for the object in the container, and deleting the object
194  position->setParent (0);
195  delete position;
196  // Removing from the container itself
197  m_list.pop_back();
198  }
199 
202  virtual long remove(ContainedObject* value) {
203  // Find the object of value value
204  long idx = 0;
205  typename ObjectList<TYPE>::iterator iter;
206  for( iter = begin(); iter != end(); iter++, idx++ ) {
207  if( value == *iter ) {
208  break;
209  }
210  }
211  if( end() == iter ) {
212  // Object cannot be released from the container,
213  // as it is not contained in it
214  return -1;
215  }
216  else {
217  // Set the back pointer to 0 to avoid repetitional searching
218  // for the object in the container and deleting the object
219  (*iter)->setParent (0);
220  erase(iter);
221  return idx;
222  }
223  }
224 
227  typename ObjectList<TYPE>::const_reference value ) {
228  value->setParent(this);
229  typename ObjectList<TYPE>::iterator i = m_list.insert(position, value);
230  return i;
231  }
232 
234  void erase( typename ObjectList<TYPE>::iterator position ) {
235  if( 0 != (*position)->parent() ) {
236  // Set the back pointer to 0 to avoid repetitional searching
237  // for the object in the container, and deleting the object
238  (*position)->setParent (0);
239  delete *position;
240  }
241  // Removing from the container itself
242  m_list.erase(position);
243  }
244 
246  void erase( typename ObjectList<TYPE>::iterator first,
247  typename ObjectList<TYPE>::iterator last ) {
248  for( typename ObjectList<TYPE>::iterator iter = first; iter != last; iter++ ) {
249  // Set the back pointer to 0 to avoid repetitional searching
250  // for the object in the container, and deleting the object
251  (*iter)->setParent (0);
252  delete *iter;
253  }
254  // Removing from the container itself
255  m_list.erase(first, last);
256  }
257 
259  void clear() {
260  erase(begin(), end());
261  }
262 
265  virtual long index( const ContainedObject* obj ) const {
266  long i = 0;
267  typename ObjectList<TYPE>::const_iterator iter;
268  for( iter = begin(); iter != end(); iter++ ) {
269  if( *iter == obj ) {
270  return i;
271  }
272  i++;
273  }
274  return -1;
275  }
276 
278  virtual ContainedObject* containedObject( long dist ) const {
279  long i = 0;
280  typename ObjectList<TYPE>::const_iterator iter;
281  for( iter = begin(); iter != end(); iter++ ) {
282  if( dist == i ) {
283  return *iter;
284  }
285  i++;
286  }
287  return 0;
288  }
289 
291  virtual std::ostream& fillStream( std::ostream& s ) const {
292  s << "class ObjectList : size = "
293  << std::setw(12)
294  << size() << "\n";
295  // Output the base class
296  //ObjectContainerBase::fillStream(s);
297  if ( 0 != size() ) {
298  s << "\nContents of the STL list :";
299  long count = 0;
300  typename ObjectList<TYPE>::const_iterator iter;
301  for( iter = m_list.begin(); iter != m_list.end(); iter++, count++ ) {
302  s << "\nIndex "
303  << std::setw(12)
304  << count
305  << " of object of type "<< **iter;
306  }
307  }
308  return s;
309  }
310 
311 private:
312 
315 };
316 
317 
318 #endif // GAUDI_OBJECTLIST_H

Generated at Wed Dec 4 2013 14:33:09 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004