| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Containers::KeyedObjectManager< SETUP > Class Template Reference

KeyedObjectManager Class to manage keyed objects. More...

`#include <KeyedObjectManager.h>`

Collaboration diagram for Containers::KeyedObjectManager< SETUP >:
[legend]

## Public Member Functions
| KeyedObjectManager ()
| Standard Constructor.
virtual | ~KeyedObjectManager ()
| Standard Destructor.
void | clearDirect ()
| Clear all direct access fields.
long | insertDirect (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
| Insert element into direct access map.
long | isDirect () const
| Check if the container is dirty.
void * | object (long key) const
| Retrieve object identified by a key from the container.
long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
| Insert new object into container.
long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
| Insert new object into container.
void * | erase (long key, const void *obj)
| Remove object from container (very inefficient if key is invalid)
long | erase (seq_type::iterator beg, seq_type::iterator end)
| Remove object by sequential iterators.
void | reserve (long size)
| Reserve buffer space.
void | clear ()
| Clear content of the vector.
void | setup (void *seq, void **rndm)
| Setup of the Map and the parent object.
template<>
CLID | classID ()
template<>
CLID | classID ()
template<>
void * | object (long value) const
template<>
long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
template<>
long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
template<>
long | insertDirect (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
template<>
void | clearDirect ()
template<>
void * | erase (long key, const void *obj)
template<>
long | erase (seq_type::iterator beg, seq_type::iterator end)
template<>
CLID | classID ()
template<>
void * | object (long) const
template<>
long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
template<>
long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
template<>
long | insertDirect (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
template<>
void | clearDirect ()
template<>
void * | erase (long, const void *)
template<>
long | erase (seq_type::iterator beg, seq_type::iterator end)
template<>
CLID | classID ()

## Static Public Member Functions
static CLID | classID ()
| Access CLID for this type of container.

## Private Types
typedef std::vector< void * > | seq_type

## Private Member Functions
void | onDirty () const
| Callback when the container becomes dirty.
template<>
void | onDirty () const
template<>
void | onDirty () const

## Private Attributes
seq_type * | m_seq
| Container holding array like container.
long | m_direct
| Dirty flag.
long | m_keyCtxt
union {
char buffer [128]
| Buffer space to hold keyed container.
SETUP * s
} | m_setup

## Detailed Description

### template<class SETUP>
class Containers::KeyedObjectManager< SETUP >

KeyedObjectManager Class to manage keyed objects.

Object manager class.

This class is instantiated for two container types: map and hashmap. Other types are possible, but currently not supported. Other implementations may be achieved by specializing the SETUP class.

As an example below the specialization for a vector like implementation is shown.

Author
  M.Frank CERN/LHCb

Version
  1.0

Definition at line 46 of file KeyedObjectManager.h.

## Member Typedef Documentation

template<class SETUP >

typedef std::vector<void*> Containers::KeyedObjectManager< SETUP >::seq_type
| private

Definition at line 48 of file KeyedObjectManager.h.

## Constructor & Destructor Documentation

template<class T >

Containers::KeyedObjectManager< T >::KeyedObjectManager | ( |  | ) |

Standard Constructor.

Definition at line 91 of file KeyedObjectManager.cpp.

: m_direct(0)
{
if ( sizeof(typename T::map_type) > sizeof(m_setup.buffer) ) {
throw GaudiException("Basic STL contaier sizes are incompatible",
"KeyedContainer",
0);
}
m_setup.s = ::new(m_setup.buffer+sizeof(m_setup.s)) T();
m_keyCtxt = -1;
}
template<class T >

Containers::KeyedObjectManager< T >::~KeyedObjectManager | ( |  | ) |
| virtual

Standard Destructor.

Definition at line 104 of file KeyedObjectManager.cpp.

{
m_setup.s->~T();
}

## Member Function Documentation

template<class SETUP >

static CLID Containers::KeyedObjectManager< SETUP >::classID | ( |  | ) |
| static

Access CLID for this type of container.

template<>

CLID Containers::KeyedObjectManager< Containers::map >::classID | ( |  | ) |

Definition at line 324 of file KeyedObjectManager.cpp.

{
return CLID_ObjectVector+0x00030000;
}
template<>

CLID Containers::KeyedObjectManager< Containers::hashmap >::classID | ( |  | ) |

Definition at line 328 of file KeyedObjectManager.cpp.

{
return CLID_ObjectVector+0x00040000;
}
template<>

CLID Containers::KeyedObjectManager< __A >::classID | ( |  | ) |

Definition at line 566 of file KeyedObjectManager.cpp.

{
return CLID_ObjectVector+0x00050000;
}
template<>

CLID Containers::KeyedObjectManager< __V >::classID | ( |  | ) |

Definition at line 669 of file KeyedObjectManager.cpp.

{
return CLID_ObjectVector+0x00060000;
}
template<class T >

void Containers::KeyedObjectManager< T >::clear | ( |  | ) |

Clear content of the vector.

Definition at line 265 of file KeyedObjectManager.cpp.

{
clearDirect();
m_seq->clear();
}
template<class T >

void Containers::KeyedObjectManager< T >::clearDirect | ( |  | ) |

Clear all direct access fields.

Definition at line 272 of file KeyedObjectManager.cpp.

{
typedef typename T::map_type MTYP;
switch( m_direct ) {
case 1:
m_setup.s->m.clear();
break;
case 0:
m_setup.s->v.clear();
break;
default:
break;
}
m_direct = 0;
m_keyCtxt = -1;
}
template<>

void Containers::KeyedObjectManager< __A >::clearDirect | ( |  | ) |

Definition at line 463 of file KeyedObjectManager.cpp.

{
m_setup.s->v.clear();
m_setup.s->m_idx.clear();
m_direct = 0;
m_keyCtxt = -1;
}
template<>

void Containers::KeyedObjectManager< __V >::clearDirect | ( |  | ) |

Definition at line 640 of file KeyedObjectManager.cpp.

{
m_setup.s->v.clear();
m_direct = 0;
m_keyCtxt = -1;
}
template<class T >

void * Containers::KeyedObjectManager< T >::erase | ( | long | key,
|  | const void * | obj
| ) |  |

Remove object from container (very inefficient if key is invalid)

Definition at line 213 of file KeyedObjectManager.cpp.

{
typedef typename T::map_type MTYP;
typedef find<MTYP> FND;
if ( 1 == m_direct ) {
typename T::map_type& m = m_setup.s->m;
typename T::map_type::iterator i = (0==obj) ? m_setup.s->m.find(key)
: std::find_if(m.begin(),m.end(),FND(obj));
if ( i != m_setup.s->m.end() ) {
void* o = (*i).second;
seq_type::iterator j = std::find(m_seq->begin(),m_seq->end(),o);
if ( j != m_seq->end() ) {
m_seq->erase(j);
m_setup.s->m.erase(i);
return o;
}
}
containerIsInconsistent();
}
onDirty();
return erase(key, obj);
}
template<class T >

long Containers::KeyedObjectManager< T >::erase | ( | seq_type::iterator | beg,
|  | seq_type::iterator | end
| ) |  |

Remove object by sequential iterators.

Definition at line 291 of file KeyedObjectManager.cpp.

{
typedef typename T::map_type MTYP;
typedef find<MTYP> FND;
if ( 0 == m_direct ) {
onDirty();
return erase(beg, end);
}
if ( beg == m_seq->begin() && end == m_seq->end() ) {
clear();
}
else {
for ( seq_type::iterator j=beg; j != end; ++j) {
typename T::map_type& m = m_setup.s->m;
typename T::map_type::iterator i = std::find_if(m.begin(),m.end(),FND(*j));
if ( i != m_setup.s->m.end() ) {
m_setup.s->m.erase(i);
continue;
}
containerIsInconsistent();
}
m_seq->erase(beg, end);
}
return OBJ_ERASED;
}
template<>

void * Containers::KeyedObjectManager< __A >::erase | ( | long | key,
|  | const void * | obj
| ) |  |

Definition at line 472 of file KeyedObjectManager.cpp.

{
typedef std::vector<long> id_type;
typedef id_type::iterator id_iter;
typedef __A::map_type MTYP;
typedef find<MTYP> FND;
if ( 0 == m_direct ) {
onDirty();
return erase(key, obj);
}
if ( 0 != obj ) {
id_type& idx = m_setup.s->m_idx;
for ( id_iter i=idx.begin(); i != idx.end(); i++ ) {
seq_type::iterator j = m_setup.s->v.begin()+(*i);
seq_type::iterator k = std::find(m_seq->begin(),m_seq->end(),*j);
if ( *j == obj ) {
void* o = *j;
m_seq->erase(k);
m_setup.s->v.erase(j);
std::for_each(m_setup.s->m_idx.begin(),
m_setup.s->m_idx.end(),
array::decrement(*i));
*i = -1;
return o;
}
}
}
else if ( key >= 0 && key < long(m_setup.s->m_idx.size()) ) {
id_iter idx = m_setup.s->m_idx.begin()+key;
if ( *idx != -1 ) {
seq_type::iterator i = m_setup.s->v.begin()+(*idx);
if ( i == m_setup.s->v.end() ) {
containerIsInconsistent();
}
void* o = *i;
seq_type::iterator j=std::find(m_seq->begin(),m_seq->end(),o);
if ( j == m_seq->end() ) {
containerIsInconsistent();
}
m_seq->erase(j);
m_setup.s->v.erase(i);
std::for_each(m_setup.s->m_idx.begin(),
m_setup.s->m_idx.end(),
array::decrement(*idx));
*idx = -1;
return o;
}
}
containerIsInconsistent();
return 0;
}
template<>

long Containers::KeyedObjectManager< __A >::erase | ( | seq_type::iterator | beg,
|  | seq_type::iterator | end
| ) |  |

Definition at line 527 of file KeyedObjectManager.cpp.

{
typedef std::vector<long> id_type;
typedef id_type::iterator id_iter;
if ( beg == m_seq->begin() && end == m_seq->end() ) {
clear();
return OBJ_ERASED;
}
else if ( 0 == m_direct ) {
onDirty();
return erase(beg, end);
}
else {
long cnt = 0, nobj = end-beg;
id_type& idx = m_setup.s->m_idx;
for ( id_iter i=idx.begin(); i != idx.end(); i++ ) {
seq_type::iterator j = m_setup.s->v.begin()+(*i);
seq_type::iterator k = std::find(beg,end,*j);
if ( k != end ) {
m_setup.s->v.erase(j);
std::for_each(m_setup.s->m_idx.begin(),
m_setup.s->m_idx.end(),
array::decrement(*i));
*i = -1;
cnt++;
if ( cnt == nobj ) break;
}
}
m_seq->erase(beg, end);
if ( cnt != nobj ) {
containerIsInconsistent();
}
return OBJ_ERASED;
}
// cannot reach this point
}
template<>

void * Containers::KeyedObjectManager< __V >::erase | ( | long | ,
|  | const void * |
| ) |  |

Definition at line 648 of file KeyedObjectManager.cpp.

{
invalidContainerOperation();
return 0;
}
template<>

long Containers::KeyedObjectManager< __V >::erase | ( | seq_type::iterator | beg,
|  | seq_type::iterator | end
| ) |  |

Definition at line 657 of file KeyedObjectManager.cpp.

{
if ( beg == m_seq->begin() && end == m_seq->end() ) {
clear();
return OBJ_ERASED;
}
invalidContainerOperation();
return OBJ_ERASED;
}
template<class T >

long Containers::KeyedObjectManager< T >::insert | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long * | k
| ) |  |

Insert new object into container.

Definition at line 127 of file KeyedObjectManager.cpp.

{
*key = ++m_keyCtxt;
return insert(pBase, pObject, obj, *key);
}
template<class T >

long Containers::KeyedObjectManager< T >::insert | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long | k
| ) |  |

Insert new object into container.

Keep major key value

Definition at line 138 of file KeyedObjectManager.cpp.

{
if ( key > m_keyCtxt ) {
m_keyCtxt = key;
}
if ( 1==m_direct ) {
if ( m_setup.s->insert(obj, key) ) {
if ( !pObject->parent() ) {
pObject->setParent(pBase);
}
m_seq->push_back(obj);
return OBJ_INSERTED;
}
}
else if ( key == long(m_setup.s->v.size()) ) {
m_setup.s->v.push_back(obj);
if ( !pObject->parent() ) {
pObject->setParent(pBase);
}
m_seq->push_back(obj);
return OBJ_INSERTED;
}
else {
// Document is dirty now...
// need to copy all pointers from the vector to the map
onDirty();
return insert(pBase, pObject, obj, key);
}
cannotInsertToContainer();
return OBJ_CANNOT_INSERT;
}
template<>

long Containers::KeyedObjectManager< __A >::insert | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long * | k
| ) |  |

