Gaudi Framework, version v23r0 |
Home | Generated: Mon Jan 30 2012 |
template class KeyedContainer, KeyedContainer.h More...
#include <KeyedContainer.h>
Classes | |
struct | _InsertRelease |
Internal functor for insertion of objects. More... | |
struct | _RemoveRelease |
Internal functor for insertion of objects. More... | |
Public Types | |
typedef DATATYPE | contained_type |
Definition of the contained object type. | |
typedef MAPPING | container_type |
Definition of the implementing container type. | |
typedef std::vector < contained_type * > | seq_type |
General container specific type definitions. | |
typedef contained_type::key_type | key_type |
Definition of the key type: re-use definition of contained type. | |
typedef seq_type::value_type | value_type |
Sequential access: definition of type stored in sequential container. | |
typedef seq_type::reference | reference |
Sequential access: reference type used in sequential container. | |
typedef seq_type::const_reference | const_reference |
Sequential access: const reference type used in sequential container. | |
typedef seq_type::iterator | iterator |
Sequential access: iterator type used in sequential container. | |
typedef seq_type::const_iterator | const_iterator |
Sequential access: const iterator type used in sequential container. | |
typedef seq_type::reverse_iterator | reverse_iterator |
Sequential access: reverse iterator type used in sequential container. | |
typedef seq_type::const_reverse_iterator | const_reverse_iterator |
Sequential access: const reverse iterator type used in sequential container. | |
Public Member Functions | |
Constructors/Destructors | |
KeyedContainer (void) | |
Standard Constructor. | |
virtual | ~KeyedContainer () |
Destructor. | |
NOT FOR GENERAL USE ObjectContainerBase function overloads. | |
The implementation of these methods ensure the behaviour of the class as a type of class ObjectContainerBase. This base class and its behaviour are only used by "generic" object handlers. These classes collaborate with several classes such as the
For this reason, the entry points in this section are reserved for "generic" object handling and should NOT be used in public. | |
virtual size_type | numberOfObjects () const |
ObjectContainerBase overload: Number of objects in the container. | |
virtual long | add (ContainedObject *pObject) |
ObjectContainerBase overload: Add an object to the container. | |
virtual long | remove (ContainedObject *pObject) |
ObjectContainerBase overload: Remove an object from the container. | |
virtual ContainedObject * | containedObject (long key_value) const |
ObjectContainerBase overload: Retrieve the object by reference given the long integer representation of the object's key. | |
virtual long | index (const ContainedObject *p) const |
ObjectContainerBase overload: Retrieve the full long integer representation of the object's key from the object base class pointer. | |
virtual size_type | containedObjects (std::vector< ContainedObject * > &v) const |
Retrieve the full content of the object container. | |
Container related implementation. | |
These methods allow to manipulate the container as a whole and to retrieve information about the internal behaviour of the container. | |
size_type | size () const |
Number of objects in the container. | |
bool | empty () const |
For consistency with STL: check if container is empty. | |
void | reserve (size_type value) |
Reserve place for "value" objects in the container. | |
void | clear () |
Clear the entire content and erase the objects from the container. | |
virtual const std::vector < const ContainedObject * > * | containedObjects () const |
Retrieve the full content of the object container by reference. | |
virtual StatusCode | update () |
Reconfigure direct access to elements (Needed by POOL data loading) This function reuses the "update" callback of the generic DataObject base class. | |
Sequential array access to objects using iterators. | |
Sequential object access using iterators is much faster then object access by key. In case all objects of the container should be addressed, use iterators rather than direct object access.
| |
iterator | begin () |
Retrieve start iterator. | |
const_iterator | begin () const |
Retrieve start const iterator. | |
iterator | end () |
Retrieve terminating iterator. | |
const_iterator | end () const |
Retrieve terminating const iterator. | |
reverse_iterator | rbegin () |
reverse_iterator returns the beginning of the reversed container | |
const_reverse_iterator | rbegin () const |
const reverse_iterator returns the beginning of the reversed container | |
reverse_iterator | rend () |
reverse_iterator pointing to the end of the reversed container | |
const_reverse_iterator | rend () const |
const reverse_iterator pointing to the end of the reversed container | |
Random access to objects in the container. | |
Access to objects is given by Key. Please note, that random object access is nearly in all cases significantly slower than sequential access. If all objects in the contaienr should be addresses sequentially, use iterators rather than direct access. Direct access should only be used for selective retrieval of objects. | |
value_type | object (const key_type &kval) const |
Object access by key. | |
value_type | operator() (const key_type &kval) const |
STL algorithms support for object access. | |
Insert/Remove objects from the container. | |
Objects generally are identified by key. Since keys are stored with the objects, insertions and removals are possible by key or by reference. | |
long | erase (const key_type &kval) |
Remove/erase object (identified by key) from the container. | |
long | erase (const value_type val) |
Remove/erase object (identified by pointer value) from the container. | |
long | erase (iterator pos) |
Remove/erase object (identified by iterator) from the container. | |
void | erase (iterator pos_start, iterator pos_stop, bool use_temp=false) |
Remove/erase objects by iterator range. | |
const key_type & | insert (const value_type val, const key_type &kval) |
Insert entry to the container with a valid key. | |
const key_type & | insert (const value_type val) |
Insert entry to the container with automatic key assignment. | |
Private Types | |
typedef Containers::traits < container_type, contained_type > | traits |
Traits class definition. | |
Friends | |
struct | GaudiDict::KeyedContainerDict< DATATYPE > |
Implementation helpers. | |
container_type | m_cont |
Map container to facilitate object access by key. | |
seq_type | m_sequential |
Array to allow sequential access to the object (can be ordered). | |
seq_type * | m_random |
Array to allow random access to objects (not exposed) | |
FORCE_INLINE value_type | i_object (const key_type &k) const |
Internal function to access objects within the container. | |
long | i_erase (const_reference v, const key_type &k) |
Internal function to erase an object from the container. | |
DataObject virtual function overloads. | |
The implementation of these methods is required by the DataObject base class and determines the persistent run-time-type information. | |
virtual const CLID & | clID () const |
Retrieve class ID. | |
static const CLID & | classID () |
Retrieve class ID. |
template class KeyedContainer, KeyedContainer.h
This class represents a container, where the contained objects are accessed by a key. Such a key can be any class, which is able to convert to and from a 32-bit (long) integer.
To insert objects into the container, this implementation determines the key in the following way:
Access to objects is given two-fold:
The KeyedContainer class uses for further specialization a traits class. By specializing these traits extra behaviour can be forced on request for special containers or special keys.
Definition at line 64 of file KeyedContainer.h.
typedef seq_type::const_iterator KeyedContainer< DATATYPE, MAPPING >::const_iterator |
Sequential access: const iterator type used in sequential container.
Definition at line 93 of file KeyedContainer.h.
typedef seq_type::const_reference KeyedContainer< DATATYPE, MAPPING >::const_reference |
Sequential access: const reference type used in sequential container.
Definition at line 89 of file KeyedContainer.h.
typedef seq_type::const_reverse_iterator KeyedContainer< DATATYPE, MAPPING >::const_reverse_iterator |
Sequential access: const reverse iterator type used in sequential container.
Definition at line 99 of file KeyedContainer.h.
typedef DATATYPE KeyedContainer< DATATYPE, MAPPING >::contained_type |
Definition of the contained object type.
Definition at line 70 of file KeyedContainer.h.
typedef MAPPING KeyedContainer< DATATYPE, MAPPING >::container_type |
Definition of the implementing container type.
Definition at line 72 of file KeyedContainer.h.
typedef seq_type::iterator KeyedContainer< DATATYPE, MAPPING >::iterator |
Sequential access: iterator type used in sequential container.
Definition at line 91 of file KeyedContainer.h.
typedef contained_type::key_type KeyedContainer< DATATYPE, MAPPING >::key_type |
Definition of the key type: re-use definition of contained type.
Definition at line 83 of file KeyedContainer.h.
typedef seq_type::reference KeyedContainer< DATATYPE, MAPPING >::reference |
Sequential access: reference type used in sequential container.
Definition at line 87 of file KeyedContainer.h.
typedef seq_type::reverse_iterator KeyedContainer< DATATYPE, MAPPING >::reverse_iterator |
Sequential access: reverse iterator type used in sequential container.
Definition at line 95 of file KeyedContainer.h.
typedef std::vector<contained_type*> KeyedContainer< DATATYPE, MAPPING >::seq_type |
General container specific type definitions.
The following type definitions are generic to most STL containers and are also presented by the KeyedContainer class. These forward declarations typically are used by STL algorithms. Definition of the STL sequential access type
Definition at line 81 of file KeyedContainer.h.
typedef Containers::traits<container_type, contained_type> KeyedContainer< DATATYPE, MAPPING >::traits [private] |
Traits class definition.
Specializing traits allows to specialize the container implementation for special needs.
Definition at line 105 of file KeyedContainer.h.
typedef seq_type::value_type KeyedContainer< DATATYPE, MAPPING >::value_type |
Sequential access: definition of type stored in sequential container.
Definition at line 85 of file KeyedContainer.h.
KeyedContainer< DATATYPE, MAPPING >::KeyedContainer | ( | void | ) | [inline] |
Standard Constructor.
Definition at line 180 of file KeyedContainer.h.
{ // avoid problems with strict-aliasing rules seq_type** rptr = &m_random; seq_type* sptr = &m_sequential; m_cont.setup((void*)sptr,(void**)rptr); }
KeyedContainer< DATATYPE, MAPPING >::~KeyedContainer | ( | ) | [inline, virtual] |
long KeyedContainer< DATATYPE, MAPPING >::add | ( | ContainedObject * | pObject ) | [inline, virtual] |
ObjectContainerBase overload: Add an object to the container.
Plese see the documentation of the member function
const key_type& insert(DATATYPE* pObject)
for further details.
pObject | Pointer to the object to be inserted into the container. |
Implements ObjectContainerBase.
Definition at line 606 of file KeyedContainer.h.
{ return traits::identifier(insert(dynamic_cast<typename seq_type::value_type>(pObject))); }
iterator KeyedContainer< DATATYPE, MAPPING >::begin | ( | void | ) | [inline] |
Retrieve start iterator.
Definition at line 308 of file KeyedContainer.h.
{ return m_sequential.begin(); }
const_iterator KeyedContainer< DATATYPE, MAPPING >::begin | ( | void | ) | const [inline] |
Retrieve start const iterator.
Definition at line 310 of file KeyedContainer.h.
{ return m_sequential.begin(); }
static const CLID& KeyedContainer< DATATYPE, MAPPING >::classID | ( | ) | [inline, static] |
Retrieve class ID.
Reimplemented from DataObject.
Definition at line 199 of file KeyedContainer.h.
{ static CLID clid = contained_type::classID() + container_type::classID(); return clid; }
void KeyedContainer< DATATYPE, MAPPING >::clear | ( | void | ) | [inline] |
Clear the entire content and erase the objects from the container.
Definition at line 280 of file KeyedContainer.h.
virtual const CLID& KeyedContainer< DATATYPE, MAPPING >::clID | ( | ) | const [inline, virtual] |
Retrieve class ID.
Reimplemented from DataObject.
Definition at line 197 of file KeyedContainer.h.
{ return this->classID(); }
virtual ContainedObject* KeyedContainer< DATATYPE, MAPPING >::containedObject | ( | long | key_value ) | const [inline, virtual] |
ObjectContainerBase overload: Retrieve the object by reference given the long integer representation of the object's key.
Implements ObjectContainerBase.
Definition at line 253 of file KeyedContainer.h.
{ return i_object( traits::makeKey( key_value ) ); }
KeyedContainer< DATATYPE, MAPPING >::size_type KeyedContainer< DATATYPE, MAPPING >::containedObjects | ( | std::vector< ContainedObject * > & | v ) | const [inline, virtual] |
Retrieve the full content of the object container.
v | Vector of contained objects, which will host all objects contained in this container. |
Definition at line 591 of file KeyedContainer.h.
{ typename seq_type::const_iterator i = m_sequential.begin(); typename seq_type::const_iterator s = m_sequential.end(); vec.clear(); vec.reserve(size()); for ( ; i != s; i++ ) { ContainedObject* p = const_cast<typename seq_type::value_type>(*i); vec.push_back(p); } return vec.size(); }
const std::vector< const ContainedObject * > * KeyedContainer< DATATYPE, MAPPING >::containedObjects | ( | ) | const [inline, virtual] |
Retrieve the full content of the object container by reference.
Returned is the random access container if in sequntial direct access mode. Otherwise the sequential access container is returned
Definition at line 530 of file KeyedContainer.h.
{ return (const std::vector<const ContainedObject*>*) ((0==m_cont.isDirect()) ? m_random : &m_sequential); }
bool KeyedContainer< DATATYPE, MAPPING >::empty | ( | void | ) | const [inline] |
For consistency with STL: check if container is empty.
Definition at line 276 of file KeyedContainer.h.
{ return m_sequential.empty(); }
iterator KeyedContainer< DATATYPE, MAPPING >::end | ( | void | ) | [inline] |
Retrieve terminating iterator.
Definition at line 312 of file KeyedContainer.h.
{ return m_sequential.end(); }
const_iterator KeyedContainer< DATATYPE, MAPPING >::end | ( | void | ) | const [inline] |
Retrieve terminating const iterator.
Definition at line 314 of file KeyedContainer.h.
{ return m_sequential.end(); }
long KeyedContainer< DATATYPE, MAPPING >::erase | ( | const key_type & | kval ) | [inline] |
Remove/erase object (identified by key) from the container.
kval | Key to identify the object within the container. |
Definition at line 378 of file KeyedContainer.h.
{ return i_erase(0, kval); }
long KeyedContainer< DATATYPE, MAPPING >::erase | ( | iterator | pos ) | [inline] |
Remove/erase object (identified by iterator) from the container.
This member function removes an object, which is identified by its reference from the container. No key value is supplied. To identify the object within the container, the key of the object is used as it can be retrieved using the KeyedObject::key() method.
val | Reference to object to be removed from the container. |
Definition at line 424 of file KeyedContainer.h.
{ return erase(*pos); }
long KeyedContainer< DATATYPE, MAPPING >::erase | ( | const value_type | val ) | [inline] |
Remove/erase object (identified by pointer value) from the container.
This member function removes an object, which is identified by its reference from the container. No key value is supplied. To identify the object within the container, the key of the object is used as it can be retrieved using the KeyedObject::key() method.
val | Reference to object to be removed from the container. |
Definition at line 400 of file KeyedContainer.h.
{ return (val) ? i_erase(val, val->key()) : (long) Containers::OBJ_NOT_FOUND; }
void KeyedContainer< DATATYPE, MAPPING >::erase | ( | iterator | pos_start, |
iterator | pos_stop, | ||
bool | use_temp = false |
||
) | [inline] |
Remove/erase objects by iterator range.
This member function removes all objects, which are within the sequential iterator range [pos_start, pos_stop[.
pos_start | Starting iterator of the range to be removed. |
pos_stop | Starting iterator of the range to be removed. |
use_temp | Flag to indicate that a temporary arry should be used. |
Definition at line 638 of file KeyedContainer.h.
{ bool is_start = start_pos == m_sequential.begin(); bool is_stop = stop_pos == m_sequential.end(); if ( is_start && is_stop ) { // Nothing special. Taken care of by Keyed object manager } else if ( is_start || is_stop || use_tmp ) { std::vector<DATATYPE*> tmp(m_sequential.begin(), start_pos); tmp.insert(tmp.end(), stop_pos, m_sequential.end()); std::for_each(tmp.begin(), tmp.end(), traits::addRef); this->erase(m_sequential.begin(), m_sequential.end()); std::for_each(tmp.begin(), tmp.end(), _InsertRelease(this)); return; } std::for_each(start_pos, stop_pos, _RemoveRelease(this)); seq_type *sptr = &m_sequential; // avoid problems with strict-aliasing rules std::vector<void*>* v = (std::vector<void*>*)sptr; std::vector<void*>::iterator i1 = v->begin() + std::distance(m_sequential.begin(), start_pos); std::vector<void*>::iterator i2 = v->begin() + std::distance(m_sequential.begin(), stop_pos); m_cont.erase(i1, i2); }
long KeyedContainer< DATATYPE, MAPPING >::i_erase | ( | const_reference | v, |
const key_type & | k | ||
) | [inline, private] |
Internal function to erase an object from the container.
Definition at line 140 of file KeyedContainer.h.
{ value_type p = value_type(m_cont.erase(traits::hash(k), v)); if ( p ) { if ( p->parent() == this ) { p->setParent(0); } } return traits::release(p) <= 0 ? (long) Containers::OBJ_ERASED : (long) Containers::OBJ_DELETED; }
FORCE_INLINE value_type KeyedContainer< DATATYPE, MAPPING >::i_object | ( | const key_type & | k ) | const [inline, private] |
Internal function to access objects within the container.
Definition at line 133 of file KeyedContainer.h.
{ return 0==m_cont.isDirect() ? value_type(*(m_random->begin()+traits::hash(k))) : value_type(m_cont.object(traits::hash(k))); }
long KeyedContainer< DATATYPE, MAPPING >::index | ( | const ContainedObject * | p ) | const [inline, virtual] |
ObjectContainerBase overload: Retrieve the full long integer representation of the object's key from the object base class pointer.
Implements ObjectContainerBase.
Definition at line 581 of file KeyedContainer.h.
{ const contained_type* ptr = dynamic_cast<const contained_type*>(p); if ( ptr ) return traits::identifier(ptr->key()); return -1; }
const KeyedContainer< DATATYPE, MAPPING >::key_type & KeyedContainer< DATATYPE, MAPPING >::insert | ( | const value_type | val ) |
Insert entry to the container with automatic key assignment.
This member function inserts an element, which is identified by its reference to the container. No key value is supplied. The key used to insert the object is retrieved from the element itself. In the event the object already has a key, the assigned key of the object is used. If no key was assigned to the object, (i.e. the object's key is equal to the invalid key), a key is generated according to the number of objects present in the container.
The object will not be inserted and an exception will be raised under the following conditions:
val | Reference to object to be inserted into the container. |
Definition at line 558 of file KeyedContainer.h.
{ if ( 0 != val ) { if ( val->hasKey() ) { if (m_cont.insert(this,val,val,traits::hash(val->key())) == Containers::OBJ_INSERTED) { traits::addRef(val); return val->key(); } } long k0; if ( m_cont.insert(this, val, val, &k0) == Containers::OBJ_INSERTED ) { traits::setKey(val, traits::makeKey(k0)); traits::addRef(val); return val->key(); } } // Cannot insert object...indicate bad object insertion... Containers::cannotInsertToContainer(); return val->key(); }
const KeyedContainer< DATATYPE, MAPPING >::key_type & KeyedContainer< DATATYPE, MAPPING >::insert | ( | const value_type | val, |
const key_type & | kval | ||
) | [inline] |
Insert entry to the container with a valid key.
This member function inserts an element, which is identified by its reference to the container. The element will be inserted using the specified key. If the object is already keyed, the long representations of the supplied key and the object's key must agree.
The object will not be inserted and an exception will be raised under the following conditions:
val | Reference to object to be inserted into the container. The object reference may NOT be NULL. |
kval | Key to identify the object within the container. |
Definition at line 537 of file KeyedContainer.h.
{ if ( val ) { long k0 = traits::hash(kval); if ( !val->hasKey() || (traits::hash(val->key()) == k0) ) { if(m_cont.insert(this,val,val,k0) == Containers::OBJ_INSERTED) { if ( !val->hasKey() ) traits::setKey(val, kval); traits::addRef(val); return val->key(); } } } // Cannot insert object...indicate bad object insertion... Containers::cannotInsertToContainer(); return val->key(); }
virtual size_type KeyedContainer< DATATYPE, MAPPING >::numberOfObjects | ( | ) | const [inline, virtual] |
ObjectContainerBase overload: Number of objects in the container.
Implements ObjectContainerBase.
Definition at line 222 of file KeyedContainer.h.
{ return m_sequential.size(); }
value_type KeyedContainer< DATATYPE, MAPPING >::object | ( | const key_type & | kval ) | const [inline] |
Object access by key.
Access contained objects by key.
kval | Key of the object to be returned. |
Definition at line 342 of file KeyedContainer.h.
{ return i_object(kval); }
value_type KeyedContainer< DATATYPE, MAPPING >::operator() | ( | const key_type & | kval ) | const [inline] |
STL algorithms support for object access.
Access contained objects by key using the operator(), which is demanded by STL algorithms.
kval | Key of the object to be returned. |
Definition at line 353 of file KeyedContainer.h.
{ return i_object(kval); }
const_reverse_iterator KeyedContainer< DATATYPE, MAPPING >::rbegin | ( | ) | const [inline] |
const reverse_iterator returns the beginning of the reversed container
Definition at line 318 of file KeyedContainer.h.
{ return m_sequential.rbegin(); }
reverse_iterator KeyedContainer< DATATYPE, MAPPING >::rbegin | ( | ) | [inline] |
reverse_iterator returns the beginning of the reversed container
Definition at line 316 of file KeyedContainer.h.
{ return m_sequential.rbegin(); }
long KeyedContainer< DATATYPE, MAPPING >::remove | ( | ContainedObject * | pObject ) | [inline, virtual] |
ObjectContainerBase overload: Remove an object from the container.
Because this function is also called from the destructor of The ContainedObject class, it is no longer possible to deduce the key from the object itself. It is hence necessary to relay on the **NON-EXISTENCE** of virtual inheritance, ie. (void*)pObject = (void*)(contained_object). If the virtual object table is still intact, the normal erase is called.
pObject | Pointer to the object to be removed from the container. |
Implements ObjectContainerBase.
Definition at line 613 of file KeyedContainer.h.
{ contained_type* p1 = dynamic_cast<contained_type*>(p); if ( p1 ) { // Normal case; object still fully intact return this->erase(p1); } else if ( p ) { const ObjectContainerBase* par = p->parent(); // The following should never occur: object is in a funny state, // Because the parent was explicitly set to NULL in the // KeyeObject destructor. // - It cannot be a KeyedObject: It would not have a parent // - Still the parent is present: We are not in the destructor // of KeyedObject if ( par ) { Containers::invalidContainerOperation(); } return m_cont.erase(0, p)==0 ? (long) Containers::OBJ_ERASED : (long) Containers::OBJ_NOT_FOUND; } return (long) Containers::OBJ_NOT_FOUND; }
reverse_iterator KeyedContainer< DATATYPE, MAPPING >::rend | ( | ) | [inline] |
reverse_iterator pointing to the end of the reversed container
Definition at line 320 of file KeyedContainer.h.
{ return m_sequential.rend(); }
const_reverse_iterator KeyedContainer< DATATYPE, MAPPING >::rend | ( | ) | const [inline] |
const reverse_iterator pointing to the end of the reversed container
Definition at line 322 of file KeyedContainer.h.
{ return m_sequential.rend(); }
void KeyedContainer< DATATYPE, MAPPING >::reserve | ( | size_type | value ) | [inline] |
Reserve place for "value" objects in the container.
Definition at line 278 of file KeyedContainer.h.
{ m_cont.reserve(value); }
size_type KeyedContainer< DATATYPE, MAPPING >::size | ( | void | ) | const [inline] |
Number of objects in the container.
Definition at line 274 of file KeyedContainer.h.
{ return m_sequential.size(); }
StatusCode KeyedContainer< DATATYPE, MAPPING >::update | ( | ) | [inline, virtual] |
Reconfigure direct access to elements (Needed by POOL data loading) This function reuses the "update" callback of the generic DataObject base class.
Reimplemented from DataObject.
Definition at line 499 of file KeyedContainer.h.
{ int count = 0; m_cont.clearDirect(); typename seq_type::iterator i = m_sequential.begin(); typename seq_type::iterator s = m_sequential.end(); for ( ; i != s; i++ ) { typename seq_type::value_type v = *i; if ( v ) { if ( !v->hasKey() ) { traits::setKey(v, v->key()); traits::addRef(v); } long k0 = traits::hash(v->key()); if(m_cont.insertDirect(this, v, v, k0) == Containers::OBJ_INSERTED) { } } else { ++count; } } if ( count > 0 ) { Containers::cannotInsertToContainer(); } return StatusCode::SUCCESS; }
friend struct GaudiDict::KeyedContainerDict< DATATYPE > [friend] |
Definition at line 66 of file KeyedContainer.h.
container_type KeyedContainer< DATATYPE, MAPPING >::m_cont [private] |
Map container to facilitate object access by key.
Definition at line 111 of file KeyedContainer.h.
seq_type* KeyedContainer< DATATYPE, MAPPING >::m_random [private] |
Array to allow random access to objects (not exposed)
Definition at line 115 of file KeyedContainer.h.
seq_type KeyedContainer< DATATYPE, MAPPING >::m_sequential [private] |
Array to allow sequential access to the object (can be ordered).
Definition at line 113 of file KeyedContainer.h.