| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# KeyedContainer< DATATYPE, MAPPING > Class Template Reference

`#include <KeyedContainer.h>`

Inheritance diagram for KeyedContainer< DATATYPE, MAPPING >:

[legend]
Collaboration diagram for KeyedContainer< DATATYPE, MAPPING >:

[legend]

List of all members.

## Detailed Description

### template<class DATATYPE, class MAPPING = Containers::HashMap>
class KeyedContainer< DATATYPE, MAPPING >

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:

- If the object is already keyed, the object's key is kept and cannot be modified.
- If the object is NOT keyed, and a key is supplied, this key is used to register the object in the map and the same key is given to the object.
- If the object is NOT keyed, and NO key is supplied, a key is generated by the map implementation and this key is given to the object.

- It is not possible to insert two objects with the same key into the same container. This causes an exception.

Access to objects is given two-fold:

- Using iterators. This access is very efficient. The container however, may not be manipulated: No objects may not be inserted or removed using iterators.
- Using object keys: This access patterns provides random access to objects.

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.

Author:
  M.Frank CERN/LHCb

Version:
  1.0

Definition at line 64 of file KeyedContainer.h.

## 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.
## 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 SmartRef classes. Generic converters. Interfaces for interactivity (e.g. Python) 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 void | configureDirectAccess ()
| Reconfigure direct access to elements (Needed by POOL data loading).
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. If the container is accessed through the iterators defined below, the elements may be sorted according to the user needs. The container can be accesses in both const and non-const mode. Iterations are supported in both directions: From the beginning to the end and the reverse.
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 >
## Classes
struct | _InsertRelease
| Internal functor for insertion of objects. More...
struct | _RemoveRelease
| Internal functor for insertion of objects. More...

## Member Typedef Documentation

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef DATATYPE KeyedContainer< DATATYPE, MAPPING >::contained_type

Definition of the contained object type.

Definition at line 71 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef MAPPING KeyedContainer< DATATYPE, MAPPING >::container_type

Definition of the implementing container type.

Definition at line 73 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

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 82 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef contained_type::key_type KeyedContainer< DATATYPE, MAPPING >::key_type

Definition of the key type: re-use definition of contained type.

Definition at line 84 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef seq_type::value_type KeyedContainer< DATATYPE, MAPPING >::value_type

Sequential access: definition of type stored in sequential container.

Definition at line 86 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef seq_type::reference KeyedContainer< DATATYPE, MAPPING >::reference

Sequential access: reference type used in sequential container.

Definition at line 88 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef seq_type::const_reference KeyedContainer< DATATYPE, MAPPING >::const_reference

Sequential access: const reference type used in sequential container.

Definition at line 90 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef seq_type::iterator KeyedContainer< DATATYPE, MAPPING >::iterator

Sequential access: iterator type used in sequential container.

Definition at line 92 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef seq_type::const_iterator KeyedContainer< DATATYPE, MAPPING >::const_iterator

Sequential access: const iterator type used in sequential container.

Definition at line 94 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

typedef seq_type::reverse_iterator KeyedContainer< DATATYPE, MAPPING >::reverse_iterator

Sequential access: reverse iterator type used in sequential container.

Definition at line 96 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

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 100 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

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 106 of file KeyedContainer.h.

## Constructor & Destructor Documentation

template<class DATATYPE, class MAPPING = Containers::HashMap>

KeyedContainer< DATATYPE, MAPPING >::KeyedContainer | ( | void |  | ) | `[inline]`

Standard Constructor.

Definition at line 181 of file KeyedContainer.h.

    00182   {
    00183     // avoid problems with strict-aliasing rules
    00184     seq_type** rptr = &m_random;
    00185     seq_type*  sptr = &m_sequential;
    00186     m_cont.setup((void*)sptr,(void**)rptr);
    00187   }

template<class DATATYPE, class MAPPING>

KeyedContainer< DATATYPE, MAPPING >::~KeyedContainer | ( |  | ) | `[inline, virtual]`

Destructor.

Inline code for keyed container class.

Definition at line 489 of file KeyedContainer.h.

    00490 {
    00491   erase(begin(), end());
    00492   m_cont.clear();
    00493 }

## Member Function Documentation

template<class DATATYPE, class MAPPING = Containers::HashMap>

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 134 of file KeyedContainer.h.

    00134                                                              {
    00135     return 0==m_cont.isDirect()
    00136       ? value_type(*(m_random->begin()+traits::hash(k)))
    00137       : value_type(m_cont.object(traits::hash(k)));
    00138   }