Definition at line 378 of file KeyedObjectManager.cpp.

{
// auto key creation only possible for direct access!
if ( 0 == m_direct ) {
m_seq->push_back(o);
m_setup.s->v.push_back(o);
if ( !c->parent() ) c->setParent(b);
*k = ++m_keyCtxt;
return OBJ_INSERTED;
}
cannotInsertToContainer();
return OBJ_CANNOT_INSERT;
}
template<>

long Containers::KeyedObjectManager< __A >::insert | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long | k
| ) |  |

Keep major key value

Extend redirection array and insert

Definition at line 397 of file KeyedObjectManager.cpp.

{
if ( 0 == m_direct ) {
if ( k == m_keyCtxt+1 ) {
return insert(b, c, o, &k);
}
onDirty();
return insert(b, c, o, k);
}
if ( k > m_keyCtxt ) m_keyCtxt = k;
if ( k+1 > long(m_setup.s->m_idx.size()) ) {
m_setup.s->m_idx.resize(k+1, -1);
}
std::vector<long>::iterator idx = m_setup.s->m_idx.begin()+k;
if ( *idx == -1 ) {
*idx = m_setup.s->v.size();
m_setup.s->v.push_back(o);
m_seq->push_back(o);
if ( !c->parent() ) c->setParent(b);
return OBJ_INSERTED;
}
cannotInsertToContainer();
return OBJ_CANNOT_INSERT;
}
template<>

