27 auto p =
m.
insert( map_type::value_type( key, obj ) );
61 typedef typename CONT::value_type
v_type;
70 throw GaudiException(
"Cannot assign key to keyed object! Object already has a key.",
"KeyedObject",
78 throw GaudiException(
"Keyed Container structures are inconsistent - severe problem!",
"KeyedContainer",
83 throw GaudiException(
"Keyed Container cannot satisfy request - severe problem!",
"KeyedContainer",
89 if (
sizeof(
typename T::map_type ) >
sizeof(
m_setup.buffer ) ) {
98 : m_seq( nullptr ), m_direct( other.m_direct ), m_keyCtxt( other.m_keyCtxt ) {
101 other.m_keyCtxt = -1;
102 other.m_seq =
nullptr;
115 *rndm = &m_setup.s->v;
121 auto&
s = *m_setup.s;
123 for (
auto p :
s.v )
s.insert( p, i++ );
131 return insert( pBase, pObject, obj, *key );
138 if ( key > m_keyCtxt ) { m_keyCtxt = key; }
139 if ( 1 == m_direct ) {
140 if ( m_setup.s->insert( obj, key ) ) {
142 m_seq->push_back( obj );
145 }
else if ( key ==
long( m_setup.s->v.size() ) ) {
146 m_setup.s->v.push_back( obj );
148 m_seq->push_back( obj );
154 return insert( pBase, pObject, obj, key );
164 if ( key > m_keyCtxt ) { m_keyCtxt = key; }
165 if ( 1 == m_direct ) {
166 if ( m_setup.s->insert( obj, key ) ) {
170 }
else if ( key ==
long( m_setup.s->v.size() ) ) {
171 m_setup.s->v.push_back( obj );
178 return insertDirect( pBase, pObject, obj, key );
187 typedef typename T::map_type MTYP;
189 if ( 1 == m_direct ) {
190 auto&
m = m_setup.s->m;
191 auto i = ( obj ?
std::find_if(
m.begin(),
m.end(), FND( obj ) ) : m_setup.s->m.find( key ) );
192 if ( i != m_setup.s->m.end() ) {
194 auto j =
std::find( m_seq->begin(), m_seq->end(), o );
195 if ( j != m_seq->end() ) {
197 m_setup.s->m.erase( i );
204 return erase( key, obj );
209 if ( 0 == m_direct ) onDirty();
210 auto i = m_setup.s->m.find( key );
211 if ( i != m_setup.s->m.end() )
return ( *i ).second;
217 switch ( m_direct ) {
221 m_setup.s->v.reserve( len );
226 m_seq->reserve( len );
237 switch ( m_direct ) {
239 m_setup.s->m.clear();
242 m_setup.s->v.clear();
254 typedef typename T::map_type MTYP;
256 if ( 0 == m_direct ) {
258 return erase( beg,
end );
260 if ( beg == m_seq->begin() &&
end == m_seq->end() ) {
263 for (
auto j = beg; j !=
end; ++j ) {
265 auto i =
std::find_if( m_setup.s->m.begin(), m_setup.s->m.end(), FND( *j ) );
266 if ( i != m_setup.s->m.end() ) {
267 m_setup.s->m.erase( i );
272 m_seq->erase( beg,
end );
284 return CLID_ObjectVector + 0x00030000;
288 return CLID_ObjectVector + 0x00040000;
308 #ifdef CHECK_KEYED_CONTAINER 309 unsigned long siz = m_setup.s->m_idx.size();
310 if ( value >= 0 &&
size_t( value ) < siz ) {
311 long ent = *( m_setup.s->m_idx.begin() + value );
312 if ( ent >= 0 ) {
return *( m_setup.s->v.begin() + ent ); }
316 return *( m_setup.s->v.begin() + ( *( m_setup.s->m_idx.begin() + value ) ) );
323 m_setup.s->m_idx.reserve( m_setup.s->v.size() + 1 );
324 for (
int i = 0, stop = m_setup.s->v.size(); i < stop; ++i ) {
326 m_setup.s->m_idx.push_back( i );
334 if ( 0 == m_direct ) {
335 m_seq->push_back( o );
336 m_setup.s->v.push_back( o );
337 if ( !
c->parent() )
c->setParent( b );
348 if ( 0 == m_direct ) {
349 if ( k == m_keyCtxt + 1 ) {
return insert( b,
c, o, &k ); }
354 if ( k > m_keyCtxt ) m_keyCtxt = k;
356 if ( k + 1 >
long( m_setup.s->m_idx.size() ) ) { m_setup.s->m_idx.resize( k + 1, -1 ); }
357 auto idx = m_setup.s->m_idx.begin() + k;
359 *idx = m_setup.s->v.size();
360 m_setup.s->v.push_back( o );
361 m_seq->push_back( o );
362 if ( !
c->parent() )
c->setParent( b );
372 if ( 0 == m_direct ) {
373 if ( k == m_keyCtxt + 1 ) {
374 m_setup.s->v.push_back( o );
375 if ( !
c->parent() )
c->setParent( b );
380 return insertDirect( b,
c, o, k );
383 if ( k > m_keyCtxt ) m_keyCtxt = k;
385 if ( k + 1 >
long( m_setup.s->m_idx.size() ) ) { m_setup.s->m_idx.resize( k + 1, -1 ); }
386 auto idx = m_setup.s->m_idx.begin() + k;
388 *idx = m_setup.s->v.size();
389 m_setup.s->v.push_back( o );
390 if ( !
c->parent() )
c->setParent( b );
400 m_setup.s->v.clear();
401 m_setup.s->m_idx.clear();
409 if ( 0 == m_direct ) {
411 return erase( key, obj );
414 auto& idx = m_setup.s->m_idx;
415 for (
auto& elem : idx ) {
416 auto j = m_setup.s->v.begin() + ( elem );
417 auto k =
std::find( m_seq->begin(), m_seq->end(), *j );
421 m_setup.s->v.erase( j );
427 }
else if ( key >= 0 && key <
long( m_setup.s->m_idx.size() ) ) {
428 auto idx = m_setup.s->m_idx.begin() + key;
430 auto i = m_setup.s->v.begin() + ( *idx );
433 auto j =
std::find( m_seq->begin(), m_seq->end(), o );
436 m_setup.s->v.erase( i );
449 if ( beg == m_seq->begin() &&
end == m_seq->end() ) {
452 }
else if ( 0 == m_direct ) {
454 return erase( beg,
end );
456 long cnt = 0, nobj =
end - beg;
457 auto& idx = m_setup.s->m_idx;
458 for (
auto& elem : idx ) {
459 auto j = m_setup.s->v.begin() + ( elem );
462 m_setup.s->v.erase( j );
466 if ( cnt == nobj )
break;
469 m_seq->erase( beg,
end );
478 return CLID_ObjectVector + 0x00050000;
507 m_seq->push_back( o );
508 m_setup.s->v.push_back( o );
509 if ( !
c->parent() )
c->setParent( b );
510 *k = ( m_setup.s->v.size() - 1 );
517 if ( k ==
long( m_setup.s->v.size() ) ) {
return insert( b,
c, o, &k ); }
525 if ( k ==
long( m_setup.s->v.size() ) ) {
526 m_setup.s->v.push_back( o );
527 if ( !
c->parent() )
c->setParent( b );
537 m_setup.s->v.clear();
552 if ( beg == m_seq->begin() &&
end == m_seq->end() ) {
562 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