template<class DATATYPE, class MAPPING = Containers::HashMap>

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 141 of file KeyedContainer.h.

    00141                                                        {
    00142     value_type p = value_type(m_cont.erase(traits::hash(k), v));
    00143     if ( p )    {
    00144       if ( p->parent() == this )  {
    00145         p->setParent(0);
    00146       }
    00147     }
    00148     return traits::release(p) <= 0 ? (long) Containers::OBJ_ERASED
    00149                                    : (long) Containers::OBJ_DELETED;
    00150   }

template<class DATATYPE, class MAPPING = Containers::HashMap>

virtual const CLID& KeyedContainer< DATATYPE, MAPPING >::clID | ( |  | ) | const`[inline, virtual]`

Retrieve class ID.

Reimplemented from DataObject.

Definition at line 198 of file KeyedContainer.h.

    00198 {              return this->classID(); }

template<class DATATYPE, class MAPPING = Containers::HashMap>

static const CLID& KeyedContainer< DATATYPE, MAPPING >::classID | ( |  | ) | `[inline, static]`

Retrieve class ID.

Reimplemented from DataObject.

Definition at line 200 of file KeyedContainer.h.

    00200                                         {
    00201     static CLID clid = contained_type::classID() + container_type::classID();
    00202     return clid;
    00203   }

template<class DATATYPE, class MAPPING = Containers::HashMap>

virtual size_type KeyedContainer< DATATYPE, MAPPING >::numberOfObjects | ( |  | ) | const`[inline, virtual]`

ObjectContainerBase overload: Number of objects in the container.

Implements ObjectContainerBase.

Definition at line 223 of file KeyedContainer.h.

    00223 {  return m_sequential.size();       }

template<class DATATYPE, class MAPPING>

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.

Parameters:

  | pObject | Pointer to the object to be inserted into the container.

Returns:
  long integer representation of the key value.

Implements ObjectContainerBase.

Definition at line 603 of file KeyedContainer.h.

    00604 {
    00605   return traits::identifier(insert(dynamic_cast<typename seq_type::value_type>(pObject)));
    00606 }

template<class DATATYPE, class MAPPING>

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.

Parameters:

  | pObject | Pointer to the object to be removed from the container.

Implements ObjectContainerBase.

Definition at line 610 of file KeyedContainer.h.

    00611 {
    00612   contained_type* p1 = dynamic_cast<contained_type*>(p);
    00613   if ( p1 )    {  // Normal case; object still fully intact
    00614     return this->erase(p1);
    00615   }
    00616   else if ( p )   {
    00617     const ObjectContainerBase* par = p->parent();
    00618     // The following should never occur: object is in a funny state,
    00619     // Because the parent was explicitly set to NULL in the
    00620     // KeyeObject destructor.
    00621     // - It cannot be a KeyedObject:  It would not have a parent
    00622     // - Still the parent is present: We are not in the destructor
    00623     //                                of KeyedObject
    00624     if ( par )  {
    00625       Containers::invalidContainerOperation();
    00626     }
    00627     return m_cont.erase(0, p)==0 ? (long) Containers::OBJ_ERASED
    00628                                  : (long) Containers::OBJ_NOT_FOUND;
    00629   }
    00630   return (long) Containers::OBJ_NOT_FOUND;
    00631 }

template<class DATATYPE, class MAPPING = Containers::HashMap>

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 254 of file KeyedContainer.h.

    00254                                                                   {
    00255     return i_object( traits::makeKey( key_value ) );
    00256   }

template<class DATATYPE, class MAPPING>

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 578 of file KeyedContainer.h.

    00579 {
    00580   const contained_type* ptr = dynamic_cast<const contained_type*>(p);
    00581   if ( ptr ) return traits::identifier(ptr->key());
    00582   return -1;
    00583 }

template<class DATATYPE, class MAPPING>

KeyedContainer< DATATYPE, MAPPING >::size_type KeyedContainer< DATATYPE, MAPPING >::containedObjects | ( | std::vector< ContainedObject * > & | v | ) | const`[inline, virtual]`

Retrieve the full content of the object container.

Parameters:

  | v | Vector of contained objects, which will host all objects contained in this container.

Returns:
  Number of objects returned in v.

