The Gaudi Framework  master (594c33fa)
ObjectVector Class Reference

#include <GaudiKernel/ObjectVector.h>

Collaboration diagram for ObjectVector:

Public Types

typedef TYPE contained_type
 
typedef std::vector< TYPE * >::value_type value_type
 
typedef std::vector< TYPE * >::reference reference
 
typedef std::vector< TYPE * >::const_reference const_reference
 
typedef std::vector< TYPE * >::iterator iterator
 
typedef std::vector< TYPE * >::const_iterator const_iterator
 
typedef std::vector< TYPE * >::reverse_iterator reverse_iterator
 
typedef std::vector< TYPE * >::const_reverse_iterator const_reverse_iterator
 
typedef std::vector< TYPE * >::pointer pointer
 
typedef std::vector< TYPE * >::const_pointer const_pointer
 

Public Member Functions

 ObjectVector ()=default
 Constructors. More...
 
 ObjectVector (const ObjectVector< TYPE > &)=delete
 
ObjectVectoroperator= (const ObjectVector< TYPE > &)=delete
 
 ObjectVector (ObjectVector &&rhs)
 
 ~ObjectVector () override
 Destructor. More...
 
const CLIDclID () const override
 Retrieve class ID. More...
 
ObjectVector< TYPE >::iterator begin ()
 Return an iterator pointing to the beginning of the container. More...
 
ObjectVector< TYPE >::const_iterator begin () const
 Return a const_iterator pointing to the beginning of the container. More...
 
ObjectVector< TYPE >::iterator end ()
 Return an iterator pointing to the end of the container. More...
 
ObjectVector< TYPE >::const_iterator end () const
 Return a const_iterator pointing to the end of the container. More...
 
ObjectVector< TYPE >::reverse_iterator rbegin ()
 Return a reverse_iterator pointing to the beginning of the reversed container. More...
 
ObjectVector< TYPE >::const_reverse_iterator rbegin () const
 Return a const_reverse_iterator pointing to the beginning of the reversed container. More...
 
ObjectVector< TYPE >::reverse_iterator rend ()
 Return a reverse_iterator pointing to the end of the reversed container. More...
 
ObjectVector< TYPE >::const_reverse_iterator rend () const
 Return a const_reverse_iterator pointing to the end of the reversed container. More...
 
ObjectVector< TYPE >::size_type size () const
 Return the size of the container. More...
 
ObjectVector< TYPE >::size_type numberOfObjects () const override
 The same as size(), return number of objects in the container. More...
 
ObjectVector< TYPE >::size_type max_size () const
 Return the largest possible size of the container. More...
 
ObjectVector< TYPE >::size_type capacity () const
 Return number of elements for which memory has been allocated It is always greater than or equal to size() More...
 
void reserve (typename ObjectVector< TYPE >::size_type value)
 Reserve place for "value" objects in the container. More...
 
bool empty () const
 Return true if the size of the container is 0. More...
 
ObjectVector< TYPE >::reference front ()
 Return reference to the first element. More...
 
ObjectVector< TYPE >::const_reference front () const
 Return const_reference to the first element. More...
 
ObjectVector< TYPE >::reference back ()
 Return reference to the last element. More...
 
ObjectVector< TYPE >::const_reference back () const
 Return const_reference to the last element. More...
 
void push_back (typename ObjectVector< TYPE >::const_reference value)
 push_back = append = insert a new element at the end of the container More...
 
long add (ContainedObject *pObject) override
 Add an object to the container. More...
 
void pop_back ()
 pop_back = remove the last element from the container The removed object will be deleted (see the method release) More...
 
long remove (ContainedObject *value) override
 Release object from the container (the poiter will be removed from the container, but the object itself will remain alive) (see the method pop_back) More...
 
ObjectVector< TYPE >::iterator insert (typename ObjectVector< TYPE >::iterator position, typename ObjectVector< TYPE >::const_reference value)
 Insert "value" before "position". More...
 
void erase (typename ObjectVector< TYPE >::iterator position)
 Erase the object at "position" from the container. The removed object will be deleted. More...
 
void erase (typename ObjectVector< TYPE >::iterator first, typename ObjectVector< TYPE >::iterator last)
 Erase the range [first, last) from the container. The removed object will be deleted. More...
 
void clear ()
 Clear the entire content of the container and delete all contained objects. More...
 
