37 auto p =
m.
insert( map_type::value_type( key, obj ) );
71 typedef typename CONT::value_type
v_type;
80 throw GaudiException(
"Cannot assign key to keyed object! Object already has a key.",
"KeyedObject",
88 throw GaudiException(
"Keyed Container structures are inconsistent - severe problem!",
"KeyedContainer",
93 throw GaudiException(
"Keyed Container cannot satisfy request - severe problem!",
"KeyedContainer",
99 if (
sizeof(
typename T::map_type ) >
sizeof(
m_setup.buffer ) ) {
108 : m_seq( nullptr ), m_direct( other.m_direct ), m_keyCtxt( other.m_keyCtxt ) {
111 other.m_keyCtxt = -1;
112 other.m_seq =
nullptr;
125 *rndm = &m_setup.s->v;
131 auto&
s = *m_setup.s;
133 for (
auto p :
s.v )
s.insert( p, i++ );
141 return insert( pBase, pObject, obj, *key );
148 if ( key > m_keyCtxt ) { m_keyCtxt = key; }
149 if ( 1 == m_direct ) {
150 if ( m_setup.s->insert( obj, key ) ) {
152 m_seq->push_back( obj );
155 }
else if ( key ==
long( m_setup.s->v.size() ) ) {
156 m_setup.s->v.push_back( obj );
158 m_seq->push_back( obj );
164 return insert( pBase, pObject, obj, key );
174 if ( key > m_keyCtxt ) { m_keyCtxt = key; }
175 if ( 1 == m_direct ) {
176 if ( m_setup.s->insert( obj, key ) ) {
180 }
else if ( key ==
long( m_setup.s->v.size() ) ) {
181 m_setup.s->v.push_back( obj );
188 return insertDirect( pBase, pObject, obj, key );
197 typedef typename T::map_type MTYP;
199 if ( 1 == m_direct ) {
200 auto&
m = m_setup.s->m;
201 auto i = ( obj ?
std::find_if(
m.begin(),
m.end(), FND( obj ) ) : m_setup.s->m.find( key ) );
202 if ( i != m_setup.s->m.end() ) {
204 auto j =
std::find( m_seq->begin(), m_seq->end(), o );
205 if ( j != m_seq->end() ) {
207 m_setup.s->m.erase( i );
214 return erase( key, obj );
219 if ( 0 == m_direct ) onDirty();
220 auto i = m_setup.s->m.find( key );
221 if ( i != m_setup.s->m.end() )
return ( *i ).second;
227 switch ( m_direct ) {
231 m_setup.s->v.reserve( len );
236 m_seq->reserve( len );
247 switch ( m_direct ) {
249 m_setup.s->m.clear();
252 m_setup.s->v.clear();
264 typedef typename T::map_type MTYP;
266 if ( 0 == m_direct ) {
268 return erase( beg,
end );
270 if ( beg == m_seq->begin() &&
end == m_seq->end() ) {
273 for (
auto j = beg; j !=
end; ++j ) {
275 auto i =
std::find_if( m_setup.s->m.begin(), m_setup.s->m.end(), FND( *j ) );
276 if ( i != m_setup.s->m.end() ) {
277 m_setup.s->m.erase( i );
282 m_seq->erase( beg,
end );
294 return CLID_ObjectVector + 0x00030000;
298 return CLID_ObjectVector + 0x00040000;
318 #ifdef CHECK_KEYED_CONTAINER 319 unsigned long siz = m_setup.s->m_idx.size();
320 if ( value >= 0 &&
size_t( value ) < siz ) {
321 long ent = *( m_setup.s->m_idx.begin() + value );
322 if ( ent >= 0 ) {
return *( m_setup.s->v.begin() + ent ); }
326 return *( m_setup.s->v.begin() + ( *( m_setup.s->m_idx.begin() + value ) ) );
333 m_setup.s->m_idx.reserve( m_setup.s->v.size() + 1 );
334 for (
int i = 0, stop = m_setup.s->v.size(); i < stop; ++i ) {
336 m_setup.s->m_idx.push_back( i );
344 if ( 0 == m_direct ) {
345 m_seq->push_back( o );
346 m_setup.s->v.push_back( o );
347 if ( !
c->parent() )
c->setParent( b );
358 if ( 0 == m_direct ) {
359 if ( k == m_keyCtxt + 1 ) {
return insert( b,
c, o, &k ); }
364 if ( k > m_keyCtxt ) m_keyCtxt = k;
366 if ( k + 1 >
long( m_setup.s->m_idx.size() ) ) { m_setup.s->m_idx.resize( k + 1, -1 ); }
367 auto idx = m_setup.s->m_idx.begin() + k;
369 *idx = m_setup.s->v.size();
370 m_setup.s->v.push_back( o );
371 m_seq->push_back( o );
372 if ( !
c->parent() )
c->setParent( b );
382 if ( 0 == m_direct ) {
383 if ( k == m_keyCtxt + 1 ) {
384 m_setup.s->v.push_back( o );
385 if ( !
c->parent() )
c->setParent( b );
390 return insertDirect( b,
c, o, k );
393 if ( k > m_keyCtxt ) m_keyCtxt = k;
395 if ( k + 1 >
long( m_setup.s->m_idx.size() ) ) { m_setup.s->m_idx.resize( k + 1, -1 ); }
396 auto idx = m_setup.s->m_idx.begin() + k;
398 *idx = m_setup.s->v.size();
399 m_setup.s->v.push_back( o );
400 if ( !
c->parent() )
c->setParent( b );
410 m_setup.s->v.clear();
411 m_setup.s->m_idx.clear();
419 if ( 0 == m_direct ) {
421 return erase( key, obj );
424 auto& idx = m_setup.s->m_idx;
425 for (
auto& elem : idx ) {
426 auto j = m_setup.s->v.begin() + ( elem );
427 auto k =
std::find( m_seq->begin(), m_seq->end(), *j );
431 m_setup.s->v.erase( j );
437 }
else if ( key >= 0 && key <
long( m_setup.s->m_idx.size() ) ) {
438 auto idx = m_setup.s->m_idx.begin() + key;
440 auto i = m_setup.s->v.begin() + ( *idx );
443 auto j =
std::find( m_seq->begin(), m_seq->end(), o );
446 m_setup.s->v.erase( i );
459 if ( beg == m_seq->begin() &&
end == m_seq->end() ) {
462 }
else if ( 0 == m_direct ) {
464 return erase( beg,
end );
466 long cnt = 0, nobj =
end - beg;
467 auto& idx = m_setup.s->m_idx;
468 for (
auto& elem : idx ) {
469 auto j = m_setup.s->v.begin() + ( elem );
472 m_setup.s->v.erase( j );
476 if ( cnt == nobj )
break;
479 m_seq->erase( beg,
end );
488 return CLID_ObjectVector + 0x00050000;
517 m_seq->push_back( o );
518 m_setup.s->v.push_back( o );
519 if ( !
c->parent() )
c->setParent( b );
520 *k = ( m_setup.s->v.size() - 1 );
527 if ( k ==
long( m_setup.s->v.size() ) ) {
return insert( b,
c, o, &k ); }
535 if ( k ==
long( m_setup.s->v.size() ) ) {
536 m_setup.s->v.push_back( o );
537 if ( !
c->parent() )
c->setParent( b );
547 m_setup.s->v.clear();
562 if ( beg == m_seq->begin() &&
end == m_seq->end() ) {
572 return CLID_ObjectVector + 0x00060000;
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
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.
bool operator()(long &j) const
std::vector< long > m_idx
Indirection array.
void * erase(long key, const void *obj)
Remove object from container (very inefficient if key is invalid)
std::map< long, void * > map_type
Object was inserted into the container.
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.
void onDirty() const
Callback when the container becomes dirty.
void * object(long key) const
Retrieve object identified by a key from the container.
std::vector< void * > v
Direct access array.
std::pair< iterator, bool > insert(ValueType &&val)
void reserve(long size)
Reserve buffer space.
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it's cont...
bool operator()(const void *cmp) const
GaudiUtils::HashMap< long, void * > map_type
bool operator()(const v_type &cmp) const
Object was removed, but not deleted.
long insert(ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
Insert new object into container.
unsigned int CLID
Class ID definition.
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.
Cannot insert object into container.
constexpr struct ranges::Gaudi::Functional::details::insert_t insert
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.
constexpr static const auto FAILURE
const ObjectContainerBase * parent() const
Access to parent object.
ObjectContainerBase is the base class for Gaudi container classes.
KeyedObjectManager()
Standard Constructor.
bool insert(void *obj, long key)
long insertDirect(ObjectContainerBase *b, ContainedObject *c, void *o, long k)
Insert element into direct access map.
union Containers::KeyedObjectManager::@2 m_setup