2 #include "GaudiKernel/Kernel.h"
3 #include "GaudiKernel/GaudiException.h"
4 #include "GaudiKernel/ContainedObject.h"
5 #include "GaudiKernel/KeyedObjectManager.h"
8 #include "GaudiKernel/HashMap.h"
25 auto p = m.insert(map_type::value_type(key,obj));
53 typedef typename CONT::value_type
v_type;
55 find(
const void* o) : m_obj(o) {}
60 return (*
this)(cmp.second);
65 throw GaudiException(
"Cannot assign key to keyed object! Object already has a key.",
76 throw GaudiException(
"Keyed Container structures are inconsistent - severe problem!",
82 throw GaudiException(
"Keyed Container cannot satisfy request - severe problem!",
89 : m_seq(nullptr), m_direct(0)
91 if (
sizeof(
typename T::map_type) >
sizeof(
m_setup.buffer) ) {
107 template <
class T>
void
111 *rndm = &m_setup.s->v;
117 for(
int i = 0, stop = m_setup.s->v.size();
i < stop;
i++ ) {
118 m_setup.s->insert(*(m_setup.s->v.begin()+
i),
i);
120 m_setup.s->v.clear();
131 return insert(pBase, pObject, obj, *key);
142 if ( key > m_keyCtxt ) {
146 if ( m_setup.s->insert(obj, key) ) {
147 if ( !pObject->
parent() ) {
150 m_seq->push_back(obj);
154 else if ( key ==
long(m_setup.s->v.size()) ) {
155 m_setup.s->v.push_back(obj);
156 if ( !pObject->
parent() ) {
159 m_seq->push_back(obj);
166 return insert(pBase, pObject, obj, key);
180 if ( key > m_keyCtxt ) {
184 if ( m_setup.s->insert(obj, key) ) {
185 if ( !pObject->
parent() ) {
191 else if ( key ==
long(m_setup.s->v.size()) ) {
192 m_setup.s->v.push_back(obj);
193 if ( !pObject->
parent() ) {
202 return insertDirect(pBase, pObject, obj, key);
212 typedef typename T::map_type MTYP;
214 if ( 1 == m_direct ) {
215 auto&
m = m_setup.s->m;
216 auto i = (obj ? std::find_if(
m.begin(),
m.end(),FND(obj))
217 : m_setup.s->m.find(key) );
218 if (
i != m_setup.s->m.end() ) {
220 auto j = std::find(m_seq->begin(),m_seq->end(),o);
221 if ( j != m_seq->end() ) {
223 m_setup.s->m.erase(
i);
230 return erase(key, obj);
236 if ( 0 == m_direct ) onDirty();
237 auto i = m_setup.s->m.find(key);
238 if (
i != m_setup.s->m.end() )
return (*i).second;
249 m_setup.s->v.reserve(len);
269 m_setup.s->m.clear();
272 m_setup.s->v.clear();
284 seq_type::iterator
end)
286 typedef typename T::map_type MTYP;
288 if ( 0 == m_direct ) {
290 return erase(beg, end);
292 if ( beg == m_seq->begin() && end == m_seq->end() ) {
296 for (
auto j=beg; j !=
end; ++j) {
297 auto&
m = m_setup.s->m;
298 auto i = std::find_if(
m.begin(),
m.end(),FND(*j));
299 if (
i != m_setup.s->m.end() ) {
300 m_setup.s->m.erase(
i);
305 m_seq->erase(beg, end);
317 return CLID_ObjectVector+0x00030000;
321 return CLID_ObjectVector+0x00040000;
342 #ifdef CHECK_KEYED_CONTAINER
343 unsigned long siz = m_setup.s->m_idx.size();
344 if ( value >= 0 &&
size_t(value) < siz ) {
345 long ent = *(m_setup.s->m_idx.begin()+
value);
347 return *(m_setup.s->v.begin() + ent);
352 return *(m_setup.s->v.begin() + (*(m_setup.s->m_idx.begin()+
value)));
359 m_setup.s->m_idx.reserve(m_setup.s->v.size()+1);
360 for(
int i = 0, stop = m_setup.s->v.size();
i < stop; ++
i) {
361 if ( !m_setup.s->v[
i] ) {
364 m_setup.s->m_idx.push_back(
i);
376 if ( 0 == m_direct ) {
378 m_setup.s->v.push_back(o);
394 if ( 0 == m_direct ) {
395 if ( k == m_keyCtxt+1 ) {
396 return insert(b, c, o, &k);
399 return insert(b, c, o, k);
402 if ( k > m_keyCtxt ) m_keyCtxt = k;
404 if ( k+1 >
long(m_setup.s->m_idx.size()) ) {
405 m_setup.s->m_idx.resize(k+1, -1);
407 auto idx = m_setup.s->m_idx.begin()+k;
409 *idx = m_setup.s->v.size();
410 m_setup.s->v.push_back(o);
426 if ( 0 == m_direct ) {
427 if ( k == m_keyCtxt+1 ) {
428 m_setup.s->v.push_back(o);
434 return insertDirect(b, c, o, k);
437 if ( k > m_keyCtxt ) m_keyCtxt = k;
439 if ( k+1 >
long(m_setup.s->m_idx.size()) ) {
440 m_setup.s->m_idx.resize(k+1, -1);
442 auto idx = m_setup.s->m_idx.begin()+k;
444 *idx = m_setup.s->v.size();
445 m_setup.s->v.push_back(o);
456 m_setup.s->v.clear();
457 m_setup.s->m_idx.clear();
467 typedef std::vector<long> id_type;
468 typedef id_type::iterator id_iter;
469 if ( 0 == m_direct ) {
471 return erase(key, obj);
474 id_type& idx = m_setup.s->m_idx;
475 for (
auto & elem : idx) {
476 auto j = m_setup.s->v.begin()+(elem);
477 auto k = std::find(m_seq->begin(),m_seq->end(),*j);
481 m_setup.s->v.erase(j);
482 std::for_each(m_setup.s->m_idx.begin(),
483 m_setup.s->m_idx.end(),
490 else if ( key >= 0 && key <
long(m_setup.s->m_idx.size()) ) {
491 auto idx = m_setup.s->m_idx.begin()+key;
493 auto i = m_setup.s->v.begin()+(*idx);
494 if (
i == m_setup.s->v.end() ) {
498 auto j=std::find(m_seq->begin(),m_seq->end(),o);
499 if ( j == m_seq->end() ) {
503 m_setup.s->v.erase(
i);
504 std::for_each(m_setup.s->m_idx.begin(),
505 m_setup.s->m_idx.end(),
518 seq_type::iterator
end)
520 typedef std::vector<long> id_type;
521 typedef id_type::iterator id_iter;
522 if ( beg == m_seq->begin() && end == m_seq->end() ) {
526 else if ( 0 == m_direct ) {
528 return erase(beg, end);
531 long cnt = 0, nobj = end-beg;
532 id_type& idx = m_setup.s->m_idx;
533 for (
auto & elem : idx) {
534 auto j = m_setup.s->v.begin()+(elem);
535 auto k = std::find(beg,end,*j);
537 m_setup.s->v.erase(j);
538 std::for_each(m_setup.s->m_idx.begin(),
539 m_setup.s->m_idx.end(),
543 if ( cnt == nobj )
break;
546 m_seq->erase(beg, end);
557 return CLID_ObjectVector+0x00050000;
592 m_setup.s->v.push_back(o);
594 *k = (m_setup.s->v.size()-1);
605 if ( k ==
long(m_setup.s->v.size()) ) {
606 return insert(b, c, o, &k);
619 if ( k ==
long(m_setup.s->v.size()) ) {
620 m_setup.s->v.push_back(o);
631 m_setup.s->v.clear();
648 seq_type::iterator
end)
650 if ( beg == m_seq->begin() && end == m_seq->end() ) {
660 return CLID_ObjectVector+0x00060000;
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
Object was removed, but not deleted.
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)
std::vector< void * > v
Direct access array.
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
void reserve(long size)
Reserve buffer space.
auto end(reverse_wrapper< T > &w)
std::pair< const K, T > 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.
std::vector< void * > seq_type
bool operator()(const v_type &cmp) const
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent. ...
Object was inserted into the container.
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.
std::pair< iterator, bool > insert(ValueType &&val)
void setup(void *seq, void **rndm)
Setup of the Map and the parent object.
Cannot insert object into container.
ObjectContainerBase is the base class for Gaudi container classes.
KeyedObjectManager()
Standard Constructor.
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it's cont...
unsigned int CLID
Class ID definition.
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
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.