| The Gaudi Framework v27r1

- 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 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/Kernel.h"
13 #include "GaudiKernel/ClassID.h"
14 #include "GaudiKernel/ObjectContainerBase.h"
15 // ============================================================================
27 template <class TYPE>
28 class SharedObjectsContainer : public ObjectContainerBase
29 {
30 public:
31 // ==========================================================================
33 typedef std::vector<const TYPE*> ConstVector ;
35 typedef typename ConstVector::value_type value_type ;
36 typedef typename ConstVector::size_type size_type ;
37 typedef typename ConstVector::reference reference ;
38 typedef typename ConstVector::const_reference const_reference ;
39 typedef typename ConstVector::iterator iterator ;
40 typedef typename ConstVector::const_iterator const_iterator ;
41 typedef typename ConstVector::reverse_iterator reverse_iterator ;
42 typedef typename ConstVector::const_reverse_iterator const_reverse_iterator ;
43 // ==========================================================================
44 public:
45 // ==========================================================================
46 // the default constructor (creates the empty vector)
47 SharedObjectsContainer ()
48 : ObjectContainerBase(), m_data() {} ;
49 // the constructor from the data
50 SharedObjectsContainer ( const ConstVector& data )
51 : ObjectContainerBase(), m_data(data) {}
56 template <class DATA>
57 SharedObjectsContainer(DATA first, DATA last)
58 : ObjectContainerBase(), m_data(first, last) {}
82 template <class DATA, class PREDICATE>
83 SharedObjectsContainer(DATA first, DATA last, const PREDICATE& cut)
84 : ObjectContainerBase(), m_data()
85 {
86 insert ( first , last , cut ) ;
87 }
89 virtual ~SharedObjectsContainer() { m_data.clear() ; }
90 // ==========================================================================
91 public:
92 // ==========================================================================
94 virtual const CLID& clID() const
95 { return SharedObjectsContainer<TYPE>::classID(); }
97 static const CLID& classID()
98 {
99 static const CLID s_clid =
100 ( ( 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
137 ( DATA first ,
138 DATA last ) { m_data.insert ( end() , first ,last ) ; }
165 template <class DATA, class PREDICATE>
166 void insert
167 ( DATA first ,
168 DATA last ,
169 const PREDICATE& cut )
170 {
171 m_data.reserve ( m_data.size() + std::distance ( first , last ) ) ;
172 for ( ; first != last ; ++first )
173 { if ( cut ( *first ) ) { m_data.push_back ( *first ) ; } }
174 }
202 template <class OUTPUT, class PREDICATE>
203 OUTPUT get ( const PREDICATE& cut ,
204 OUTPUT output ) const
205 {
206 std::copy_if( begin(), end(), output, std::cref(cut) );
207 return output ;
208 }
210 void erase ( iterator i ) { m_data.erase ( i ) ; }
228 template <class PREDICATE>
229 void erase ( const PREDICATE& cut )
230 { m_data.erase( std::remove_if ( begin() , end() , cut ) , end() ) ; }
249 bool erase ( const TYPE* object )
250 {
251 auto i = std::find ( begin() , end() , object ) ;
252 if ( end() == i ) { return false ; }
253 m_data.erase ( i ) ;
254 return true ;
255 }
256 // ==========================================================================
257 public:
258 // ==========================================================================
260 reference operator[] ( size_type index ) { return m_data [index] ; }
262 const_reference operator[] ( size_type index ) const { return m_data [index] ; }
264 reference operator() ( size_type index ) { return m_data [index] ; }
266 const_reference operator() ( size_type index ) const { return m_data [index] ; }
268 reference at ( size_type index ) { return m_data.at(index) ; }
270 const_reference at ( size_type index ) const { return m_data.at(index) ; }
271 // ==========================================================================
272 public:
273 // ==========================================================================
274 iterator begin () { return m_data . begin () ; }
275 iterator end () { return m_data . end () ; }
276 const_iterator begin () const { return m_data . begin () ; }
277 const_iterator end () const { return m_data . end () ; }
278 reverse_iterator rbegin () { return m_data . rbegin () ; }
279 reverse_iterator rend () { return m_data . rend () ; }
280 const_reverse_iterator rbegin () const { return m_data . rbegin () ; }
281 const_reverse_iterator rend () const { return m_data . rend () ; }
282 // ==========================================================================
283 public:
284 // ==========================================================================
286 reference front () { return m_data . front () ; }
288 const_reference front () const { return m_data . front () ; }
290 reference back () { return m_data . back () ; }
292 const_reference back () const { return m_data . back () ; }
293 // ==========================================================================
294 public:
295 // ==========================================================================
297 bool operator== ( const SharedObjectsContainer& right ) const
298 { return &right == this || right.m_data == m_data ; }
300 bool operator== ( const ConstVector& right ) const
301 { return m_data == right ; }
303 bool operator < ( const SharedObjectsContainer& right ) const
304 { return m_data < right.m_data ; }
306 bool operator < ( const ConstVector& right ) const
307 { return m_data < right ; }
308 // ==========================================================================
309 public: // ObjectContainerBase methods:
310 // ==========================================================================
314 virtual long index( const ContainedObject* object ) const
315 {
316 auto _i = std::find ( begin() , end() , object ) ;
317 return end() != _i ? ( _i - begin() ) : -1 ; // RETURN
318 }
323 virtual ContainedObject* containedObject ( long index ) const
324 {
325 if ( 0 > index || !(index < (long) size () ) ) { return 0 ; } // RETURN
326 const ContainedObject* co = m_data[index] ;
327 return const_cast<ContainedObject*>( co ) ;
328 }
330 virtual size_type numberOfObjects() const { return m_data.size() ; }
335 virtual long add ( ContainedObject* object)
336 {
337 if ( !object ) { return -1 ; } // RETURN
338 TYPE* _obj = dynamic_cast<TYPE*> ( object ) ;
339 if ( !_obj ) { return -1 ; } // RETURN
340 const size_type pos = size() ;
341 push_back ( _obj ) ;
342 return pos ;
343 }
348 virtual long remove ( ContainedObject* value )
349 {
350 auto _i = std::find ( begin() , end() , value ) ;
351 if ( end() == _i ) { return -1 ; } // RETURN
352 const size_type pos = _i - begin() ;
353 m_data.erase ( _i ) ;
354 return pos ; // RETURN
355 }
356 // ==========================================================================
357 private:
358 // ==========================================================================
359 // the actual data
360 ConstVector m_data ; // the actual data
361 // ==========================================================================
362 };
363 // ============================================================================
364 // The END
365 // ============================================================================
366 #endif // GAUDIKERNEL_SHAREDOBJECTSCONTAINER_H
367 // ============================================================================
SharedObjectsContainer::erase
bool erase(const TYPE *object)
erase the first occurance of the certain element
Definition: SharedObjectsContainer.h:249
SharedObjectsContainer::clID
virtual const CLID & clID() const
Retrieve the unique class ID (virtual)
Definition: SharedObjectsContainer.h:94
SharedObjectsContainer::front
reference front()
the first element (only for non-empty vectors)
Definition: SharedObjectsContainer.h:286
SharedObjectsContainer
Very simple class to represent the container of objects which are not ownered by the container...
Definition: SharedObjectsContainer.h:28
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:270
SharedObjectsContainer::containedObject
virtual ContainedObject * containedObject(long index) const
Pointer to an object of a given distance.
Definition: SharedObjectsContainer.h:323
std::copy_if
T copy_if(T...args)
std::distance
T distance(T...args)
SharedObjectsContainer::operator()
reference operator()(size_type index)
'functional'-access
Definition: SharedObjectsContainer.h:264
SharedObjectsContainer::begin
const_iterator begin() const
Definition: SharedObjectsContainer.h:276
SharedObjectsContainer::erase
void erase(const PREDICATE &cut)
erase the objects which satisfy the criteria
Definition: SharedObjectsContainer.h:229
SharedObjectsContainer::operator==
bool operator==(const SharedObjectsContainer &right) const
equal content with other container ?
Definition: SharedObjectsContainer.h:297
SharedObjectsContainer::push_back
void push_back(const TYPE *object)
insert one object into the container
Definition: SharedObjectsContainer.h:126
SharedObjectsContainer::operator<
bool operator<(const SharedObjectsContainer &right) const
comparisons with other container
Definition: SharedObjectsContainer.h:303
SharedObjectsContainer::size_type
ConstVector::size_type size_type
Definition: SharedObjectsContainer.h:36
ObjectContainerBase.h
SharedObjectsContainer::reverse_iterator
ConstVector::reverse_iterator reverse_iterator
Definition: SharedObjectsContainer.h:41
SharedObjectsContainer::size
size_type size() const
get the actual size of the container
Definition: SharedObjectsContainer.h:120
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:83
SharedObjectsContainer::add
virtual long add(ContainedObject *object)
Virtual functions (forwards to the concrete container definitions) Add an object to the container...
Definition: SharedObjectsContainer.h:335
SharedObjectsContainer::rbegin
reverse_iterator rbegin()
Definition: SharedObjectsContainer.h:278
SharedObjectsContainer::iterator
ConstVector::iterator iterator
Definition: SharedObjectsContainer.h:39
SharedObjectsContainer::const_reference
ConstVector::const_reference const_reference
Definition: SharedObjectsContainer.h:38
std::vector::at
T at(T...args)
SharedObjectsContainer::insert
void insert(const TYPE *object)
insert one object into the container
Definition: SharedObjectsContainer.h:130
SharedObjectsContainer::index
virtual long index(const ContainedObject *object) const
Distance of a given object from the beginning of its container.
Definition: SharedObjectsContainer.h:314
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:288
SharedObjectsContainer::end
const_iterator end() const
Definition: SharedObjectsContainer.h:277
SharedObjectsContainer::rbegin
const_reverse_iterator rbegin() const
Definition: SharedObjectsContainer.h:280
SharedObjectsContainer::const_iterator
ConstVector::const_iterator const_iterator
Definition: SharedObjectsContainer.h:40
SharedObjectsContainer::begin
iterator begin()
Definition: SharedObjectsContainer.h:274
SharedObjectsContainer::SharedObjectsContainer
SharedObjectsContainer(const ConstVector &data)
Definition: SharedObjectsContainer.h:50
SharedObjectsContainer::back
const_reference back() const
the last element (only for non-empty vectors) (const-version)
Definition: SharedObjectsContainer.h:292
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:275
SharedObjectsContainer::~SharedObjectsContainer
virtual ~SharedObjectsContainer()
destructor
Definition: SharedObjectsContainer.h:89
SharedObjectsContainer::at
reference at(size_type index)
checked access
Definition: SharedObjectsContainer.h:268
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
std::vector::clear
T clear(T...args)
SharedObjectsContainer::numberOfObjects
virtual size_type numberOfObjects() const
Number of objects in the container.
Definition: SharedObjectsContainer.h:330
SharedObjectsContainer::empty
bool empty() const
empty container?
Definition: SharedObjectsContainer.h:122
SharedObjectsContainer::rend
reverse_iterator rend()
Definition: SharedObjectsContainer.h:279
SharedObjectsContainer::operator[]
reference operator[](size_type index)
index access
Definition: SharedObjectsContainer.h:260
SharedObjectsContainer::ConstVector
std::vector< const TYPE * > ConstVector
the actual container type
Definition: SharedObjectsContainer.h:33
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:29
std::find
T find(T...args)
SharedObjectsContainer::rend
const_reverse_iterator rend() const
Definition: SharedObjectsContainer.h:281
std::vector::size
T size(T...args)
SharedObjectsContainer::SharedObjectsContainer
SharedObjectsContainer()
Definition: SharedObjectsContainer.h:47
std::vector< const TYPE * >
std::cref
T cref(T...args)
SharedObjectsContainer::classID
static const CLID & classID()
Retrieve the unuqie class ID (static)
Definition: SharedObjectsContainer.h:97
SharedObjectsContainer::reference
ConstVector::reference reference
Definition: SharedObjectsContainer.h:37
SharedObjectsContainer::back
reference back()
the last element (only for non-empty vectors)
Definition: SharedObjectsContainer.h:290
ObjectContainerBase
ObjectContainerBase is the base class for Gaudi container classes.
Definition: ObjectContainerBase.h:19
ana.i
list i
Definition: ana.py:128
SharedObjectsContainer::SharedObjectsContainer
SharedObjectsContainer(DATA first, DATA last)
the templated constructor from the pair of iterators
Definition: SharedObjectsContainer.h:57
Objects::reference
TO * reference(FROM *from)
Definition: KeyedObject.cpp:20
SharedObjectsContainer::m_data
ConstVector m_data
Definition: SharedObjectsContainer.h:360
std::vector::reserve
T reserve(T...args)
SharedObjectsContainer::erase
void erase(iterator i)
erase the object by iterator
Definition: SharedObjectsContainer.h:210
SharedObjectsContainer::const_reverse_iterator
ConstVector::const_reverse_iterator const_reverse_iterator
Definition: SharedObjectsContainer.h:42
SharedObjectsContainer::value_type
ConstVector::value_type value_type
various types (to make STL happy)
Definition: SharedObjectsContainer.h:35