| The Gaudi Framework v30r0 (c919700c)

- 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 // Include files
5 #include "GaudiKernel/ClassID.h"
6 #include "GaudiKernel/Kernel.h"
7 #include "GaudiKernel/ObjectContainerBase.h"
8 #include "GaudiKernel/StreamBuffer.h"
9
10 #include <iomanip>
11 #include <list>
12
13 // Definition of the CLID for this class defined in ClassID.h
14 // static const CLID CLID_ObjectList = (1<<18); // ObjectList (bit 18 set)
15
34 template <class TYPE>
35 class ObjectList : public ObjectContainerBase
36 {
37
38 public:
39 typedef TYPE contained_type;
40 typedef typename std::list<TYPE*>::value_type value_type;
41
42 typedef typename std::list<TYPE*>::reference reference;
43 typedef typename std::list<TYPE*>::const_reference const_reference;
44
45 typedef typename std::list<TYPE*>::iterator iterator;
46 typedef typename std::list<TYPE*>::const_iterator const_iterator;
47
48 typedef typename std::list<TYPE*>::reverse_iterator reverse_iterator;
49 typedef typename std::list<TYPE*>::const_reverse_iterator const_reverse_iterator;
50
51 #ifdef _WIN32
52 typedef typename std::vector<TYPE*>::_Tptr pointer;
53 typedef typename std::vector<TYPE*>::_Ctptr const_pointer;
54 #else
55 typedef typename std::vector<TYPE*>::pointer pointer;
56 typedef typename std::vector<TYPE*>::const_pointer const_pointer;
57 #endif
58
59 public:
61 ObjectList() = default;
62
63 ObjectList( const ObjectList<TYPE>& ) = delete;
64 ObjectList& operator=( const ObjectList<TYPE>& ) = delete;
65
67 ~ObjectList() override { clear(); }
68
70 const CLID& clID() const override { return ObjectList<TYPE>::classID(); }
71 static const CLID& classID()
72 {
73 static CLID clid = TYPE::classID() + CLID_ObjectList;
74 return clid;
75 }
76
78 typename ObjectList<TYPE>::iterator begin() { return m_list.begin(); }
79
81 typename ObjectList<TYPE>::const_iterator begin() const { return m_list.begin(); }
82
84 typename ObjectList<TYPE>::iterator end() { return m_list.end(); }
85
87 typename ObjectList<TYPE>::const_iterator end() const { return m_list.end(); }
88
91 typename ObjectList<TYPE>::reverse_iterator rbegin() { return m_list.rbegin(); }
92
94 typename ObjectList<TYPE>::const_reverse_iterator rbegin() const { return m_list.rbegin(); }
95
97 typename ObjectList<TYPE>::reverse_iterator rend() { return m_list.rend(); }
98
100 typename ObjectList<TYPE>::const_reverse_iterator rend() const { return m_list.rend(); }
101
105 typename ObjectList<TYPE>::size_type size() const
106 {
107 // C++11: std::list::size is constant (pre C++11 it could be linear!)
108 return m_list.size();
109 }
111 typename ObjectList<TYPE>::size_type numberOfObjects() const override { return m_list.size(); }
112
114 typename ObjectList<TYPE>::size_type max_size() const { return m_list.max_size(); }
115
117 bool empty() const { return m_list.empty(); }
118
120 typename ObjectList<TYPE>::reference front() { return m_list.front(); }
121
123 typename ObjectList<TYPE>::const_reference front() const { return m_list.front(); }
124
126 typename ObjectList<TYPE>::reference back() { return m_list.back(); }
127
129 typename ObjectList<TYPE>::const_reference back() const { return m_list.back(); }
130
132 void push_back( typename ObjectList<TYPE>::const_reference value )
133 {
134 if ( value->parent() ) {
135 const_cast<ObjectContainerBase*>( value->parent() )->remove( value );
136 }
137 value->setParent( this );
138 m_list.push_back( value );
139 }
140
142 long add( ContainedObject* pObject ) override
143 {
144 try {
145 auto ptr = dynamic_cast<typename ObjectList<TYPE>::value_type>( pObject );
146 if ( ptr ) {
147 push_back( ptr );
148 return m_list.size() - 1;
149 }
150 } catch ( ... ) {
151 }
152 return -1;
153 }
154
157 void pop_back()
158 {
159 auto position = m_list.back();
160 // Set the back pointer to 0 to avoid repetitional searching
161 // for the object in the container, and deleting the object
162 position->setParent( nullptr );
163 delete position;
164 // Removing from the container itself
165 m_list.pop_back();
166 }
167
170 long remove( ContainedObject* value ) override
171 {
172 // Find the object of value value
173 long idx = 0;
174 auto iter = std::find_if( begin(), end(), [&]( const ContainedObject* i ) { return i == value; } );
175 if ( iter == end() ) {
176 // Object cannot be released from the container,
177 // as it is not contained in it
178 return -1;
179 }
180
181 // Set the back pointer to 0 to avoid repetitional searching
182 // for the object in the container and deleting the object
183 ( *iter )->setParent( nullptr );
184 erase( iter );
185 return idx;
186 }
187
189 typename ObjectList<TYPE>::iterator insert( typename ObjectList<TYPE>::iterator position,
190 typename ObjectList<TYPE>::const_reference value )
191 {
192 value->setParent( this );
193 return m_list.insert( position, value );
194 }
195
197 void erase( typename ObjectList<TYPE>::iterator position )
198 {
199 if ( ( *position )->parent() ) {
200 // Set the back pointer to 0 to avoid repetitional searching
201 // for the object in the container, and deleting the object
202 ( *position )->setParent( nullptr );
203 delete *position;
204 }
205 // Removing from the container itself
206 m_list.erase( position );
207 }
208
210 void erase( typename ObjectList<TYPE>::iterator first, typename ObjectList<TYPE>::iterator last )
211 {
212 for ( auto iter = first; iter != last; ++iter ) {
213 // Set the back pointer to 0 to avoid repetitional searching
214 // for the object in the container, and deleting the object
215 ( *iter )->setParent( nullptr );
216 delete *iter;
217 }
218 // Removing from the container itself
219 m_list.erase( first, last );
220 }
221
223 void clear() { erase( begin(), end() ); }
224
227 long index( const ContainedObject* obj ) const override
228 {
229 auto i = std::find_if( begin(), end(), [&]( const ContainedObject* o ) { return o == obj; } );
230 return i != end() ? std::distance( begin(), i ) : -1;
231 }
232
234 ContainedObject* containedObject( long dist ) const override
235 {
236 return dist < size() ? *std::next( begin(), dist ) : nullptr;
237 }
238
240 std::ostream& fillStream( std::ostream& s ) const override
241 {
242 s << "class ObjectList : size = " << std::setw( 12 ) << size() << "\n";
243 // Output the base class
244 // ObjectContainerBase::fillStream(s);
245 if ( !empty() ) {
246 s << "\nContents of the STL list :";
247 long count = 0;
248 for ( const auto& iter : m_list ) {
249 s << "\nIndex " << std::setw( 12 ) << count++ << " of object of type " << *iter;
250 }
251 }
252 return s;
253 }
254
255 private:
257 std::list<TYPE*> m_list;
258 };
259
260 #endif // GAUDI_OBJECTLIST_H
ObjectList::pointer
std::vector< TYPE * >::pointer pointer
Definition: ObjectList.h:55
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:100
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:39
ObjectContainerBase::size_type
size_t size_type
size_type, to conform the STL container interface
Definition: ObjectContainerBase.h:30
ObjectList::numberOfObjects
ObjectList< TYPE >::size_type numberOfObjects() const override
The same as size(), return number of objects in the container.
Definition: ObjectList.h:111
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:157
ObjectList::insert
ObjectList< TYPE >::iterator insert(typename ObjectList< TYPE >::iterator position, typename ObjectList< TYPE >::const_reference value)
Insert "value" before "position".
Definition: ObjectList.h:189
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:81
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:117
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:105
ObjectList::containedObject
ContainedObject * containedObject(long dist) const override
Return const pointer to an object of a given distance.
Definition: ObjectList.h:234
ObjectList::const_reference
std::list< TYPE * >::const_reference const_reference
Definition: ObjectList.h:43
StreamBuffer.h
ObjectList::const_iterator
std::list< TYPE * >::const_iterator const_iterator
Definition: ObjectList.h:46
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:14
ObjectList::reverse_iterator
std::list< TYPE * >::reverse_iterator reverse_iterator
Definition: ObjectList.h:48
ObjectList::clID
const CLID & clID() const override
Retrieve pointer to class definition structure.
Definition: ObjectList.h:70
std::list::push_back
T push_back(T...args)
ObjectList::reference
std::list< TYPE * >::reference reference
Definition: ObjectList.h:42
ObjectList::~ObjectList
~ObjectList() override
Destructor.
Definition: ObjectList.h:67
ObjectList::value_type
std::list< TYPE * >::value_type value_type
Definition: ObjectList.h:40
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:94
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:91
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:87
ObjectList::begin
ObjectList< TYPE >::iterator begin()
Return an iterator pointing to the beginning of the container.
Definition: ObjectList.h:78
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:97
ObjectList::back
ObjectList< TYPE >::const_reference back() const
Return const_reference to the last element.
Definition: ObjectList.h:129
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:126
ObjectList::iterator
std::list< TYPE * >::iterator iterator
Definition: ObjectList.h:45
ObjectList::m_list
std::list< TYPE * > m_list
The STL list.
Definition: ObjectList.h:257
std::list::insert
T insert(T...args)
ObjectList::classID
static const CLID & classID()
Definition: ObjectList.h:71
ContainedObject
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
Definition: ContainedObject.h:31
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:120
ObjectList::fillStream
std::ostream & fillStream(std::ostream &s) const override
Fill the output stream (ASCII)
Definition: ObjectList.h:240
ObjectList::max_size
ObjectList< TYPE >::size_type max_size() const
Return the largest possible size of the container.
Definition: ObjectList.h:114
ObjectList::const_reverse_iterator
std::list< TYPE * >::const_reverse_iterator const_reverse_iterator
Definition: ObjectList.h:49
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:210
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:227
std::list::back
T back(T...args)
gaudirun.s
string s
Definition: gaudirun.py:253
ObjectList::clear
void clear()
Clear the entire content of the container and delete all contained objects.
Definition: ObjectList.h:223
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:132
ObjectList::add
long add(ContainedObject *pObject) override
Add an object to the container.
Definition: ObjectList.h:142
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:56
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:197
std::ostream
STL class.
ObjectList::front
ObjectList< TYPE >::const_reference front() const
Return const_reference to the first element.
Definition: ObjectList.h:123
ObjectList::end
ObjectList< TYPE >::iterator end()
Return an iterator pointing to the end of the container.
Definition: ObjectList.h:84
std::list::rbegin
T rbegin(T...args)