| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

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"
9 #include "GaudiKernel/StreamBuffer.h"
10 #include "GaudiKernel/ObjectContainerBase.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;
42 typedef typename std::list<TYPE*>::value_type value_type;
43
44 typedef typename std::list<TYPE*>::reference reference;
45 typedef typename std::list<TYPE*>::const_reference const_reference;
46
47 typedef typename std::list<TYPE*>::iterator iterator;
48 typedef typename std::list<TYPE*>::const_iterator const_iterator;
49
50 typedef typename std::list<TYPE*>::reverse_iterator reverse_iterator;
51 typedef typename std::list<TYPE*>::const_reverse_iterator const_reverse_iterator;
52
53 #ifdef _WIN32
54 typedef typename std::vector<TYPE*>::_Tptr pointer;
55 typedef typename std::vector<TYPE*>::_Ctptr const_pointer;
56 #else
57 typedef typename std::vector<TYPE*>::pointer pointer;
58 typedef typename std::vector<TYPE*>::const_pointer const_pointer;
59 #endif
60
61 public:
63 ObjectList()
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 {
76 return ObjectList<TYPE>::classID();
77 }
78 static const CLID& classID() {
79 static CLID clid = TYPE::classID() + CLID_ObjectList;
80 return clid;
81 }
82
84 typename ObjectList<TYPE>::iterator begin () {
85 return m_list.begin();
86 }
87
89 typename ObjectList<TYPE>::const_iterator begin () const {
90 return m_list.begin();
91 }
92
94 typename ObjectList<TYPE>::iterator end () {
95 return m_list.end();
96 }
97
99 typename ObjectList<TYPE>::const_iterator end () const {
100 return m_list.end();
101 }
102
105 typename ObjectList<TYPE>::reverse_iterator rbegin () {
106 return m_list.rbegin();
107 }
108
110 typename ObjectList<TYPE>::const_reverse_iterator rbegin () const {
111 return m_list.rbegin();
112 }
113
115 typename ObjectList<TYPE>::reverse_iterator rend () {
116 return m_list.rend();
117 }
118
120 typename ObjectList<TYPE>::const_reverse_iterator rend () const {
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
135 typename ObjectList<TYPE>::size_type max_size () const {
136 return m_list.max_size();
137 }
138
140 bool empty () const {
141 return m_list.empty();
142 }
143
145 typename ObjectList<TYPE>::reference front () {
146 return m_list.front();
147 }
148
150 typename ObjectList<TYPE>::const_reference front () const {
151 return m_list.front();
152 }
153
155 typename ObjectList<TYPE>::reference back () {
156 return m_list.back();
157 }
158
160 typename ObjectList<TYPE>::const_reference back () const {
161 return m_list.back();
162 }
163
165 void push_back( typename ObjectList<TYPE>::const_reference value ) {
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
226 typename ObjectList<TYPE>::iterator insert( typename ObjectList<TYPE>::iterator position,
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
314 std::list<TYPE*> m_list;
315 };
316
317
318 #endif // GAUDI_OBJECTLIST_H