long Containers::KeyedObjectManager< __V >::insert | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long * | k
| ) |  |

Definition at line 596 of file KeyedObjectManager.cpp.

{
m_seq->push_back(o);
m_setup.s->v.push_back(o);
if ( !c->parent() ) c->setParent(b);
*k = (m_setup.s->v.size()-1);
return OBJ_INSERTED;
}
template<>

long Containers::KeyedObjectManager< __V >::insert | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long | k
| ) |  |

Definition at line 610 of file KeyedObjectManager.cpp.

{
if ( k == long(m_setup.s->v.size()) ) {
return insert(b, c, o, &k);
}
cannotInsertToContainer();
return OBJ_CANNOT_INSERT;
}
template<class T >

long Containers::KeyedObjectManager< T >::insertDirect | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long | k
| ) |  |

Insert element into direct access map.

Keep major key value

Definition at line 176 of file KeyedObjectManager.cpp.

{
if ( key > m_keyCtxt ) {
m_keyCtxt = key;
}
if ( 1==m_direct ) {
if ( m_setup.s->insert(obj, key) ) {
if ( !pObject->parent() ) {
pObject->setParent(pBase);
}
return OBJ_INSERTED;
}
}
else if ( key == long(m_setup.s->v.size()) ) {
m_setup.s->v.push_back(obj);
if ( !pObject->parent() ) {
pObject->setParent(pBase);
}
return OBJ_INSERTED;
}
else {
// Document is dirty now...
// need to copy all pointers from the vector to the map
onDirty();
return insertDirect(pBase, pObject, obj, key);
}
cannotInsertToContainer();
return OBJ_CANNOT_INSERT;
}
template<>