Definition at line 588 of file KeyedContainer.h.

    00589 {
    00590   typename seq_type::const_iterator i = m_sequential.begin();
    00591   typename seq_type::const_iterator s = m_sequential.end();
    00592   vec.clear();
    00593   vec.reserve(size());
    00594   for ( ; i != s; i++ )  {
    00595     ContainedObject* p = const_cast<typename seq_type::value_type>(*i);
    00596     vec.push_back(p);
    00597   }
    00598   return vec.size();
    00599 }

template<class DATATYPE, class MAPPING = Containers::HashMap>

size_type KeyedContainer< DATATYPE, MAPPING >::size | ( | void |  | ) | const`[inline]`

Number of objects in the container.

Definition at line 275 of file KeyedContainer.h.

    00275 {      return m_sequential.size();    }

template<class DATATYPE, class MAPPING = Containers::HashMap>

bool KeyedContainer< DATATYPE, MAPPING >::empty | ( | void |  | ) | const`[inline]`

For consistency with STL: check if container is empty.

Definition at line 277 of file KeyedContainer.h.

    00277 {      return m_sequential.empty();   }

template<class DATATYPE, class MAPPING = Containers::HashMap>

void KeyedContainer< DATATYPE, MAPPING >::reserve | ( | size_type | value | ) | `[inline]`

Reserve place for "value" objects in the container.

Definition at line 279 of file KeyedContainer.h.

    00279 {      m_cont.reserve(value);          }

template<class DATATYPE, class MAPPING = Containers::HashMap>

void KeyedContainer< DATATYPE, MAPPING >::clear | ( | void |  | ) | `[inline]`

Clear the entire content and erase the objects from the container.

Definition at line 281 of file KeyedContainer.h.

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

template<class DATATYPE, class MAPPING>

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

Returns:
  Reference to sequencal access container.

Definition at line 527 of file KeyedContainer.h.

    00527                                                            {
    00528   return (const std::vector<const ContainedObject*>*)
    00529     ((0==m_cont.isDirect()) ? m_random : &m_sequential);
    00530 }

template<class DATATYPE, class MAPPING>

void KeyedContainer< DATATYPE, MAPPING >::configureDirectAccess | ( |  | ) | `[inline, virtual]`

Reconfigure direct access to elements (Needed by POOL data loading).

Definition at line 497 of file KeyedContainer.h.

    00498 {
    00499   int count = 0;
    00500   m_cont.clearDirect();
    00501   typename seq_type::iterator i = m_sequential.begin();
    00502   typename seq_type::iterator s = m_sequential.end();
    00503   for ( ; i != s; i++ )  {
    00504     typename seq_type::value_type v = *i;
    00505     if ( v )  {
    00506       if ( !v->hasKey() ) {
    00507         traits::setKey(v, v->key());
    00508         traits::addRef(v);
    00509       }
    00510       long k0 = traits::hash(v->key());
    00511       if(m_cont.insertDirect(this, v, v, k0) == Containers::OBJ_INSERTED)   {
    00512       }
    00513     }
    00514     else  {
    00515       ++count;
    00516     }
    00517   }
    00518   if ( count > 0 )  {
    00519     Containers::cannotInsertToContainer();
    00520   }
    00521 }

template<class DATATYPE, class MAPPING = Containers::HashMap>

iterator KeyedContainer< DATATYPE, MAPPING >::begin | ( | void |  | ) | `[inline]`

Retrieve start iterator.

Definition at line 306 of file KeyedContainer.h.

    00306 {      return m_sequential.begin();   }

template<class DATATYPE, class MAPPING = Containers::HashMap>

const_iterator KeyedContainer< DATATYPE, MAPPING >::begin | ( | void |  | ) | const`[inline]`

Retrieve start const iterator.

Definition at line 308 of file KeyedContainer.h.

    00308 {      return m_sequential.begin();   }

template<class DATATYPE, class MAPPING = Containers::HashMap>

iterator KeyedContainer< DATATYPE, MAPPING >::end | ( | void |  | ) | `[inline]`

Retrieve terminating iterator.

Definition at line 310 of file KeyedContainer.h.

    00310 {      return m_sequential.end();     }

template<class DATATYPE, class MAPPING = Containers::HashMap>

const_iterator KeyedContainer< DATATYPE, MAPPING >::end | ( | void |  | ) | const`[inline]`

Retrieve terminating const iterator.

Definition at line 312 of file KeyedContainer.h.

    00312 {      return m_sequential.end();     }

template<class DATATYPE, class MAPPING = Containers::HashMap>

