|
Gaudi Framework, version v23r2 |
| Home | Generated: Thu Jun 28 2012 |
KeyedObjectManager Class to manage keyed objects. More...
#include <KeyedObjectManager.h>

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 |
KeyedObjectManager Class to manage keyed objects.
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.
Definition at line 46 of file KeyedObjectManager.h.
typedef std::vector<void*> Containers::KeyedObjectManager< SETUP >::seq_type [private] |
Definition at line 48 of file KeyedObjectManager.h.
| Containers::KeyedObjectManager< T >::KeyedObjectManager | ( | ) |
Standard Constructor.
Definition at line 91 of file KeyedObjectManager.cpp.
| Containers::KeyedObjectManager< T >::~KeyedObjectManager | ( | ) | [virtual] |
| static CLID Containers::KeyedObjectManager< SETUP >::classID | ( | ) | [static] |
Access CLID for this type of container.
| CLID Containers::KeyedObjectManager< __V >::classID | ( | ) |
Definition at line 669 of file KeyedObjectManager.cpp.
{
return CLID_ObjectVector+0x00060000;
}
| CLID Containers::KeyedObjectManager< Containers::map >::classID | ( | ) |
Definition at line 324 of file KeyedObjectManager.cpp.
{
return CLID_ObjectVector+0x00030000;
}
| CLID Containers::KeyedObjectManager< __A >::classID | ( | ) |
Definition at line 566 of file KeyedObjectManager.cpp.
{
return CLID_ObjectVector+0x00050000;
}
| CLID Containers::KeyedObjectManager< Containers::hashmap >::classID | ( | ) |
Definition at line 328 of file KeyedObjectManager.cpp.
{
return CLID_ObjectVector+0x00040000;
}
| void Containers::KeyedObjectManager< T >::clear | ( | void | ) |
Clear content of the vector.
Definition at line 265 of file KeyedObjectManager.cpp.
{
clearDirect();
m_seq->clear();
}
| void Containers::KeyedObjectManager< T >::clearDirect | ( | ) |
| void Containers::KeyedObjectManager< __A >::clearDirect | ( | ) |
| void Containers::KeyedObjectManager< __V >::clearDirect | ( | ) |
Definition at line 640 of file KeyedObjectManager.cpp.
| 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;
}
| 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;
}
| 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);
}
| 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;
}
| 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
}
| void * Containers::KeyedObjectManager< __V >::erase | ( | long | , |
| const void * | |||
| ) |
Definition at line 648 of file KeyedObjectManager.cpp.
{
invalidContainerOperation();
return 0;
}
| 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;
}
| 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;
}
| 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;
}
| 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.
| long Containers::KeyedObjectManager< __V >::insert | ( | ObjectContainerBase * | b, |
| ContainedObject * | c, | ||
| void * | o, | ||
| long * | k | ||
| ) |
Definition at line 596 of file KeyedObjectManager.cpp.
| 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;
}
| 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;
}
| 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;
}
| 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;
}
| long Containers::KeyedObjectManager< SETUP >::isDirect | ( | ) | const [inline] |
Check if the container is dirty.
Definition at line 73 of file KeyedObjectManager.h.
{ return m_direct; }
| 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
}
| void * Containers::KeyedObjectManager< T >::object | ( | long | key ) | const |
| void * Containers::KeyedObjectManager< __V >::object | ( | long | ) | const |
Definition at line 583 of file KeyedObjectManager.cpp.
{
invalidContainerOperation();
return 0;
}
| void Containers::KeyedObjectManager< T >::onDirty | ( | ) | const [private] |
| void Containers::KeyedObjectManager< __A >::onDirty | ( | ) | const [private] |
| void Containers::KeyedObjectManager< __V >::onDirty | ( | ) | const [private] |
Definition at line 590 of file KeyedObjectManager.cpp.
{
invalidContainerOperation();
}
| void Containers::KeyedObjectManager< T >::reserve | ( | long | size ) |
| 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.
| char Containers::KeyedObjectManager< SETUP >::buffer[128] |
Buffer space to hold keyed container.
Definition at line 56 of file KeyedObjectManager.h.
long Containers::KeyedObjectManager< SETUP >::m_direct [mutable, private] |
Dirty flag.
Definition at line 52 of file KeyedObjectManager.h.
long Containers::KeyedObjectManager< SETUP >::m_keyCtxt [mutable, private] |
Definition at line 53 of file KeyedObjectManager.h.
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 [private] |
| SETUP* Containers::KeyedObjectManager< SETUP >::s |
Definition at line 57 of file KeyedObjectManager.h.