ObjectVector< TYPE >::reference operator[] (typename ObjectVector< TYPE >::size_type n)
 Return the reference to the n'th object in the container. More...
 
ObjectVector< TYPE >::const_reference operator[] (typename ObjectVector< TYPE >::size_type n) const
 Return the const_reference to the n'th object in the container. More...
 
long index (const ContainedObject *obj) const override
 Return distance of a given object from the beginning of its container It correcponds to the "index" ( from 0 to size()-1 ) If "obj" not fount, return -1. More...
 
ContainedObject const * containedObject (long dist) const override
 Return const pointer to an object of a given distance (index) More...
 
ContainedObjectcontainedObject (long dist) override
 
std::ostreamfillStream (std::ostream &s) const override
 Fill the output stream (ASCII) More...
 

Static Public Member Functions

static const CLIDclassID ()
 Retrieve class ID. More...
 

Private Attributes

std::vector< TYPE * > m_vector
 The STL vector itself. More...
 

Detailed Description

ObjectVector is one of the basic Gaudi container classes capable of being registered in Data Stores. It is based on Standard Library (STL) std::vector (see STL Programmer's Guide) ObjectVector has all functions of the std::vector interface, and in addition a number of Gaudi specific functions.

Each object is allowed to belong into a single container only. After inserting the object into the container, it takes over all responsibilities for the object. E.g. erasing the object from its container causes removing the object's pointer from the container and deleting the object itself.

Author
Pavel Binko
Pere Mato
Date
19/10/1999, 30/11/2000

Definition at line 22 of file ContainedObject.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 56 of file ObjectVector.h.

◆ const_pointer

Definition at line 65 of file ObjectVector.h.

◆ const_reference

Definition at line 53 of file ObjectVector.h.

◆ const_reverse_iterator

◆ contained_type

Definition at line 49 of file ObjectVector.h.

◆ iterator

Definition at line 55 of file ObjectVector.h.

◆ pointer

Definition at line 64 of file ObjectVector.h.

◆ reference

Definition at line 52 of file ObjectVector.h.

◆ reverse_iterator

Definition at line 58 of file ObjectVector.h.

◆ value_type

Definition at line 50 of file ObjectVector.h.

Constructor & Destructor Documentation

◆ ObjectVector() [1/3]

ObjectVector::ObjectVector ( )
default

Constructors.

◆ ObjectVector() [2/3]

ObjectVector::ObjectVector ( const ObjectVector< TYPE > &  )
delete

◆ ObjectVector() [3/3]

ObjectVector::ObjectVector ( ObjectVector &&  rhs)
inline

Definition at line 73 of file ObjectVector.h.

74  std::for_each( begin(), end(), [this]( TYPE* obj ) { obj->setParent( this ); } );
75  }

◆ ~ObjectVector()

ObjectVector::~ObjectVector ( )
inlineoverride

Destructor.

Definition at line 78 of file ObjectVector.h.

78  {
79  for ( auto& i : m_vector ) {
80  // Set the back pointer to 0 to avoid repetitional searching
81  // for the object in the container, and deleting the object
82  i->setParent( nullptr );
83  delete i;
84  }
85  }

Member Function Documentation

◆ add()

long ObjectVector::add ( ContainedObject pObject)
inlineoverride

Add an object to the container.

Definition at line 168 of file ObjectVector.h.

168  {
169  try {
170  auto ptr = dynamic_cast<typename ObjectVector<TYPE>::value_type>( pObject );
171  if ( ptr ) {
172  push_back( ptr );
173  return m_vector.size() - 1;
174  }
175  } catch ( ... ) {}
176  return -1;
177  }

◆ back() [1/2]

ObjectVector<TYPE>::reference ObjectVector::back ( )
inline

Return reference to the last element.

Definition at line 155 of file ObjectVector.h.

155 { return m_vector.back(); }

◆ back() [2/2]

ObjectVector<TYPE>::const_reference ObjectVector::back ( ) const
inline

Return const_reference to the last element.

Definition at line 158 of file ObjectVector.h.

158 { return m_vector.back(); }

◆ begin() [1/2]

ObjectVector<TYPE>::iterator ObjectVector::begin ( )
inline

Return an iterator pointing to the beginning of the container.

Definition at line 96 of file ObjectVector.h.

96 { return m_vector.begin(); }

