| The Gaudi Framework v28r2-patches (bc4ad17a)

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

- File List
- File Members

ObjectList.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_OBJECTLIST_H
2 #define GAUDIKERNEL_OBJECTLIST_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 <list>
12 #include <iomanip>
13
14
15 // Definition of the CLID for this class defined in ClassID.h
16 // static const CLID CLID_ObjectList = (1<<18); // ObjectList (bit 18 set)
17
36 template <class TYPE>
37 class ObjectList : public ObjectContainerBase {
38
39 public:
40 typedef TYPE contained_type;
41 typedef typename std::list<TYPE*>::value_type value_type;
42
43 typedef typename std::list<TYPE*>::reference reference;
44 typedef typename std::list<TYPE*>::const_reference const_reference;
45
46 typedef typename std::list<TYPE*>::iterator iterator;
47 typedef typename std::list<TYPE*>::const_iterator const_iterator;
48
49 typedef typename std::list<TYPE*>::reverse_iterator reverse_iterator;
50 typedef typename std::list<TYPE*>::const_reverse_iterator const_reverse_iterator;
51
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 ObjectList() = default;
63
64 ObjectList( const ObjectList<TYPE>& ) = delete;
65 ObjectList& operator=( const ObjectList<TYPE>& ) = delete;
66
68 ~ObjectList() override {
69 clear();
70 }
71
73 const CLID& clID() const override {
74 return ObjectList<TYPE>::classID();
75 }
76 static const CLID& classID() {
77 static CLID clid = TYPE::classID() + CLID_ObjectList;
78 return clid;
79 }
80
82 typename ObjectList<TYPE>::iterator begin () {
83 return m_list.begin();
84 }
85
87 typename ObjectList<TYPE>::const_iterator begin () const {
88 return m_list.begin();
89 }
90
92 typename ObjectList<TYPE>::iterator end () {
93 return m_list.end();
94 }
95
97 typename ObjectList<TYPE>::const_iterator end () const {
98 return m_list.end();
99 }
100
103 typename ObjectList<TYPE>::reverse_iterator rbegin () {
104 return m_list.rbegin();
105 }
106
108 typename ObjectList<TYPE>::const_reverse_iterator rbegin () const {
109 return m_list.rbegin();
110 }
111
113 typename ObjectList<TYPE>::reverse_iterator rend () {
114 return m_list.rend();
115 }
116
118 typename ObjectList<TYPE>::const_reverse_iterator rend () const {
119 return m_list.rend();
120 }
121
124 typename ObjectList<TYPE>::size_type size () const {
125 // C++11: std::list::size is constant (pre C++11 it could be linear!)
126 return m_list.size();
127 }
129 typename ObjectList<TYPE>::size_type numberOfObjects() const override {
130 return m_list.size();
131 }
132
134 typename ObjectList<TYPE>::size_type max_size () const {
135 return m_list.max_size();
136 }
137
139 bool empty () const {
140 return m_list.empty();
141 }
142
144 typename ObjectList<TYPE>::reference front () {
145 return m_list.front();
146 }
147
149 typename ObjectList<TYPE>::const_reference front () const {
150 return m_list.front();
151 }
152
154 typename ObjectList<TYPE>::reference back () {
155 return m_list.back();
156 }
157
159 typename ObjectList<TYPE>::const_reference back () const {
160 return m_list.back();
161 }
162
164 void push_back( typename ObjectList<TYPE>::const_reference value ) {
165 if( value->parent() ) {
166 const_cast<ObjectContainerBase*>(value->parent())->remove(value);
167 }
168 value->setParent(this);
169 m_list.push_back(value);
170 }
171
173 long add(ContainedObject* pObject) override {
174 try {
175 auto ptr = dynamic_cast<typename ObjectList<TYPE>::value_type>(pObject);
176 if ( ptr ) {
177 push_back(ptr);
178 return m_list.size()-1;
179 }
180 }
181 catch(...) {
182 }
183 return -1;
184 }
185
188 void pop_back () {
189 auto position = m_list.back();
190 // Set the back pointer to 0 to avoid repetitional searching
191 // for the object in the container, and deleting the object
192 position->setParent (nullptr);
193 delete position;
194 // Removing from the container itself
195 m_list.pop_back();
196 }
197
200 long remove(ContainedObject* value) override {
201 // Find the object of value value
202 long idx = 0;
203 auto iter = std::find_if( begin(), end(), [&](const ContainedObject* i) { return i == value; } );
204 if( iter == end() ) {
205 // Object cannot be released from the container,
206 // as it is not contained in it
207 return -1;
208 }
209
210 // Set the back pointer to 0 to avoid repetitional searching
211 // for the object in the container and deleting the object
212 (*iter)->setParent(nullptr);
213 erase(iter);
214 return idx;
215 }
216
218 typename ObjectList<TYPE>::iterator insert( typename ObjectList<TYPE>::iterator position,
219 typename ObjectList<TYPE>::const_reference value ) {
220 value->setParent(this);
221 return m_list.insert(position, value);
222 }
223
225 void erase( typename ObjectList<TYPE>::iterator position ) {
226 if( (*position)->parent() ) {
227 // Set the back pointer to 0 to avoid repetitional searching
228 // for the object in the container, and deleting the object
229 (*position)->setParent(nullptr);
230 delete *position;
231 }
232 // Removing from the container itself
233 m_list.erase(position);
234 }
235
237 void erase( typename ObjectList<TYPE>::iterator first,
238 typename ObjectList<TYPE>::iterator last ) {
239 for( auto iter = first; iter != last; ++iter ) {
240 // Set the back pointer to 0 to avoid repetitional searching
241 // for the object in the container, and deleting the object
242 (*iter)->setParent(nullptr);
243 delete *iter;
244 }
245 // Removing from the container itself
246 m_list.erase(first, last);
247 }
248
250 void clear() {
251 erase(begin(), end());
252 }
253
256 long index( const ContainedObject* obj ) const override {
257 auto i = std::find_if(begin(),end(),
258 [&](const ContainedObject* o)
259 { return o == obj; } );
260 return i!=end() ? std::distance( begin(), i ) : -1 ;
261 }
262
264 ContainedObject* containedObject( long dist ) const override {
265 return dist < size() ? *std::next( begin(), dist ) : nullptr;
266 }
267
269 std::ostream& fillStream( std::ostream& s ) const override {
270 s << "class ObjectList : size = "
271 << std::setw(12)
272 << size() << "\n";
273 // Output the base class
274 //ObjectContainerBase::fillStream(s);
275 if ( !empty() ) {
276 s << "\nContents of the STL list :";
277 long count = 0;
278 for( const auto& iter : m_list ) {
279 s << "\nIndex "
280 << std::setw(12)
281 << count++
282 << " of object of type "<< *iter;
283 }
284 }
285 return s;
286 }
287
288 private:
290 std::list<TYPE*> m_list;
291 };
292
293
294 #endif // GAUDI_OBJECTLIST_H
ObjectList::pointer
std::vector< TYPE * >::pointer pointer
Definition: ObjectList.h:56
ObjectList::rend
ObjectList< TYPE >::const_reverse_iterator rend() const
Return a const_reverse_iterator pointing to the end of the reversed container.
Definition: ObjectList.h:118
ClassID.h
Kernel.h
std::list::empty
T empty(T...args)
std::distance
T distance(T...args)
ObjectList::contained_type
TYPE contained_type
Definition: ObjectList.h:40
ObjectContainerBase::size_type
size_t size_type
size_type, to conform the STL container interface
Definition: ObjectContainerBase.h:31
ObjectList::numberOfObjects
ObjectList< TYPE >::size_type numberOfObjects() const override
The same as size(), return number of objects in the container.
Definition: ObjectList.h:129
ObjectList::pop_back
void pop_back()
pop_back = remove the last element from the container The removed object will be deleted (see the met...
Definition: ObjectList.h:188
ObjectList::insert
ObjectList< TYPE >::iterator insert(typename ObjectList< TYPE >::iterator position, typename ObjectList< TYPE >::const_reference value)
Insert "value" before "position".
Definition: ObjectList.h:218
std::list::rend
T rend(T...args)
std::list::front
T front(T...args)
ObjectList::operator=
ObjectList & operator=(const ObjectList< TYPE > &)=delete
ObjectList::begin
ObjectList< TYPE >::const_iterator begin() const
Return a const_iterator pointing to the beginning of the container.
Definition: ObjectList.h:87
ObjectContainerBase.h
std::list::end
T end(T...args)
ObjectList::empty
bool empty() const
Return true if the size of the container is 0.
Definition: ObjectList.h:139
ObjectList::size
ObjectList< TYPE >::size_type size() const
Return the size of the container Size means the number of objects stored in the container, independently on the amount of information stored in each object.
Definition: ObjectList.h:124
ObjectList::containedObject
ContainedObject * containedObject(long dist) const override
Return const pointer to an object of a given distance.
Definition: ObjectList.h:264
ObjectList::const_reference
std::list< TYPE * >::const_reference const_reference
Definition: ObjectList.h:44
StreamBuffer.h
ObjectList::const_iterator
std::list< TYPE * >::const_iterator const_iterator
Definition: ObjectList.h:47
std::setw
T setw(T...args)
ObjectList
ObjectList is one of the basic Gaudi container classes capable of being registered in Data Stores...
Definition: ContainedObject.h:12
ObjectList::reverse_iterator
std::list< TYPE * >::reverse_iterator reverse_iterator
Definition: ObjectList.h:49
ObjectList::clID
const CLID & clID() const override
Retrieve pointer to class definition structure.
Definition: ObjectList.h:73
std::list::push_back
T push_back(T...args)
ObjectList::reference
std::list< TYPE * >::reference reference
Definition: ObjectList.h:43
ObjectList::~ObjectList
~ObjectList() override
Destructor.
Definition: ObjectList.h:68
ObjectList::value_type
std::list< TYPE * >::value_type value_type
Definition: ObjectList.h:41
ObjectList::rbegin
ObjectList< TYPE >::const_reverse_iterator rbegin() const
Return a const_reverse_iterator pointing to the beginning of the reversed container.
Definition: ObjectList.h:108
std::next
T next(T...args)
ObjectList::rbegin
ObjectList< TYPE >::reverse_iterator rbegin()
Return a reverse_iterator pointing to the beginning of the reversed container.
Definition: ObjectList.h:103
std::list::erase
T erase(T...args)
ObjectList::end
ObjectList< TYPE >::const_iterator end() const
Return a const_iterator pointing to the end of the container.
Definition: ObjectList.h:97
ObjectList::begin
ObjectList< TYPE >::iterator begin()
Return an iterator pointing to the beginning of the container.
Definition: ObjectList.h:82
std::list::pop_back
T pop_back(T...args)
ObjectList::rend
ObjectList< TYPE >::reverse_iterator rend()
Return a reverse_iterator pointing to the end of the reversed container.
Definition: ObjectList.h:113
ObjectList::back
ObjectList< TYPE >::const_reference back() const
Return const_reference to the last element.
Definition: ObjectList.h:159
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
std::list
STL class.
ObjectList::back
ObjectList< TYPE >::reference back()
Return reference to the last element.
Definition: ObjectList.h:154
ObjectList::iterator
std::list< TYPE * >::iterator iterator
Definition: ObjectList.h:46
ObjectList::m_list
std::list< TYPE * > m_list
The STL list.
Definition: ObjectList.h:290
std::list::insert
T insert(T...args)
ObjectList::classID
static const CLID & classID()
Definition: ObjectList.h:76
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)
ObjectList::ObjectList
ObjectList()=default
Constructors.
std::list::size
T size(T...args)
std::vector
STL class.
ObjectList::front
ObjectList< TYPE >::reference front()
Return reference to the first element.
Definition: ObjectList.h:144
ObjectList::fillStream
std::ostream & fillStream(std::ostream &s) const override
Fill the output stream (ASCII)
Definition: ObjectList.h:269
ObjectList::max_size
ObjectList< TYPE >::size_type max_size() const
Return the largest possible size of the container.
Definition: ObjectList.h:134
ObjectList::const_reverse_iterator
std::list< TYPE * >::const_reverse_iterator const_reverse_iterator
Definition: ObjectList.h:50
std::list::begin
T begin(T...args)
ObjectList::erase
void erase(typename ObjectList< TYPE >::iterator first, typename ObjectList< TYPE >::iterator last)
Erase the range [first, last) from the container. The removed object will be deleted.
Definition: ObjectList.h:237
std::list::max_size
T max_size(T...args)
ObjectList::index
long index(const ContainedObject *obj) const override
Return distance of a given object from the beginning of its container It corresponds to the "index" (...
Definition: ObjectList.h:256
std::list::back
T back(T...args)
gaudirun.s
string s
Definition: gaudirun.py:245
ObjectList::clear
void clear()
Clear the entire content of the container and delete all contained objects.
Definition: ObjectList.h:250
ObjectList::push_back
void push_back(typename ObjectList< TYPE >::const_reference value)
push_back = append = insert a new element at the end of the container
Definition: ObjectList.h:164
ObjectList::add
long add(ContainedObject *pObject) override
Add an object to the container.
Definition: ObjectList.h:173
ObjectContainerBase
ObjectContainerBase is the base class for Gaudi container classes.
Definition: ObjectContainerBase.h:19
ObjectList::const_pointer
std::vector< TYPE * >::const_pointer const_pointer
Definition: ObjectList.h:57
ObjectList::erase
void erase(typename ObjectList< TYPE >::iterator position)
Erase the object at "position" from the container. The removed object will be deleted.
Definition: ObjectList.h:225
std::ostream
STL class.
ObjectList::front
ObjectList< TYPE >::const_reference front() const
Return const_reference to the first element.
Definition: ObjectList.h:149
ObjectList::end
ObjectList< TYPE >::iterator end()
Return an iterator pointing to the end of the container.
Definition: ObjectList.h:92
std::list::rbegin
T rbegin(T...args)