Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v28r2p1 (f1a77ff4)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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"
15 // ============================================================================
27 template <class TYPE>
29 {
30 public:
31  // ==========================================================================
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 () = default;
48  // move constructor and move assignement
51  // the constructor from the data
52  SharedObjectsContainer ( const ConstVector& data )
53  : m_data(data) {}
54  SharedObjectsContainer ( ConstVector&& data )
55  : m_data(std::move(data)) {}
56 
61  template <class DATA>
62  SharedObjectsContainer(DATA first, DATA last)
63  : m_data(first, last) {}
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
99  static const CLID& classID()
100  {
101  static const CLID s_clid =
102  ( ( static_cast<CLID> ( -1 ) << 16 ) // 16 used and 16 empty bits
103  & !CLID_ObjectVector // not an ObjectVector
104  & !CLID_ObjectList // not an ObjectList
105  & !static_cast<CLID> ( 0x00030000 ) // not a KeyedContainer/map
106  & !static_cast<CLID> ( 0x00040000 ) )// not a KeyedContainer/hashmap
107  + TYPE::classID() ; // the specific CLID from the contents
108  //
109  return s_clid;
110  }
111  // ==========================================================================
112 public:
113  // ==========================================================================
115  inline const ConstVector& data () const { return m_data ; }
117  operator const ConstVector& () const { return data () ; }
118  // ==========================================================================
119 public:
120  // ==========================================================================
122  size_type size () const { return m_data.size () ; }
124  bool empty () const { return m_data.empty () ; }
128  void push_back ( const TYPE* object ) { m_data.push_back ( object ) ; }
132  void insert ( const TYPE* object ) { m_data.push_back ( object ) ; }
137  template <class DATA>
138  void insert
139  ( DATA first ,
140  DATA last ) { m_data.insert ( end() , first ,last ) ; }
167  template <class DATA, class PREDICATE>
168  void insert
169  ( DATA first ,
170  DATA last ,
171  const PREDICATE& cut )
172  {
173  m_data.reserve ( m_data.size() + std::distance ( first , last ) ) ;
174  std::copy_if( first, last, std::back_inserter(m_data), std::cref(cut) );
175  }
200  template <class OUTPUT, class PREDICATE>
201  OUTPUT get ( const PREDICATE& cut ,
202  OUTPUT output ) const
203  {
204  return std::copy_if( begin(), end(), output, std::cref(cut) );
205  }
207  void erase ( iterator i ) { m_data.erase ( i ) ; }
225  template <class PREDICATE>
226  void erase ( const PREDICATE& cut )
227  { m_data.erase( std::remove_if ( begin() , end() , cut ) , end() ) ; }
246  bool erase ( const TYPE* object )
247  {
248  auto i = std::find ( begin() , end() , object ) ;
249  if ( end() == i ) { return false ; }
250  m_data.erase ( i ) ;
251  return true ;
252  }
253  // ==========================================================================
254 public:
255  // ==========================================================================
257  reference operator[] ( size_type index ) { return m_data [index] ; }
259  const_reference operator[] ( size_type index ) const { return m_data [index] ; }
261  reference operator() ( size_type index ) { return m_data [index] ; }
263  const_reference operator() ( size_type index ) const { return m_data [index] ; }
265  reference at ( size_type index ) { return m_data.at(index) ; }
267  const_reference at ( size_type index ) const { return m_data.at(index) ; }
268  // ==========================================================================
269 public:
270  // ==========================================================================
271  iterator begin () { return m_data . begin () ; }
272  iterator end () { return m_data . end () ; }
273  const_iterator begin () const { return m_data . begin () ; }
274  const_iterator end () const { return m_data . end () ; }
275  reverse_iterator rbegin () { return m_data . rbegin () ; }
276  reverse_iterator rend () { return m_data . rend () ; }
277  const_reverse_iterator rbegin () const { return m_data . rbegin () ; }
278  const_reverse_iterator rend () const { return m_data . rend () ; }
279  // ==========================================================================
280 public:
281  // ==========================================================================
283  reference front () { return m_data . front () ; }
285  const_reference front () const { return m_data . front () ; }
287  reference back () { return m_data . back () ; }
289  const_reference back () const { return m_data . back () ; }
290  // ==========================================================================
291 public:
292  // ==========================================================================
294  bool operator== ( const SharedObjectsContainer& right ) const
295  { return &right == this || right.m_data == m_data ; }
297  bool operator== ( const ConstVector& right ) const
298  { return m_data == right ; }
300  bool operator < ( const SharedObjectsContainer& right ) const
301  { return m_data < right.m_data ; }
303  bool operator < ( const ConstVector& right ) const
304  { return m_data < right ; }
305  // ==========================================================================
306 public: // ObjectContainerBase methods:
307  // ==========================================================================
311  long index( const ContainedObject* object ) const override
312  {
313  auto _i = std::find ( begin() , end() , object ) ;
314  return end() != _i ? ( _i - begin() ) : -1 ; // RETURN
315  }
320  ContainedObject* containedObject ( long index ) const override
321  {
322  if ( 0 > index || !(index < (long) size () ) ) { return nullptr; } // RETURN
323  const ContainedObject* co = m_data[index] ;
324  return const_cast<ContainedObject*>( co ) ;
325  }
327  size_type numberOfObjects() const override { return m_data.size() ; }
332  long add ( ContainedObject* object) override
333  {
334  if ( !object ) { return -1 ; } // RETURN
335  TYPE* _obj = dynamic_cast<TYPE*> ( object ) ;
336  if ( !_obj ) { return -1 ; } // RETURN
337  const size_type pos = size() ;
338  push_back ( _obj ) ;
339  return pos ;
340  }
345  long remove ( ContainedObject* value ) override
346  {
347  auto _i = std::find ( begin() , end() , value ) ;
348  if ( end() == _i ) { return -1 ; } // RETURN
349  const size_type pos = _i - begin() ;
350  m_data.erase ( _i ) ;
351  return pos ; // RETURN
352  }
353  // ==========================================================================
354 private:
355  // ==========================================================================
356  // the actual data
357  ConstVector m_data ; // the actual data
358  // ==========================================================================
359 };
360 // ============================================================================
361 // The END
362 // ============================================================================
363 #endif // GAUDIKERNEL_SHAREDOBJECTSCONTAINER_H
364 // ============================================================================
bool erase(const TYPE *object)
erase the first occurance of the certain element
reference front()
the first element (only for non-empty vectors)
Very simple class to represent the container of objects which are not owned by this container...
ContainedObject * containedObject(long index) const override
Pointer to an object of a given distance.
T empty(T...args)
const_reference at(size_type index) const
checked access (const-version)
T copy_if(T...args)
T distance(T...args)
reference operator()(size_type index)
&#39;functional&#39;-access
const_iterator begin() const
void erase(const PREDICATE &cut)
erase the objects which satisfy the criteria
bool operator==(const SharedObjectsContainer &right) const
equal content with other container ?
void push_back(const TYPE *object)
insert one object into the container
bool operator<(const SharedObjectsContainer &right) const
comparisons with other container
ConstVector::size_type size_type
STL namespace.
ConstVector::reverse_iterator reverse_iterator
size_type size() const
get the actual size of the container
size_type numberOfObjects() const override
Number of objects in the container.
T remove_if(T...args)
SharedObjectsContainer(DATA first, DATA last, const PREDICATE &cut)
the templated constructor from the pair of iterators and the predicate.
ConstVector::iterator iterator
ConstVector::const_reference const_reference
T at(T...args)
void insert(const TYPE *object)
insert one object into the container
T push_back(T...args)
const_reference front() const
the first element (only for non-empty vectors) (const-version)
const_iterator end() const
const_reverse_iterator rbegin() const
ConstVector::const_iterator const_iterator
SharedObjectsContainer(const ConstVector &data)
const_reference back() const
the last element (only for non-empty vectors) (const-version)
const ConstVector & data() const
get the access to the underlying container (const)
T erase(T...args)
reference at(size_type index)
checked access
long index(const ContainedObject *object) const override
Distance of a given object from the beginning of its container.
long add(ContainedObject *object) override
Virtual functions (forwards to the concrete container definitions) Add an object to the container...
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
SharedObjectsContainer()=default
bool empty() const
empty container?
reference operator[](size_type index)
index access
SharedObjectsContainer & operator=(SharedObjectsContainer &&)=default
std::vector< const TYPE * > ConstVector
the actual container type
T insert(T...args)
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
T find(T...args)
const_reverse_iterator rend() const
T size(T...args)
SharedObjectsContainer(ConstVector &&data)
T cref(T...args)
T back_inserter(T...args)
static const CLID & classID()
Retrieve the unuqie class ID (static)
ConstVector::reference reference
reference back()
the last element (only for non-empty vectors)
ObjectContainerBase is the base class for Gaudi container classes.
const CLID & clID() const override
Retrieve the unique class ID (virtual)
SharedObjectsContainer(DATA first, DATA last)
the templated constructor from the pair of iterators
TO * reference(FROM *from)
Definition: KeyedObject.cpp:20
T reserve(T...args)
void erase(iterator i)
erase the object by iterator
ConstVector::const_reverse_iterator const_reverse_iterator
ConstVector::value_type value_type
various types (to make STL happy)