◆ begin() [2/2]

ObjectVector<TYPE>::const_iterator ObjectVector::begin ( ) const
inline

Return a const_iterator pointing to the beginning of the container.

Definition at line 99 of file ObjectVector.h.

99 { return m_vector.begin(); }

◆ capacity()

ObjectVector<TYPE>::size_type ObjectVector::capacity ( ) const
inline

Return number of elements for which memory has been allocated It is always greater than or equal to size()

Definition at line 134 of file ObjectVector.h.

134 { return m_vector.capacity(); }

◆ classID()

static const CLID& ObjectVector::classID ( )
inlinestatic

Retrieve class ID.

Definition at line 90 of file ObjectVector.h.

90  {
91  static const CLID clid = TYPE::classID() + CLID_ObjectVector;
92  return clid;
93  }

◆ clear()

void ObjectVector::clear ( )
inline

Clear the entire content of the container and delete all contained objects.

Definition at line 241 of file ObjectVector.h.

241 { erase( begin(), end() ); }

◆ clID()

const CLID& ObjectVector::clID ( ) const
inlineoverride

Retrieve class ID.

Definition at line 88 of file ObjectVector.h.

88 { return ObjectVector<TYPE>::classID(); }

◆ containedObject() [1/2]

ContainedObject const* ObjectVector::containedObject ( long  dist) const
inlineoverride

Return const pointer to an object of a given distance (index)

Definition at line 260 of file ObjectVector.h.

260 { return m_vector[dist]; }

◆ containedObject() [2/2]

ContainedObject* ObjectVector::containedObject ( long  dist)
inlineoverride

Definition at line 261 of file ObjectVector.h.

261 { return m_vector[dist]; }

◆ empty()

bool ObjectVector::empty ( ) const
inline

Return true if the size of the container is 0.

Definition at line 146 of file ObjectVector.h.

146 { return m_vector.empty(); }

◆ end() [1/2]

ObjectVector<TYPE>::iterator ObjectVector::end ( )
inline

Return an iterator pointing to the end of the container.

Definition at line 102 of file ObjectVector.h.

102 { return m_vector.end(); }

◆ end() [2/2]

ObjectVector<TYPE>::const_iterator ObjectVector::end ( ) const
inline

Return a const_iterator pointing to the end of the container.

Definition at line 105 of file ObjectVector.h.

105 { return m_vector.end(); }

◆ erase() [1/2]

void ObjectVector::erase ( typename ObjectVector< TYPE >::iterator  first,
typename ObjectVector< TYPE >::iterator  last 
)
inline

Erase the range [first, last) from the container. The removed object will be deleted.

Definition at line 229 of file ObjectVector.h.

229  {
230  for ( auto i = first; i != last; i++ ) {
231  // Set the back pointer to 0 to avoid repetitional searching
232  // for the object in the container, and deleting the object
233  ( *i )->setParent( nullptr );
234  delete *i;
235  }
236  // Removing from the container itself
237  m_vector.erase( first, last );
238  }

◆ erase() [2/2]

void ObjectVector::erase ( typename ObjectVector< TYPE >::iterator  position)
inline

Erase the object at "position" from the container. The removed object will be deleted.

Definition at line 217 of file ObjectVector.h.

217  {
218  if ( ( *position )->parent() ) {
219  // Set the back pointer to 0 to avoid repetitional searching
220  // for the object in the container, and deleting the object
221  ( *position )->setParent( nullptr );
222  delete *position;
223  }
224  // Removing from the container itself
225  m_vector.erase( position );
226  }

◆ fillStream()

std::ostream& ObjectVector::fillStream ( std::ostream s) const
inlineoverride

Fill the output stream (ASCII)

Definition at line 264 of file ObjectVector.h.

264  {
265  s << "class ObjectVector : size = " << std::setw( 12 ) << size() << "\n";
266  // Output the base class
267  // ObjectContainerBase::fillStream(s);
268  if ( !empty() ) {
269  s << "\nContents of the STL vector :";
270  long count = 0;
271  for ( const auto& i : m_vector ) { s << "\nIndex " << std::setw( 12 ) << count++ << " of object of type " << *i; }
272  }
273  return s;
274  }

◆ front() [1/2]

ObjectVector<TYPE>::reference ObjectVector::front ( )
inline

Return reference to the first element.