reverse_iterator KeyedContainer< DATATYPE, MAPPING >::rbegin | ( | void |  | ) | `[inline]`

reverse_iterator returns the beginning of the reversed container

Definition at line 314 of file KeyedContainer.h.

    00314 {      return m_sequential.rbegin();  }

template<class DATATYPE, class MAPPING = Containers::HashMap>

const_reverse_iterator KeyedContainer< DATATYPE, MAPPING >::rbegin | ( | void |  | ) | const`[inline]`

const reverse_iterator returns the beginning of the reversed container

Definition at line 316 of file KeyedContainer.h.

    00316 {      return m_sequential.rbegin();  }

template<class DATATYPE, class MAPPING = Containers::HashMap>

reverse_iterator KeyedContainer< DATATYPE, MAPPING >::rend | ( | void |  | ) | `[inline]`

reverse_iterator pointing to the end of the reversed container

Definition at line 318 of file KeyedContainer.h.

    00318 {      return m_sequential.rend();    }

template<class DATATYPE, class MAPPING = Containers::HashMap>

const_reverse_iterator KeyedContainer< DATATYPE, MAPPING >::rend | ( | void |  | ) | const`[inline]`

const reverse_iterator pointing to the end of the reversed container

Definition at line 320 of file KeyedContainer.h.

    00320 {      return m_sequential.rend();    }

template<class DATATYPE, class MAPPING = Containers::HashMap>

value_type KeyedContainer< DATATYPE, MAPPING >::object | ( | const key_type & | kval | ) | const`[inline]`

Object access by key.

Access contained objects by key.

Parameters:

  | kval | Key of the object to be returned.

Returns:
  Valid reference to the requested object. If the key of the requested object cannot be found in the container a null reference is returned.

Definition at line 340 of file KeyedContainer.h.

    00340 {  return i_object(kval);  }

template<class DATATYPE, class MAPPING = Containers::HashMap>

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.

Parameters:

  | kval | Key of the object to be returned.

Returns:
  Valid reference to the requested object. If the key of the requested object cannot be found in the container a null reference is returned.

Definition at line 351 of file KeyedContainer.h.

    00351 {  return i_object(kval);  }

template<class DATATYPE, class MAPPING = Containers::HashMap>

long KeyedContainer< DATATYPE, MAPPING >::erase | ( | const key_type & | kval | ) | `[inline]`

Remove/erase object (identified by key) from the container.

Parameters:

  | kval | Key to identify the object within the container.

Returns:
  Enumeration value from the Containers namespace:
  - OBJ_NOT_FOUND: The indicated object was not found in the container
  - OBJ_ERASED: The indicated object was found and removed from the container. The object was not yet deleted, because its reference count was non zero.
  - OBJ_DELETED The indicated object was found and removed from the container. The object was deleted, because its reference count was zero.

Definition at line 376 of file KeyedContainer.h.

    00376 { return i_erase(0, kval);  }

template<class DATATYPE, class MAPPING = Containers::HashMap>

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.

Parameters:

  | val | Reference to object to be removed from the container.

Returns:
  Enumeration value from the Containers namespace:
  - OBJ_NOT_FOUND: The indicated object was not found in the container
  - OBJ_ERASED: The indicated object was found and removed from the container. The object was not yet deleted, because its reference count was non zero.
  - OBJ_DELETED The indicated object was found and removed from the container. The object was deleted, because its reference count was zero.

Definition at line 398 of file KeyedContainer.h.

    00398                                    {
    00399     return (val) ? i_erase(val, val->key()) : (long) Containers::OBJ_NOT_FOUND;
    00400   }

template<class DATATYPE, class MAPPING = Containers::HashMap>

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.

Parameters:

  | val | Reference to object to be removed from the container.

Returns:
  Enumeration value from the Containers namespace:
  - OBJ_NOT_FOUND: The indicated object was not found in the container
  - OBJ_ERASED: The indicated object was found and removed from the container. The object was not yet deleted, because its reference count was non zero.
  - OBJ_DELETED The indicated object was found and removed from the container. The object was deleted, because its reference count was zero.

Definition at line 422 of file KeyedContainer.h.

    00422 {                return erase(*pos);              }

