The Gaudi Framework  v40r0 (475e45c1)
ObjectList Class Reference

#include <GaudiKernel/ObjectList.h>

Collaboration diagram for ObjectList:

Public Types

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

Public Member Functions

 ObjectList ()=default
 
 ObjectList (const ObjectList< TYPE > &)=delete
 
ObjectListoperator= (const ObjectList< TYPE > &)=delete
 
 ~ObjectList () override
 
const CLIDclID () const override
 Retrieve pointer to class definition structure. More...
 
ObjectList< TYPE >::iterator begin ()
 Return an iterator pointing to the beginning of the container. More...
 
ObjectList< TYPE >::const_iterator begin () const
 Return a const_iterator pointing to the beginning of the container. More...
 
ObjectList< TYPE >::iterator end ()
 Return an iterator pointing to the end of the container. More...
 
ObjectList< TYPE >::const_iterator end () const
 Return a const_iterator pointing to the end of the container. More...
 
ObjectList< TYPE >::reverse_iterator rbegin ()
 Return a reverse_iterator pointing to the beginning of the reversed container. More...
 
ObjectList< TYPE >::const_reverse_iterator rbegin () const
 Return a const_reverse_iterator pointing to the beginning of the reversed container. More...
 
ObjectList< TYPE >::reverse_iterator rend ()
 Return a reverse_iterator pointing to the end of the reversed container. More...
 
ObjectList< TYPE >::const_reverse_iterator rend () const
 Return a const_reverse_iterator pointing to the end of the reversed container. More...
 
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. More...
 
ObjectList< TYPE >::size_type numberOfObjects () const override
 The same as size(), return number of objects in the container. More...
 
ObjectList< TYPE >::size_type max_size () const
 Return the largest possible size of the container. More...
 
bool empty () const
 Return true if the size of the container is 0. More...
 
ObjectList< TYPE >::reference front ()
 Return reference to the first element. More...
 
ObjectList< TYPE >::const_reference front () const
 Return const_reference to the first element. More...
 
ObjectList< TYPE >::reference back ()
 Return reference to the last element. More...
 
ObjectList< TYPE >::const_reference back () const
 Return const_reference to the last element. More...
 
void push_back (typename ObjectList< 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 pointer will be removed from the container, but the object itself will remain alive) (see the method pop_back) More...
 
ObjectList< TYPE >::iterator insert (typename ObjectList< TYPE >::iterator position, typename ObjectList< TYPE >::const_reference value)
 Insert "value" before "position". More...
 
void erase (typename ObjectList< TYPE >::iterator position)
 Erase the object at "position" from the container. The removed object will be deleted. More...
 
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. More...
 
void clear ()
 Clear the entire content of the container and delete all contained objects. More...
 
long index (const ContainedObject *obj) const override
 Return distance of a given object from the beginning of its container It corresponds to the "index" ( from 0 to size()-1 ) If "obj" not fount, return -1. More...
 
const ContainedObjectcontainedObject (long dist) const override
 Return const pointer to an object of a given distance. More...
 
ContainedObjectcontainedObject (long dist) override
 Return const pointer to an object of a given distance. More...
 
std::ostream & fillStream (std::ostream &s) const override
 Fill the output stream (ASCII) More...
 

Static Public Member Functions

static const CLIDclassID ()
 

Private Attributes

std::list< TYPE * > m_list
 

Detailed Description