long Containers::KeyedObjectManager< __A >::insertDirect | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long | k
| ) |  |

Keep major key value

Extend redirection array and insert

Definition at line 429 of file KeyedObjectManager.cpp.

{
if ( 0 == m_direct ) {
if ( k == m_keyCtxt+1 ) {
m_setup.s->v.push_back(o);
if ( !c->parent() ) c->setParent(b);
++m_keyCtxt;
return OBJ_INSERTED;
}
onDirty();
return insertDirect(b, c, o, k);
}
if ( k > m_keyCtxt ) m_keyCtxt = k;
if ( k+1 > long(m_setup.s->m_idx.size()) ) {
m_setup.s->m_idx.resize(k+1, -1);
}
std::vector<long>::iterator idx = m_setup.s->m_idx.begin()+k;
if ( *idx == -1 ) {
*idx = m_setup.s->v.size();
m_setup.s->v.push_back(o);
if ( !c->parent() ) c->setParent(b);
return OBJ_INSERTED;
}
cannotInsertToContainer();
return OBJ_CANNOT_INSERT;
}
template<>

long Containers::KeyedObjectManager< __V >::insertDirect | ( | ObjectContainerBase * | b,
|  | ContainedObject * | c,
|  | void * | o,
|  | long | k
| ) |  |

Definition at line 624 of file KeyedObjectManager.cpp.

{
if ( k == long(m_setup.s->v.size()) ) {
m_setup.s->v.push_back(o);
if ( !c->parent() ) c->setParent(b);
return OBJ_INSERTED;
}
cannotInsertToContainer();
return OBJ_CANNOT_INSERT;
}
template<class SETUP >