template<class DATATYPE, class MAPPING>

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[.

Parameters:

  | 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 635 of file KeyedContainer.h.

    00638 {
    00639   bool is_start = start_pos == m_sequential.begin();
    00640   bool is_stop  = stop_pos  == m_sequential.end();
    00641   if ( is_start && is_stop )  {
    00642     // Nothing special. Taken care of by Keyed object manager
    00643   }
    00644   else if ( is_start || is_stop || use_tmp )  {
    00645     std::vector<DATATYPE*> tmp(m_sequential.begin(), start_pos);
    00646     tmp.insert(tmp.end(), stop_pos, m_sequential.end());
    00647     std::for_each(tmp.begin(), tmp.end(), traits::addRef);
    00648     this->erase(m_sequential.begin(), m_sequential.end());
    00649     std::for_each(tmp.begin(), tmp.end(), _InsertRelease(this));
    00650     return;
    00651   }
    00652   std::for_each(start_pos, stop_pos, _RemoveRelease(this));
    00653   seq_type *sptr = &m_sequential; // avoid problems with strict-aliasing rules
    00654   std::vector<void*>* v = (std::vector<void*>*)sptr;
    00655   std::vector<void*>::iterator i1 =
    00656     v->begin() + std::distance(m_sequential.begin(), start_pos);
    00657   std::vector<void*>::iterator i2 =
    00658     v->begin() + std::distance(m_sequential.begin(), stop_pos);
    00659   m_cont.erase(i1, i2);
    00660 }

template<class DATATYPE, class MAPPING>

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:

- The supplied key does not agree with the object's key.
- An object with the supplied key is already present in the container.

Parameters:

  | 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.

Returns:
  Key, which was used to index the object within the container. If the operation is not successful, an exception is thrown.

Definition at line 534 of file KeyedContainer.h.

    00536 {
    00537   if ( val )    {
    00538     long k0 = traits::hash(kval);
    00539     if ( !val->hasKey() || (traits::hash(val->key()) == k0) )    {
    00540       if(m_cont.insert(this,val,val,k0) == Containers::OBJ_INSERTED)   {
    00541         if ( !val->hasKey() ) traits::setKey(val, kval);
    00542         traits::addRef(val);
    00543         return val->key();
    00544       }
    00545     }
    00546   }
    00547   // Cannot insert object...indicate bad object insertion...
    00548   Containers::cannotInsertToContainer();
    00549   return val->key();
    00550 }

template<class DATATYPE, class MAPPING>

const KeyedContainer< DATATYPE, MAPPING >::key_type & KeyedContainer< DATATYPE, MAPPING >::insert | ( | const value_type | val | ) | `[inline]`

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:

- A key was already assigned to the object, but another object with the same key is already present in the container.

Parameters:

  | val | Reference to object to be inserted into the container.

Returns:
  Key, which was used to index the object within the container. If the operation is not successful, an exception is thrown.

Definition at line 555 of file KeyedContainer.h.

    00556 {
    00557   if ( 0 != val )   {
    00558     if ( val->hasKey() )   {
    00559       if (m_cont.insert(this,val,val,traits::hash(val->key()))
    00560           == Containers::OBJ_INSERTED)   {
    00561         traits::addRef(val);
    00562         return val->key();
    00563       }
    00564     }
    00565     long k0;
    00566     if ( m_cont.insert(this, val, val, &k0) == Containers::OBJ_INSERTED )   {
    00567       traits::setKey(val, traits::makeKey(k0));
    00568       traits::addRef(val);
    00569       return val->key();
    00570     }
    00571   }
    00572   // Cannot insert object...indicate bad object insertion...
    00573   Containers::cannotInsertToContainer();
    00574   return val->key();
    00575 }

## Friends And Related Function Documentation

template<class DATATYPE, class MAPPING = Containers::HashMap>

friend struct GaudiDict::KeyedContainerDict< DATATYPE >`[friend]`

Definition at line 67 of file KeyedContainer.h.

## Member Data Documentation

template<class DATATYPE, class MAPPING = Containers::HashMap>

container_type KeyedContainer< DATATYPE, MAPPING >::m_cont`[private]`

Map container to facilitate object access by key.

Definition at line 112 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

seq_type KeyedContainer< DATATYPE, MAPPING >::m_sequential`[private]`

Array to allow sequential access to the object (can be ordered).

Definition at line 114 of file KeyedContainer.h.

template<class DATATYPE, class MAPPING = Containers::HashMap>

seq_type* KeyedContainer< DATATYPE, MAPPING >::m_random`[private]`

Array to allow random access to objects (not exposed).

Definition at line 116 of file KeyedContainer.h.

The documentation for this class was generated from the following file:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r3/GaudiKernel/GaudiKernel/KeyedContainer.h