11 namespace Containers {
17 std::pair<map_type::iterator,bool> p =
27 std::pair<map_type::iterator,bool> p =
28 m.insert(map_type::value_type(key,obj));
56 typedef typename CONT::value_type
v_type;
63 return (*
this)(cmp.second);
68 throw GaudiException(
"Cannot assign key to keyed object! Object already has a key.",
79 throw GaudiException(
"Keyed Container structures are inconsistent - severe problem!",
85 throw GaudiException(
"Keyed Container cannot satisfy request - severe problem!",
92 : m_seq(nullptr), m_direct(0)
94 if (
sizeof(
typename T::map_type) >
sizeof(
m_setup.buffer) ) {
110 template <
class T>
void
114 *rndm = &m_setup.s->v;
120 for(
int i = 0, stop = m_setup.s->v.size();
i < stop;
i++ ) {
121 m_setup.s->insert(*(m_setup.s->v.begin()+
i),
i);
123 m_setup.s->v.clear();
134 return insert(pBase, pObject, obj, *key);
145 if ( key > m_keyCtxt ) {
149 if ( m_setup.s->insert(obj, key) ) {
150 if ( !pObject->
parent() ) {
153 m_seq->push_back(obj);
157 else if ( key ==
long(m_setup.s->v.size()) ) {
158 m_setup.s->v.push_back(obj);
159 if ( !pObject->
parent() ) {
162 m_seq->push_back(obj);
169 return insert(pBase, pObject, obj, key);
183 if ( key > m_keyCtxt ) {
187 if ( m_setup.s->insert(obj, key) ) {
188 if ( !pObject->
parent() ) {
194 else if ( key ==
long(m_setup.s->v.size()) ) {
195 m_setup.s->v.push_back(obj);
196 if ( !pObject->
parent() ) {
205 return insertDirect(pBase, pObject, obj, key);
215 typedef typename T::map_type MTYP;
217 if ( 1 == m_direct ) {
218 typename T::map_type& m = m_setup.s->m;
219 typename T::map_type::iterator
i = (0==obj) ? m_setup.s->m.find(key)
220 : std::find_if(m.begin(),m.end(),FND(obj));
221 if ( i != m_setup.s->m.end() ) {
222 void* o = (*i).second;
223 seq_type::iterator j = std::find(m_seq->begin(),m_seq->end(),o);
224 if ( j != m_seq->end() ) {
226 m_setup.s->m.erase(i);
233 return erase(key, obj);
239 if ( 0 == m_direct ) {
242 typename T::map_type::const_iterator
i = m_setup.s->m.find(key);
243 if ( i != m_setup.s->m.end() ) {
256 m_setup.s->v.reserve(len);
276 m_setup.s->m.clear();
279 m_setup.s->v.clear();
291 seq_type::iterator
end)
293 typedef typename T::map_type MTYP;
295 if ( 0 == m_direct ) {
297 return erase(beg, end);
299 if ( beg == m_seq->begin() && end == m_seq->end() ) {
303 for ( seq_type::iterator j=beg; j !=
end; ++j) {
304 typename T::map_type& m = m_setup.s->m;
305 typename T::map_type::iterator
i = std::find_if(m.begin(),m.end(),FND(*j));
306 if ( i != m_setup.s->m.end() ) {
307 m_setup.s->m.erase(i);
312 m_seq->erase(beg, end);
317 namespace Containers {
324 return CLID_ObjectVector+0x00030000;
328 return CLID_ObjectVector+0x00040000;
343 namespace Containers {
349 #ifdef CHECK_KEYED_CONTAINER
350 unsigned long siz = m_setup.s->m_idx.size();
351 if ( value >= 0 &&
size_t(value) < siz ) {
352 long ent = *(m_setup.s->m_idx.begin()+
value);
354 return *(m_setup.s->v.begin() + ent);
359 return *(m_setup.s->v.begin() + (*(m_setup.s->m_idx.begin()+
value)));
366 m_setup.s->m_idx.reserve(m_setup.s->v.size()+1);
367 for(
int i = 0, stop = m_setup.s->v.size();
i < stop; ++
i) {
368 if ( m_setup.s->v[
i] == 0 ) {
371 m_setup.s->m_idx.push_back(
i);
383 if ( 0 == m_direct ) {
385 m_setup.s->v.push_back(o);
401 if ( 0 == m_direct ) {
402 if ( k == m_keyCtxt+1 ) {
403 return insert(b, c, o, &k);
406 return insert(b, c, o, k);
409 if ( k > m_keyCtxt ) m_keyCtxt = k;
411 if ( k+1 >
long(m_setup.s->m_idx.size()) ) {
412 m_setup.s->m_idx.resize(k+1, -1);
414 std::vector<long>::iterator idx = m_setup.s->m_idx.begin()+k;
416 *idx = m_setup.s->v.size();
417 m_setup.s->v.push_back(o);
433 if ( 0 == m_direct ) {
434 if ( k == m_keyCtxt+1 ) {
435 m_setup.s->v.push_back(o);
441 return insertDirect(b, c, o, k);
444 if ( k > m_keyCtxt ) m_keyCtxt = k;
446 if ( k+1 >
long(m_setup.s->m_idx.size()) ) {
447 m_setup.s->m_idx.resize(k+1, -1);
449 std::vector<long>::iterator idx = m_setup.s->m_idx.begin()+k;
451 *idx = m_setup.s->v.size();
452 m_setup.s->v.push_back(o);
463 m_setup.s->v.clear();
464 m_setup.s->m_idx.clear();
474 typedef std::vector<long> id_type;
475 typedef id_type::iterator id_iter;
476 if ( 0 == m_direct ) {
478 return erase(key, obj);
481 id_type& idx = m_setup.s->m_idx;
482 for ( id_iter
i=idx.begin();
i != idx.end();
i++ ) {
483 seq_type::iterator j = m_setup.s->v.begin()+(*i);
484 seq_type::iterator k = std::find(m_seq->begin(),m_seq->end(),*j);
488 m_setup.s->v.erase(j);
489 std::for_each(m_setup.s->m_idx.begin(),
490 m_setup.s->m_idx.end(),
497 else if ( key >= 0 && key <
long(m_setup.s->m_idx.size()) ) {
498 id_iter idx = m_setup.s->m_idx.begin()+key;
500 seq_type::iterator
i = m_setup.s->v.begin()+(*idx);
501 if ( i == m_setup.s->v.end() ) {
505 seq_type::iterator j=std::find(m_seq->begin(),m_seq->end(),o);
506 if ( j == m_seq->end() ) {
510 m_setup.s->v.erase(i);
511 std::for_each(m_setup.s->m_idx.begin(),
512 m_setup.s->m_idx.end(),
525 seq_type::iterator
end)
527 typedef std::vector<long> id_type;
528 typedef id_type::iterator id_iter;
529 if ( beg == m_seq->begin() && end == m_seq->end() ) {
533 else if ( 0 == m_direct ) {
535 return erase(beg, end);
538 long cnt = 0, nobj = end-beg;
539 id_type& idx = m_setup.s->m_idx;
540 for ( id_iter
i=idx.begin();
i != idx.end();
i++ ) {
541 seq_type::iterator j = m_setup.s->v.begin()+(*i);
542 seq_type::iterator k = std::find(beg,end,*j);
544 m_setup.s->v.erase(j);
545 std::for_each(m_setup.s->m_idx.begin(),
546 m_setup.s->m_idx.end(),
550 if ( cnt == nobj )
break;
553 m_seq->erase(beg, end);
564 return CLID_ObjectVector+0x00050000;
577 namespace Containers {
599 m_setup.s->v.push_back(o);
601 *k = (m_setup.s->v.size()-1);
612 if ( k ==
long(m_setup.s->v.size()) ) {
613 return insert(b, c, o, &k);
626 if ( k ==
long(m_setup.s->v.size()) ) {
627 m_setup.s->v.push_back(o);
638 m_setup.s->v.clear();
655 seq_type::iterator
end)
657 if ( beg == m_seq->begin() && end == m_seq->end() ) {
667 return CLID_ObjectVector+0x00060000;
Object was inserted into the container.
bool operator()(long &j) const
Define general base for Gaudi exception.
std::vector< void * > map_type
virtual ~KeyedObjectManager()
Standard Destructor.
void clear()
Clear content of the vector.
std::vector< long > map_type
union Containers::KeyedObjectManager::@6 m_setup
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent. ...
void clearDirect()
Clear all direct access fields.
std::vector< long > m_idx
Indirection array.
void * object(long key) const
Retrieve object identified by a key from the container.
void * erase(long key, const void *obj)
Remove object from container (very inefficient if key is invalid)
std::map< long, void * > map_type
const ObjectContainerBase * parent() const
Access to parent object.
bool insert(void *obj, long key)
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
std::vector< void * > v
Direct access array.
std::pair< iterator, bool > insert(const value_type &val)
void reserve(long size)
Reserve buffer space.
Cannot insert object into container.
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it's cont...
std::pair< const long, void * > value_type
GaudiUtils::HashMap< long, void * > map_type
void onDirty() const
Callback when the container becomes dirty.
long insert(ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
Insert new object into container.
unsigned int CLID
Class ID definition.
std::vector< void * > seq_type
bool operator()(const v_type &cmp) const
Object was removed, but not deleted.
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
KeyedObjectManager Class to manage keyed objects.
std::vector< void * > v
Direct access array.
void setParent(ObjectContainerBase *value)
Update parent member.
static CLID classID()
Access CLID for this type of container.
void setup(void *seq, void **rndm)
Setup of the Map and the parent object.
ObjectContainerBase is the base class for Gaudi container classes.
KeyedObjectManager()
Standard Constructor.
bool operator()(const void *cmp) const
bool insert(void *obj, long key)
long insertDirect(ObjectContainerBase *b, ContainedObject *c, void *o, long k)
Insert element into direct access map.