ObjectList is one of the basic Gaudi container classes capable of being registered in Data Stores. It is based on Standard Library (STL) std::list (see STL Programmer's Guide) ObjectList has all functions of the std::list interface,

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 21 of file ContainedObject.h.

Member Typedef Documentation

◆ const_iterator

typedef std::list<TYPE*>::const_iterator ObjectList::const_iterator

Definition at line 52 of file ObjectList.h.

◆ const_pointer

typedef std::vector<TYPE*>::const_pointer ObjectList::const_pointer

Definition at line 62 of file ObjectList.h.

◆ const_reference

typedef std::list<TYPE*>::const_reference ObjectList::const_reference

Definition at line 49 of file ObjectList.h.

◆ const_reverse_iterator

Definition at line 55 of file ObjectList.h.

◆ contained_type

Definition at line 45 of file ObjectList.h.

◆ iterator

typedef std::list<TYPE*>::iterator ObjectList::iterator

Definition at line 51 of file ObjectList.h.

◆ pointer

typedef std::vector<TYPE*>::pointer ObjectList::pointer

Definition at line 61 of file ObjectList.h.

◆ reference

typedef std::list<TYPE*>::reference ObjectList::reference

Definition at line 48 of file ObjectList.h.

◆ reverse_iterator

Definition at line 54 of file ObjectList.h.

◆ value_type

typedef std::list<TYPE*>::value_type ObjectList::value_type

Definition at line 46 of file ObjectList.h.

Constructor & Destructor Documentation

◆ ObjectList() [1/2]

ObjectList::ObjectList ( )
default

◆ ObjectList() [2/2]

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

◆ ~ObjectList()

ObjectList::~ObjectList ( )
inlineoverride

Definition at line 70 of file ObjectList.h.

70 { clear(); }

Member Function Documentation

◆ add()

long ObjectList::add ( ContainedObject pObject)
inlineoverride

Add an object to the container.

Definition at line 140 of file ObjectList.h.

140  {
141  try {
142  auto ptr = dynamic_cast<typename ObjectList<TYPE>::value_type>( pObject );
143  if ( ptr ) {
144  push_back( ptr );
145  return m_list.size() - 1;
146  }
147  } catch ( ... ) {}
148  return -1;
149  }

◆ back() [1/2]

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

Return reference to the last element.

Definition at line 127 of file ObjectList.h.

127 { return m_list.back(); }

◆ back() [2/2]

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

Return const_reference to the last element.

Definition at line 130 of file ObjectList.h.

130 { return m_list.back(); }

◆ begin() [1/2]

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

Return an iterator pointing to the beginning of the container.

Definition at line 80 of file ObjectList.h.

80 { return m_list.begin(); }

◆ begin() [2/2]

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

Return a const_iterator pointing to the beginning of the container.

Definition at line 83 of file ObjectList.h.

83 { return m_list.begin(); }

◆ classID()

static const CLID& ObjectList::classID ( )
inlinestatic

Definition at line 74 of file ObjectList.h.

74  {
75  static CLID clid = TYPE::classID() + CLID_ObjectList;
76  return clid;
77  }

◆ clear()

void ObjectList::clear ( )
inline

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

Definition at line 214 of file ObjectList.h.

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

◆ clID()

const CLID& ObjectList::clID ( ) const
inlineoverride

Retrieve pointer to class definition structure.

Definition at line 73 of file ObjectList.h.

73 { return ObjectList<TYPE>::classID(); }

◆ containedObject() [1/2]

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

Return const pointer to an object of a given distance.

Definition at line 224 of file ObjectList.h.

224  {
225  return dist < size() ? *std::next( begin(), dist ) : nullptr;
226  }

◆ containedObject() [2/2]

ContainedObject* ObjectList::containedObject ( long  dist)
inlineoverride

Return const pointer to an object of a given distance.

Definition at line 228 of file ObjectList.h.

228  {
229  return dist < size() ? *std::next( begin(), dist ) : nullptr;
230  }

◆ empty()

bool ObjectList::empty ( ) const
inline

Return true if the size of the container is 0.

Definition at line 118 of file ObjectList.h.

118 { return m_list.empty(); }

◆ end() [1/2]

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

Return an iterator pointing to the end of the container.

Definition at line 86 of file ObjectList.h.

86 { return m_list.end(); }

◆ end() [2/2]

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

Return a const_iterator pointing to the end of the container.

Definition at line 89 of file ObjectList.h.

89 { return m_list.end(); }

◆ erase() [1/2]

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

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

Definition at line 202 of file ObjectList.h.

202  {
203  for ( auto iter = first; iter != last; ++iter ) {
204  // Set the back pointer to 0 to avoid repetitional searching
205  // for the object in the container, and deleting the object
206  ( *iter )->setParent( nullptr );
207  delete *iter;
208  }
209  // Removing from the container itself
210  m_list.erase( first, last );
211  }

◆ erase() [2/2]

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

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

Definition at line 190 of file ObjectList.h.

190  {
191  if ( ( *position )->parent() ) {
192  // Set the back pointer to 0 to avoid repetitional searching
193  // for the object in the container, and deleting the object
194  ( *position )->setParent( nullptr );
195  delete *position;
196  }
197  // Removing from the container itself
198  m_list.erase( position );
199  }

◆ fillStream()

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

Fill the output stream (ASCII)

Definition at line 233 of file ObjectList.h.

233  {
234  s << "class ObjectList : size = " << std::setw( 12 ) << size() << "\n";
235  // Output the base class
236  // ObjectContainerBase::fillStream(s);
237  if ( !empty() ) {
238  s << "\nContents of the STL list :";
239  long count = 0;
240  for ( const auto& iter : m_list ) {
241  s << "\nIndex " << std::setw( 12 ) << count++ << " of object of type " << *iter;
242  }
243  }
244  return s;
245  }

◆ front() [1/2]

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

Return reference to the first element.

Definition at line 121 of file ObjectList.h.

121 { return m_list.front(); }

◆ front() [2/2]

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

Return const_reference to the first element.

Definition at line 124 of file ObjectList.h.

124 { return m_list.front(); }

◆ index()

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

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

Definition at line 218 of file ObjectList.h.

218  {
219  auto i = std::find_if( begin(), end(), [&]( const ContainedObject* o ) { return o == obj; } );
220  return i != end() ? std::distance( begin(), i ) : -1;
221  }

◆ insert()

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

Insert "value" before "position".

Definition at line 183 of file ObjectList.h.

184  {
185  value->setParent( this );
186  return m_list.insert( position, value );
187  }

◆ max_size()

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

Return the largest possible size of the container.

Definition at line 115 of file ObjectList.h.

115 { return m_list.max_size(); }

◆ numberOfObjects()

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

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

Definition at line 112 of file ObjectList.h.

112 { return m_list.size(); }

◆ operator=()

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

◆ pop_back()

void ObjectList::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 153 of file ObjectList.h.

153  {
154  auto position = m_list.back();
155  // Set the back pointer to 0 to avoid repetitional searching
156  // for the object in the container, and deleting the object
157  position->setParent( nullptr );
158  delete position;
159  // Removing from the container itself
160  m_list.pop_back();
161  }

◆ push_back()

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

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

Definition at line 133 of file ObjectList.h.

133  {
134  if ( value->parent() ) { const_cast<ObjectContainerBase*>( value->parent() )->remove( value ); }
135  value->setParent( this );
136  m_list.push_back( value );
137  }

◆ rbegin() [1/2]

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

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

Definition at line 93 of file ObjectList.h.

93 { return m_list.rbegin(); }

◆ rbegin() [2/2]

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

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

Definition at line 96 of file ObjectList.h.

96 { return m_list.rbegin(); }

◆ remove()

long ObjectList::remove ( ContainedObject value)
inlineoverride

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

Definition at line 165 of file ObjectList.h.

165  {
166  // Find the object of value value
167  long idx = 0;
168  auto iter = std::find_if( begin(), end(), [&]( const ContainedObject* i ) { return i == value; } );
169  if ( iter == end() ) {
170  // Object cannot be released from the container,
171  // as it is not contained in it
172  return -1;
173  }
174 
175  // Set the back pointer to 0 to avoid repetitional searching
176  // for the object in the container and deleting the object
177  ( *iter )->setParent( nullptr );
178  erase( iter );
179  return idx;
180  }

◆ rend() [1/2]

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

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

Definition at line 99 of file ObjectList.h.

99 { return m_list.rend(); }

◆ rend() [2/2]

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

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

Definition at line 102 of file ObjectList.h.

102 { return m_list.rend(); }

◆ size()

ObjectList<TYPE>::size_type ObjectList::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 107 of file ObjectList.h.

107  {
108  // C++11: std::list::size is constant (pre C++11 it could be linear!)
109  return m_list.size();
110  }

Member Data Documentation

◆ m_list

std::list<TYPE*> ObjectList::m_list
private

Definition at line 248 of file ObjectList.h.


The documentation for this class was generated from the following files:
gaudirun.s
string s
Definition: gaudirun.py:346
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:133
ObjectList::clear
void clear()
Clear the entire content of the container and delete all contained objects.
Definition: ObjectList.h:214
ObjectList::end
ObjectList< TYPE >::iterator end()
Return an iterator pointing to the end of the container.
Definition: ObjectList.h:86
ObjectList::remove
long remove(ContainedObject *value) override
Release object from the container (the pointer will be removed from the container,...
Definition: ObjectList.h:165
ObjectList::m_list
std::list< TYPE * > m_list
Definition: ObjectList.h:248
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:190
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:87
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:16
ObjectList::begin
ObjectList< TYPE >::iterator begin()
Return an iterator pointing to the beginning of the container.
Definition: ObjectList.h:80
ObjectContainerBase
Definition: ObjectContainerBase.h:26
ObjectList::classID
static const CLID & classID()
Definition: ObjectList.h:74
ObjectList::value_type
std::list< TYPE * >::value_type value_type
Definition: ObjectList.h:46
ObjectList::size
ObjectList< TYPE >::size_type size() const
Return the size of the container Size means the number of objects stored in the container,...
Definition: ObjectList.h:107
ContainedObject
Definition: ContainedObject.h:37
ObjectList::empty
bool empty() const
Return true if the size of the container is 0.
Definition: ObjectList.h:118