| The Gaudi Framework v29r1 (5cd95fa2)

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

- File List
- File Members

SharedObjectsContainer.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_SHAREDOBJECTSCONTAINER_H
2 #define GAUDIKERNEL_SHAREDOBJECTSCONTAINER_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <algorithm>
9 #include <vector>
10 // ============================================================================
11 // GaudiKernel
12 // ============================================================================
13 #include "GaudiKernel/ClassID.h"
14 #include "GaudiKernel/Kernel.h"
15 #include "GaudiKernel/ObjectContainerBase.h"
16 // ============================================================================
28 template <class TYPE>
29 class SharedObjectsContainer : public ObjectContainerBase
30 {
31 public:
32 // ==========================================================================
34 typedef std::vector<const TYPE*> ConstVector;
36 typedef typename ConstVector::value_type value_type;
37 typedef typename ConstVector::size_type size_type;
38 typedef typename ConstVector::reference reference;
39 typedef typename ConstVector::const_reference const_reference;
40 typedef typename ConstVector::iterator iterator;
41 typedef typename ConstVector::const_iterator const_iterator;
42 typedef typename ConstVector::reverse_iterator reverse_iterator;
43 typedef typename ConstVector::const_reverse_iterator const_reverse_iterator;
44 // ==========================================================================
45 public:
46 // ==========================================================================
47 // the default constructor (creates the empty vector)
48 SharedObjectsContainer() = default;
49 // move constructor and move assignement
50 SharedObjectsContainer( SharedObjectsContainer&& ) = default;
51 SharedObjectsContainer& operator=( SharedObjectsContainer&& ) = default;
52 // the constructor from the data
53 SharedObjectsContainer( const ConstVector& data ) : m_data( data ) {}
54 SharedObjectsContainer( ConstVector&& data ) : m_data( std::move( data ) ) {}
55
60 template <class DATA>
61 SharedObjectsContainer( DATA first, DATA last ) : m_data( first, last )
62 {
63 }
87 template <class DATA, class PREDICATE>
88 SharedObjectsContainer( DATA first, DATA last, const PREDICATE& cut )
89 {
90 insert( first, last, cut );
91 }
92 // ==========================================================================
93 public:
94 // ==========================================================================
96 const CLID& clID() const override { return SharedObjectsContainer<TYPE>::classID(); }
98 static const CLID& classID()
99 {
100 static const CLID s_clid = ( ( static_cast<CLID>( -1 ) << 16 ) // 16 used and 16 empty bits
101 & !CLID_ObjectVector // not an ObjectVector
102 & !CLID_ObjectList // not an ObjectList
103 & !static_cast<CLID>( 0x00030000 ) // not a KeyedContainer/map
104 & !static_cast<CLID>( 0x00040000 ) ) // not a KeyedContainer/hashmap
105 + TYPE::classID(); // the specific CLID from the contents
106 //
107 return s_clid;
108 }
109 // ==========================================================================
110 public:
111 // ==========================================================================
113 inline const ConstVector& data() const { return m_data; }
115 operator const ConstVector&() const { return data(); }
116 // ==========================================================================
117 public:
118 // ==========================================================================
120 size_type size() const { return m_data.size(); }
122 bool empty() const { return m_data.empty(); }
126 void push_back( const TYPE* object ) { m_data.push_back( object ); }
130 void insert( const TYPE* object ) { m_data.push_back( object ); }
135 template <class DATA>
136 void insert( DATA first, DATA last )
137 {
138 m_data.insert( end(), first, last );
139 }
166 template <class DATA, class PREDICATE>
167 void insert( DATA first, DATA last, const PREDICATE& cut )
168 {
169 m_data.reserve( m_data.size() + std::distance( first, last ) );
170 std::copy_if( first, last, std::back_inserter( m_data ), std::cref( cut ) );
171 }
196 template <class OUTPUT, class PREDICATE>
197 OUTPUT get( const PREDICATE& cut, OUTPUT output ) const
198 {
199 return std::copy_if( begin(), end(), output, std::cref( cut ) );
200 }
202 void erase( iterator i ) { m_data.erase( i ); }
220 template <class PREDICATE>
221 void erase( const PREDICATE& cut )
222 {
223 m_data.erase( std::remove_if( begin(), end(), cut ), end() );
224 }
243 bool erase( const TYPE* object )
244 {
245 auto i = std::find( begin(), end(), object );
246 if ( end() == i ) {
247 return false;
248 }
249 m_data.erase( i );
250 return true;
251 }
252 // ==========================================================================
253 public:
254 // ==========================================================================
256 reference operator[]( size_type index ) { return m_data[index]; }
258 const_reference operator[]( size_type index ) const { return m_data[index]; }
260 reference operator()( size_type index ) { return m_data[index]; }
262 const_reference operator()( size_type index ) const { return m_data[index]; }
264 reference at( size_type index ) { return m_data.at( index ); }
266 const_reference at( size_type index ) const { return m_data.at( index ); }
267 // ==========================================================================
268 public:
269 // ==========================================================================
270 iterator begin() { return m_data.begin(); }
271 iterator end() { return m_data.end(); }
272 const_iterator begin() const { return m_data.begin(); }
273 const_iterator end() const { return m_data.end(); }
274 reverse_iterator rbegin() { return m_data.rbegin(); }
275 reverse_iterator rend() { return m_data.rend(); }
276 const_reverse_iterator rbegin() const { return m_data.rbegin(); }
277 const_reverse_iterator rend() const { return m_data.rend(); }
278 // ==========================================================================
279 public:
280 // ==========================================================================
282 reference front() { return m_data.front(); }
284 const_reference front() const { return m_data.front(); }
286 reference back() { return m_data.back(); }
288 const_reference back() const { return m_data.back(); }
289 // ==========================================================================
290 public:
291 // ==========================================================================
293 bool operator==( const SharedObjectsContainer& right ) const { return &right == this || right.m_data == m_data; }
295 bool operator==( const ConstVector& right ) const { return m_data == right; }
297 bool operator<( const SharedObjectsContainer& right ) const { return m_data < right.m_data; }
299 bool operator<( const ConstVector& right ) const { return m_data < right; }
300 // ==========================================================================
301 // ObjectContainerBase methods:
302 // ==========================================================================
303 public:
307 long index( const ContainedObject* object ) const override
308 {
309 auto _i = std::find( begin(), end(), object );
310 return end() != _i ? ( _i - begin() ) : -1; // RETURN
311 }
316 ContainedObject* containedObject( long index ) const override
317 {
318 if ( 0 > index || !( index < (long)size() ) ) {
319 return nullptr;
320 } // RETURN
321 const ContainedObject* co = m_data[index];
322 return const_cast<ContainedObject*>( co );
323 }
325 size_type numberOfObjects() const override { return m_data.size(); }
330 long add( ContainedObject* object ) override
331 {
332 if ( !object ) {
333 return -1;
334 } // RETURN
335 TYPE* _obj = dynamic_cast<TYPE*>( object );
336 if ( !_obj ) {
337 return -1;
338 } // RETURN
339 const size_type pos = size();
340 push_back( _obj );
341 return pos;
342 }
347 long remove( ContainedObject* value ) override
348 {
349 auto _i = std::find( begin(), end(), value );
350 if ( end() == _i ) {
351 return -1;
352 } // RETURN
353 const size_type pos = _i - begin();
354 m_data.erase( _i );
355 return pos; // RETURN
356 }
357 // ==========================================================================
358 private:
359 // ==========================================================================
360 // the actual data
361 ConstVector m_data; // the actual data
362 // ==========================================================================
363 };
364 // ============================================================================
365 // The END
366 // ============================================================================
367 #endif // GAUDIKERNEL_SHAREDOBJECTSCONTAINER_H
368 // ============================================================================
SharedObjectsContainer::erase
bool erase(const TYPE *object)
erase the first occurance of the certain element
Definition: SharedObjectsContainer.h:243
SharedObjectsContainer::front
reference front()
the first element (only for non-empty vectors)
Definition: SharedObjectsContainer.h:282
SharedObjectsContainer
Very simple class to represent the container of objects which are not owned by this container...
Definition: SharedObjectsContainer.h:29
SharedObjectsContainer::containedObject
ContainedObject * containedObject(long index) const override
Pointer to an object of a given distance.
Definition: SharedObjectsContainer.h:316
ClassID.h
Kernel.h
std::vector::empty
T empty(T...args)
SharedObjectsContainer::at
const_reference at(size_type index) const
checked access (const-version)
Definition: SharedObjectsContainer.h:266
std::copy_if
T copy_if(T...args)
SharedObjectsContainer::operator==
bool operator==(const ConstVector &right) const
equal content with corresponding vector ?
Definition: SharedObjectsContainer.h:295
std::distance
T distance(T...args)
SharedObjectsContainer::operator()
reference operator()(size_type index)
&#39;functional&#39;-access
Definition: SharedObjectsContainer.h:260
SharedObjectsContainer::begin
const_iterator begin() const
Definition: SharedObjectsContainer.h:272
SharedObjectsContainer::erase
void erase(const PREDICATE &cut)
erase the objects which satisfy the criteria
Definition: SharedObjectsContainer.h:221
SharedObjectsContainer::operator==
bool operator==(const SharedObjectsContainer &right) const
equal content with other container ?
Definition: SharedObjectsContainer.h:293
gaudirun.output
output
Definition: gaudirun.py:404
std::vector::rend
T rend(T...args)
SharedObjectsContainer::push_back
void push_back(const TYPE *object)
insert one object into the container
Definition: SharedObjectsContainer.h:126
std::vector::front
T front(T...args)
SharedObjectsContainer::operator<
bool operator<(const SharedObjectsContainer &right) const
comparisons with other container
Definition: SharedObjectsContainer.h:297
SharedObjectsContainer::size_type
ConstVector::size_type size_type
Definition: SharedObjectsContainer.h:37
std
STL namespace.
ObjectContainerBase.h
SharedObjectsContainer::reverse_iterator
ConstVector::reverse_iterator reverse_iterator
Definition: SharedObjectsContainer.h:42
std::vector::end
T end(T...args)
SharedObjectsContainer::size
size_type size() const
get the actual size of the container
Definition: SharedObjectsContainer.h:120
SharedObjectsContainer::numberOfObjects
size_type numberOfObjects() const override
Number of objects in the container.
Definition: SharedObjectsContainer.h:325
std::remove_if
T remove_if(T...args)
SharedObjectsContainer::SharedObjectsContainer
SharedObjectsContainer(DATA first, DATA last, const PREDICATE &cut)
the templated constructor from the pair of iterators and the predicate.
Definition: SharedObjectsContainer.h:88
SharedObjectsContainer::insert
void insert(DATA first, DATA last, const PREDICATE &cut)
add the sequence of &#39;good&#39;objects into the container
Definition: SharedObjectsContainer.h:167
SharedObjectsContainer::rbegin
reverse_iterator rbegin()
Definition: SharedObjectsContainer.h:274
SharedObjectsContainer::iterator
ConstVector::iterator iterator
Definition: SharedObjectsContainer.h:40
SharedObjectsContainer::const_reference
ConstVector::const_reference const_reference
Definition: SharedObjectsContainer.h:39
std::vector::at
T at(T...args)
SharedObjectsContainer::insert
void insert(const TYPE *object)
insert one object into the container
Definition: SharedObjectsContainer.h:130
std::vector::push_back
T push_back(T...args)
SharedObjectsContainer::front
const_reference front() const
the first element (only for non-empty vectors) (const-version)
Definition: SharedObjectsContainer.h:284
SharedObjectsContainer::end
const_iterator end() const
Definition: SharedObjectsContainer.h:273
SharedObjectsContainer::rbegin
const_reverse_iterator rbegin() const
Definition: SharedObjectsContainer.h:276
SharedObjectsContainer::const_iterator
ConstVector::const_iterator const_iterator
Definition: SharedObjectsContainer.h:41
SharedObjectsContainer::begin
iterator begin()
Definition: SharedObjectsContainer.h:270
SharedObjectsContainer::operator()
const_reference operator()(size_type index) const
&#39;functional&#39;-access (const version)
Definition: SharedObjectsContainer.h:262
SharedObjectsContainer::SharedObjectsContainer
SharedObjectsContainer(const ConstVector &data)
Definition: SharedObjectsContainer.h:53
SharedObjectsContainer::back
const_reference back() const
the last element (only for non-empty vectors) (const-version)
Definition: SharedObjectsContainer.h:288
SharedObjectsContainer::operator[]
const_reference operator[](size_type index) const
index access (const-version)
Definition: SharedObjectsContainer.h:258
SharedObjectsContainer::data
const ConstVector & data() const
get the access to the underlying container (const)
Definition: SharedObjectsContainer.h:113
std::vector::erase
T erase(T...args)
SharedObjectsContainer::end
iterator end()
Definition: SharedObjectsContainer.h:271
SharedObjectsContainer::at
reference at(size_type index)
checked access
Definition: SharedObjectsContainer.h:264
SharedObjectsContainer::index
long index(const ContainedObject *object) const override
Distance of a given object from the beginning of its container.
Definition: SharedObjectsContainer.h:307
SharedObjectsContainer::add
long add(ContainedObject *object) override
Virtual functions (forwards to the concrete container definitions) Add an object to the container...
Definition: SharedObjectsContainer.h:330
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
SharedObjectsContainer::SharedObjectsContainer
SharedObjectsContainer()=default
SharedObjectsContainer::empty
bool empty() const
empty container?
Definition: SharedObjectsContainer.h:122
SharedObjectsContainer::rend
reverse_iterator rend()
Definition: SharedObjectsContainer.h:275
SharedObjectsContainer::operator[]
reference operator[](size_type index)
index access
Definition: SharedObjectsContainer.h:256
SharedObjectsContainer::operator=
SharedObjectsContainer & operator=(SharedObjectsContainer &&)=default
SharedObjectsContainer::ConstVector
std::vector< const TYPE * > ConstVector
the actual container type
Definition: SharedObjectsContainer.h:34
std::vector::insert
T insert(T...args)
ContainedObject
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
Definition: ContainedObject.h:31
std::find
T find(T...args)
SharedObjectsContainer::rend
const_reverse_iterator rend() const
Definition: SharedObjectsContainer.h:277
std::vector::size
T size(T...args)
SharedObjectsContainer::SharedObjectsContainer
SharedObjectsContainer(ConstVector &&data)
Definition: SharedObjectsContainer.h:54
std::vector< const TYPE * >
std::cref
T cref(T...args)
std::vector::begin
T begin(T...args)
std::back_inserter
T back_inserter(T...args)
SharedObjectsContainer::classID
static const CLID & classID()
Retrieve the unuqie class ID (static)
Definition: SharedObjectsContainer.h:98
std::vector::back
T back(T...args)
SharedObjectsContainer::reference
ConstVector::reference reference
Definition: SharedObjectsContainer.h:38
SharedObjectsContainer::back
reference back()
the last element (only for non-empty vectors)
Definition: SharedObjectsContainer.h:286
ObjectContainerBase
ObjectContainerBase is the base class for Gaudi container classes.
Definition: ObjectContainerBase.h:19
SharedObjectsContainer::insert
void insert(DATA first, DATA last)
add the sequence of objects into the container
Definition: SharedObjectsContainer.h:136
SharedObjectsContainer::operator<
bool operator<(const ConstVector &right) const
comparisons with corresponding vector
Definition: SharedObjectsContainer.h:299
SharedObjectsContainer::clID
const CLID & clID() const override
Retrieve the unique class ID (virtual)
Definition: SharedObjectsContainer.h:96
SharedObjectsContainer::SharedObjectsContainer
SharedObjectsContainer(DATA first, DATA last)
the templated constructor from the pair of iterators
Definition: SharedObjectsContainer.h:61
Objects::reference
TO * reference(FROM *from)
Definition: KeyedObject.cpp:21
SharedObjectsContainer::m_data
ConstVector m_data
Definition: SharedObjectsContainer.h:361
std::vector::reserve
T reserve(T...args)
SharedObjectsContainer::erase
void erase(iterator i)
erase the object by iterator
Definition: SharedObjectsContainer.h:202
SharedObjectsContainer::const_reverse_iterator
ConstVector::const_reverse_iterator const_reverse_iterator
Definition: SharedObjectsContainer.h:43
std::vector::rbegin
T rbegin(T...args)
SharedObjectsContainer::value_type
ConstVector::value_type value_type
various types (to make STL happy)
Definition: SharedObjectsContainer.h:36