long Containers::KeyedObjectManager< SETUP >::isDirect | ( |  | ) | const
| inline

Check if the container is dirty.

Definition at line 73 of file KeyedObjectManager.h.

{ return m_direct; }
template<class T >

void * Containers::KeyedObjectManager< T >::object | ( | long | key | ) | const

Retrieve object identified by a key from the container.

Definition at line 237 of file KeyedObjectManager.cpp.

{
if ( 0 == m_direct ) {
onDirty();
}
typename T::map_type::const_iterator i = m_setup.s->m.find(key);
if ( i != m_setup.s->m.end() ) {
return (*i).second;
}
return 0;
}
template<>

void * Containers::KeyedObjectManager< __A >::object | ( | long | value | ) | const

Definition at line 348 of file KeyedObjectManager.cpp.

{
#ifdef CHECK_KEYED_CONTAINER
unsigned long siz = m_setup.s->m_idx.size();
if ( value >= 0 && size_t(value) < siz ) {
long ent = *(m_setup.s->m_idx.begin()+value);
if ( ent >= 0 ) {
return *(m_setup.s->v.begin() + ent);
}
}
return 0;
#else
return *(m_setup.s->v.begin() + (*(m_setup.s->m_idx.begin()+value)));
#endif
}
template<>

void * Containers::KeyedObjectManager< __V >::object | ( | long |  | ) | const

Definition at line 583 of file KeyedObjectManager.cpp.

{
invalidContainerOperation();
return 0;
}
template<class T >

void Containers::KeyedObjectManager< T >::onDirty | ( |  | ) | const
| private

Callback when the container becomes dirty.

Definition at line 118 of file KeyedObjectManager.cpp.

{
m_direct = 1;
for(int i = 0, stop = m_setup.s->v.size(); i < stop; i++ ) {
m_setup.s->insert(*(m_setup.s->v.begin()+i), i);
}
m_setup.s->v.clear();
}
template<>

void Containers::KeyedObjectManager< __A >::onDirty | ( |  | ) | const
| private

Definition at line 365 of file KeyedObjectManager.cpp.

{
m_direct = 1;
m_setup.s->m_idx.reserve(m_setup.s->v.size()+1);
for(int i = 0, stop = m_setup.s->v.size(); i < stop; ++i) {
if ( m_setup.s->v[i] == 0 ) {
containerIsInconsistent();
}
m_setup.s->m_idx.push_back(i);
}
}
template<>

void Containers::KeyedObjectManager< __V >::onDirty | ( |  | ) | const
| private

Definition at line 590 of file KeyedObjectManager.cpp.

{
invalidContainerOperation();
}
template<class T >

void Containers::KeyedObjectManager< T >::reserve | ( | long | size | ) |

Reserve buffer space.

Definition at line 250 of file KeyedObjectManager.cpp.

{
switch( m_direct ) {
case 1:
break;
case 0:
m_setup.s->v.reserve(len);
break;
default:
break;
}
m_seq->reserve(len);
}
template<class T >

void Containers::KeyedObjectManager< T >::setup | ( | void * | seq,
|  | void ** | rndm
| ) |  |

Setup of the Map and the parent object.

Definition at line 111 of file KeyedObjectManager.cpp.

{
m_seq = (seq_type*)seq;
*rndm = &m_setup.s->v;
}

## Member Data Documentation

template<class SETUP >

char Containers::KeyedObjectManager< SETUP >::buffer[128]

Buffer space to hold keyed container.

Definition at line 56 of file KeyedObjectManager.h.

template<class SETUP >

long Containers::KeyedObjectManager< SETUP >::m_direct
| mutable private

Dirty flag.

Definition at line 52 of file KeyedObjectManager.h.

template<class SETUP >

long Containers::KeyedObjectManager< SETUP >::m_keyCtxt
| mutable private

Definition at line 53 of file KeyedObjectManager.h.

template<class SETUP >

seq_type* Containers::KeyedObjectManager< SETUP >::m_seq
| private

Container holding array like container.

Definition at line 50 of file KeyedObjectManager.h.

union { ... } Containers::KeyedObjectManager< SETUP >::m_setup

template<class SETUP >

SETUP* Containers::KeyedObjectManager< SETUP >::s

Definition at line 57 of file KeyedObjectManager.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiKernel/GaudiKernel/KeyedObjectManager.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiKernel/src/Lib/KeyedObjectManager.cpp