Definition at line 149 of file ObjectVector.h.

149 { return m_vector.front(); }

◆ front() [2/2]

ObjectVector<TYPE>::const_reference ObjectVector::front ( ) const
inline

Return const_reference to the first element.

Definition at line 152 of file ObjectVector.h.

152 { return m_vector.front(); }

◆ index()

long ObjectVector::index ( const ContainedObject obj) const
inlineoverride

Return distance of a given object from the beginning of its container It correcponds to the "index" ( from 0 to size()-1 ) If "obj" not fount, return -1.

Definition at line 254 of file ObjectVector.h.

254  {
255  auto i = std::find_if( begin(), end(), [&]( const ContainedObject* o ) { return o == obj; } );
256  return i != end() ? std::distance( begin(), i ) : -1;
257  }

◆ insert()

ObjectVector<TYPE>::iterator ObjectVector::insert ( typename ObjectVector< TYPE >::iterator  position,
typename ObjectVector< TYPE >::const_reference  value 
)
inline

Insert "value" before "position".

Definition at line 210 of file ObjectVector.h.

211  {
212  value->setParent( this );
213  return m_vector.insert( position, value );
214  }

◆ max_size()

ObjectVector<TYPE>::size_type ObjectVector::max_size ( ) const
inline

Return the largest possible size of the container.

Definition at line 130 of file ObjectVector.h.

130 { return m_vector.max_size(); }

◆ numberOfObjects()

ObjectVector<TYPE>::size_type ObjectVector::numberOfObjects ( ) const
inlineoverride

The same as size(), return number of objects in the container.

Definition at line 127 of file ObjectVector.h.

127 { return m_vector.size(); }

◆ operator=()

ObjectVector& ObjectVector::operator= ( const ObjectVector< TYPE > &  )
delete

◆ operator[]() [1/2]

ObjectVector<TYPE>::reference ObjectVector::operator[] ( typename ObjectVector< TYPE >::size_type  n)
inline

Return the reference to the n'th object in the container.

Definition at line 244 of file ObjectVector.h.

244 { return m_vector[n]; }

◆ operator[]() [2/2]

ObjectVector<TYPE>::const_reference ObjectVector::operator[] ( typename ObjectVector< TYPE >::size_type  n) const
inline

Return the const_reference to the n'th object in the container.

Definition at line 247 of file ObjectVector.h.

247  {
248  return m_vector[n];
249  }

◆ pop_back()

void ObjectVector::pop_back ( )
inline

pop_back = remove the last element from the container The removed object will be deleted (see the method release)

Definition at line 181 of file ObjectVector.h.

181  {
182  auto position = m_vector.back();
183  // Set the back pointer to 0 to avoid repetitional searching
184  // for the object in the container, and deleting the object
185  position->setParent( nullptr );
186  delete position;
187  // Removing from the container itself
188  m_vector.pop_back();
189  }

◆ push_back()

void ObjectVector::push_back ( typename ObjectVector< TYPE >::const_reference  value)
inline

push_back = append = insert a new element at the end of the container

Definition at line 161 of file ObjectVector.h.

161  {
162  if ( value->parent() ) { const_cast<ObjectContainerBase*>( value->parent() )->remove( value ); }
163  value->setParent( this );
164  m_vector.push_back( value );
165  }

◆ rbegin() [1/2]

ObjectVector<TYPE>::reverse_iterator ObjectVector::rbegin ( )
inline

Return a reverse_iterator pointing to the beginning of the reversed container.

Definition at line 108 of file ObjectVector.h.

108 { return m_vector.rbegin(); }

◆ rbegin() [2/2]

ObjectVector<TYPE>::const_reverse_iterator ObjectVector::rbegin ( ) const
inline

Return a const_reverse_iterator pointing to the beginning of the reversed container.

Definition at line 112 of file ObjectVector.h.

112 { return m_vector.rbegin(); }

◆ remove()

long ObjectVector::remove ( ContainedObject value)
inlineoverride

Release object from the container (the poiter will be removed from the container, but the object itself will remain alive) (see the method pop_back)

Definition at line 193 of file ObjectVector.h.

193  {
194  // Find the object of the value value
195  auto i = std::find_if( begin(), end(), [&]( const ContainedObject* j ) { return j == value; } );
196  if ( i == end() ) {
197  // Object cannot be released from the conatiner,
198  // as it is not contained in it
199  return 0;
200  }
201  long idx = std::distance( begin(), i );
202  // Set the back pointer to 0 to avoid repetitional searching
203  // for the object in the container and deleting the object
204  ( *i )->setParent( nullptr );
205  erase( i );
206  return idx;
207  }

◆ rend() [1/2]

ObjectVector<TYPE>::reverse_iterator ObjectVector::rend ( )
inline

Return a reverse_iterator pointing to the end of the reversed container.

Definition at line 115 of file ObjectVector.h.

115 { return m_vector.rend(); }

◆ rend() [2/2]

ObjectVector<TYPE>::const_reverse_iterator ObjectVector::rend ( ) const
inline

Return a const_reverse_iterator pointing to the end of the reversed container.

Definition at line 118 of file ObjectVector.h.

118 { return m_vector.rend(); }

◆ reserve()

void ObjectVector::reserve ( typename ObjectVector< TYPE >::size_type  value)
inline

Reserve place for "value" objects in the container.

If "value" is less than or equal to capacity(), this call has no effect, otherwise, it is a request for allocation of additional memory. If the request is successful, then capacity() is >= n, otherwise, capacity() is unchanged. In either case, size() is unchanged

Definition at line 143 of file ObjectVector.h.

143 { m_vector.reserve( value ); }

◆ size()

ObjectVector<TYPE>::size_type ObjectVector::size ( ) const
inline

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 at line 124 of file ObjectVector.h.

124 { return m_vector.size(); }

Member Data Documentation

◆ m_vector

std::vector<TYPE*> ObjectVector::m_vector
private

The STL vector itself.

Definition at line 278 of file ObjectVector.h.


The documentation for this class was generated from the following files:
std::for_each
T for_each(T... args)
std::move
T move(T... args)
std::vector::reserve
T reserve(T... args)
gaudirun.s
string s
Definition: gaudirun.py:346
ObjectVector::value_type
std::vector< TYPE * >::value_type value_type
Definition: ObjectVector.h:50
std::find_if
T find_if(T... args)
std::vector::size
T size(T... args)
ObjectVector::size
ObjectVector< TYPE >::size_type size() const
Return the size of the container.
Definition: ObjectVector.h:124
std::distance
T distance(T... args)
ObjectVector::push_back
void push_back(typename ObjectVector< TYPE >::const_reference value)
push_back = append = insert a new element at the end of the container
Definition: ObjectVector.h:161
std::vector::back
T back(T... args)
ObjectVector::begin
ObjectVector< TYPE >::iterator begin()
Return an iterator pointing to the beginning of the container.
Definition: ObjectVector.h:96
std::vector::front
T front(T... args)
std::vector::push_back
T push_back(T... args)
std::vector::capacity
T capacity(T... args)
ProduceConsume.j
j
Definition: ProduceConsume.py:101
std::vector::erase
T erase(T... args)
ObjectVector::erase
void erase(typename ObjectVector< TYPE >::iterator position)
Erase the object at "position" from the container. The removed object will be deleted.
Definition: ObjectVector.h:217
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
std::vector::pop_back
T pop_back(T... args)
std::vector::max_size
T max_size(T... args)
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:234
std::vector::rend
T rend(T... args)
ObjectContainerBase
Definition: ObjectContainerBase.h:29
ObjectVector::end
ObjectVector< TYPE >::iterator end()
Return an iterator pointing to the end of the container.
Definition: ObjectVector.h:102
ObjectVector::remove
long remove(ContainedObject *value) override
Release object from the container (the poiter will be removed from the container, but the object itse...
Definition: ObjectVector.h:193
std::vector::begin
T begin(T... args)
std::vector::insert
T insert(T... args)
ObjectVector::empty
bool empty() const
Return true if the size of the container is 0.
Definition: ObjectVector.h:146
std::count
T count(T... args)
std::vector::empty
T empty(T... args)
std::vector::end
T end(T... args)
std::setw
T setw(T... args)
ObjectVector::m_vector
std::vector< TYPE * > m_vector
The STL vector itself.
Definition: ObjectVector.h:278
ContainedObject
Definition: ContainedObject.h:41
std::vector::rbegin
T rbegin(T... args)
ObjectVector::classID
static const CLID & classID()
Retrieve class ID.
Definition: ObjectVector.h:90