The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
Containers::KeyedObjectManager< SETUP > Class Template Reference

KeyedObjectManager Class to manage keyed objects. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/KeyedObjectManager.h>

Collaboration diagram for Containers::KeyedObjectManager< SETUP >:

Public Member Functions

 KeyedObjectManager ()
 Standard Constructor.
 
 KeyedObjectManager (KeyedObjectManager &&other)
 
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.
 
CLID classID ()
 
CLID classID ()
 
void * object (long value) const
 
long insert (ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
 
long insert (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
 
long insertDirect (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
 
void clearDirect ()
 
void * erase (long key, const void *obj)
 
long erase (seq_type::iterator beg, seq_type::iterator end)
 
CLID classID ()
 
void * object (long) const
 
long insert (ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
 
long insert (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
 
long insertDirect (ObjectContainerBase *b, ContainedObject *c, void *o, long k)
 
void clearDirect ()
 
void * erase (long, const void *)
 
long erase (seq_type::iterator beg, seq_type::iterator end)
 
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.
 
void onDirty () const
 
void onDirty () const
 

Private Attributes

seq_typem_seq
 Container holding array like container.
 
long m_direct
 Dirty flag.
 
long m_keyCtxt
 
union { 
 
   char   buffer [128] 
 Buffer space to hold keyed container. More...
 
   SETUP *   s 
 
m_setup 
 

Detailed Description

template<class SETUP>
class Containers::KeyedObjectManager< SETUP >

KeyedObjectManager Class to manage keyed objects.

Object manager class.

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.

Author
M.Frank CERN/LHCb
Version
1.0

Definition at line 45 of file KeyedTraits.h.

Member Typedef Documentation

◆ seq_type

template<class SETUP>
typedef std::vector<void*> Containers::KeyedObjectManager< SETUP >::seq_type
private

Definition at line 49 of file KeyedObjectManager.h.

Constructor & Destructor Documentation

◆ KeyedObjectManager() [1/2]

template<class T>
Containers::KeyedObjectManager< T >::KeyedObjectManager ( )

Standard Constructor.

Definition at line 97 of file KeyedObjectManager.cpp.

97 : m_seq( nullptr ), m_direct( 0 ) {
98 if ( sizeof( typename T::map_type ) > sizeof( m_setup.buffer ) ) {
99 throw GaudiException( "Basic STL contaier sizes are incompatible", "KeyedContainer", StatusCode::FAILURE );
100 }
101 m_setup.s = ::new ( m_setup.buffer + sizeof( m_setup.s ) ) T();
102 m_keyCtxt = -1;
103}
KeyedObjectManager Class to manage keyed objects.
Definition KeyedTraits.h:45
union Containers::KeyedObjectManager::@010153222074056071241275200334232161065316116020 m_setup
seq_type * m_seq
Container holding array like container.

◆ KeyedObjectManager() [2/2]

template<class T>
Containers::KeyedObjectManager< T >::KeyedObjectManager ( KeyedObjectManager< SETUP > && other)

Definition at line 106 of file KeyedObjectManager.cpp.

107 : m_seq( nullptr ), m_direct( other.m_direct ), m_keyCtxt( other.m_keyCtxt ) {
108 m_setup.s = ::new ( m_setup.buffer + sizeof( m_setup.s ) ) T( std::move( *other.m_setup.s ) );
109
110 other.m_keyCtxt = -1;
111 other.m_seq = nullptr;
112 other.m_direct = 0;
113}

◆ ~KeyedObjectManager()

Standard Destructor.

Definition at line 120 of file KeyedObjectManager.cpp.

120 {
121 m_setup.s->~T();
122 }

Member Function Documentation

◆ classID() [1/5]

template<class SETUP>
static CLID Containers::KeyedObjectManager< SETUP >::classID ( )
static

Access CLID for this type of container.

◆ classID() [2/5]

Definition at line 297 of file KeyedObjectManager.cpp.

297 {
298 return CLID_ObjectVector + 0x00030000;
299 }

◆ classID() [3/5]

Definition at line 301 of file KeyedObjectManager.cpp.

301 {
302 return CLID_ObjectVector + 0x00040000;
303 }

◆ classID() [4/5]

Definition at line 491 of file KeyedObjectManager.cpp.

491 {
492 return CLID_ObjectVector + 0x00050000;
493 }

◆ classID() [5/5]

Definition at line 575 of file KeyedObjectManager.cpp.

575 {
576 return CLID_ObjectVector + 0x00060000;
577 }

◆ clear()

template<class T>
void Containers::KeyedObjectManager< T >::clear ( )

Clear content of the vector.

Definition at line 244 of file KeyedObjectManager.cpp.

244 {
245 clearDirect();
246 m_seq->clear();
247}
void clearDirect()
Clear all direct access fields.

◆ clearDirect() [1/3]

template<class T>
void Containers::KeyedObjectManager< T >::clearDirect ( )

Clear all direct access fields.

Definition at line 250 of file KeyedObjectManager.cpp.

250 {
251 switch ( m_direct ) {
252 case 1:
253 m_setup.s->m.clear();
254 break;
255 case 0:
256 m_setup.s->v.clear();
257 break;
258 default:
259 break;
260 }
261 m_direct = 0;
262 m_keyCtxt = -1;
263}

◆ clearDirect() [2/3]

void Containers::KeyedObjectManager< __A >::clearDirect ( )

Definition at line 413 of file KeyedObjectManager.cpp.

413 {
414 m_setup.s->v.clear();
415 m_setup.s->m_idx.clear();
416 m_direct = 0;
417 m_keyCtxt = -1;
418 }

◆ clearDirect() [3/3]

void Containers::KeyedObjectManager< __V >::clearDirect ( )

Definition at line 550 of file KeyedObjectManager.cpp.

550 {
551 m_setup.s->v.clear();
552 m_direct = 0;
553 m_keyCtxt = -1;
554 }

◆ erase() [1/6]

template<class T>
void * Containers::KeyedObjectManager< T >::erase ( long key,
const void * obj )

Remove object from container (very inefficient if key is invalid)

Definition at line 200 of file KeyedObjectManager.cpp.

200 {
201 typedef typename T::map_type MTYP;
202 typedef find<MTYP> FND;
203 if ( 1 == m_direct ) {
204 auto& m = m_setup.s->m;
205 auto i = ( obj ? std::find_if( m.begin(), m.end(), FND( obj ) ) : m_setup.s->m.find( key ) );
206 if ( i != m_setup.s->m.end() ) {
207 void* o = i->second;
208 auto j = std::find( m_seq->begin(), m_seq->end(), o );
209 if ( j != m_seq->end() ) {
210 m_seq->erase( j );
211 m_setup.s->m.erase( i );
212 return o;
213 }
214 }
216 }
217 onDirty();
218 return erase( key, obj );
219}
void onDirty() const
Callback when the container becomes dirty.
void * erase(long key, const void *obj)
Remove object from container (very inefficient if key is invalid)
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent.

◆ erase() [2/6]

void * Containers::KeyedObjectManager< __A >::erase ( long key,
const void * obj )

Definition at line 422 of file KeyedObjectManager.cpp.

422 {
423 if ( 0 == m_direct ) {
424 onDirty();
425 return erase( key, obj );
426 }
427 if ( obj ) {
428 auto& idx = m_setup.s->m_idx;
429 for ( auto& elem : idx ) {
430 auto j = m_setup.s->v.begin() + ( elem );
431 auto k = std::find( m_seq->begin(), m_seq->end(), *j );
432 if ( *j == obj ) {
433 void* o = *j;
434 m_seq->erase( k );
435 m_setup.s->v.erase( j );
436 std::for_each( m_setup.s->m_idx.begin(), m_setup.s->m_idx.end(), array::decrement( elem ) );
437 elem = -1;
438 return o;
439 }
440 }
441 } else if ( key >= 0 && key < long( m_setup.s->m_idx.size() ) ) {
442 auto idx = m_setup.s->m_idx.begin() + key;
443 if ( *idx != -1 ) {
444 auto i = m_setup.s->v.begin() + ( *idx );
445 if ( i == m_setup.s->v.end() ) { containerIsInconsistent(); }
446 void* o = *i;
447 auto j = std::find( m_seq->begin(), m_seq->end(), o );
448 if ( j == m_seq->end() ) { containerIsInconsistent(); }
449 m_seq->erase( j );
450 m_setup.s->v.erase( i );
451 std::for_each( m_setup.s->m_idx.begin(), m_setup.s->m_idx.end(), array::decrement( *idx ) );
452 *idx = -1;
453 return o;
454 }
455 }
457 return nullptr;
458 }

◆ erase() [3/6]

void * Containers::KeyedObjectManager< __V >::erase ( long ,
const void *  )

Definition at line 558 of file KeyedObjectManager.cpp.

558 {
560 return nullptr;
561 }
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it's cont...

◆ erase() [4/6]

template<class T>
long Containers::KeyedObjectManager< T >::erase ( seq_type::iterator beg,
seq_type::iterator end )

Remove object by sequential iterators.

Definition at line 267 of file KeyedObjectManager.cpp.

267 {
268 typedef typename T::map_type MTYP;
269 typedef find<MTYP> FND;
270 if ( 0 == m_direct ) {
271 onDirty();
272 return erase( beg, end );
273 }
274 if ( beg == m_seq->begin() && end == m_seq->end() ) {
275 clear();
276 } else {
277 for ( auto j = beg; j != end; ++j ) {
278 // auto& m = m_setup.s->m;
279 auto i = std::find_if( m_setup.s->m.begin(), m_setup.s->m.end(), FND( *j ) );
280 if ( i != m_setup.s->m.end() ) {
281 m_setup.s->m.erase( i );
282 continue;
283 }
285 }
286 m_seq->erase( beg, end );
287 }
288 return OBJ_ERASED;
289}
void clear()
Clear content of the vector.

◆ erase() [5/6]

long Containers::KeyedObjectManager< __A >::erase ( seq_type::iterator beg,
seq_type::iterator end )

Definition at line 462 of file KeyedObjectManager.cpp.

462 {
463 if ( beg == m_seq->begin() && end == m_seq->end() ) {
464 clear();
465 return OBJ_ERASED;
466 } else if ( 0 == m_direct ) {
467 onDirty();
468 return erase( beg, end );
469 } else {
470 long cnt = 0, nobj = end - beg;
471 auto& idx = m_setup.s->m_idx;
472 for ( auto& elem : idx ) {
473 auto j = m_setup.s->v.begin() + ( elem );
474 auto k = std::find( beg, end, *j );
475 if ( k != end ) {
476 m_setup.s->v.erase( j );
477 std::for_each( m_setup.s->m_idx.begin(), m_setup.s->m_idx.end(), array::decrement( elem ) );
478 elem = -1;
479 cnt++;
480 if ( cnt == nobj ) break;
481 }
482 }
483 m_seq->erase( beg, end );
484 if ( cnt != nobj ) { containerIsInconsistent(); }
485 return OBJ_ERASED;
486 }
487 // cannot reach this point
488 }

◆ erase() [6/6]

long Containers::KeyedObjectManager< __V >::erase ( seq_type::iterator beg,
seq_type::iterator end )

Definition at line 565 of file KeyedObjectManager.cpp.

565 {
566 if ( beg == m_seq->begin() && end == m_seq->end() ) {
567 clear();
568 return OBJ_ERASED;
569 }
571 return OBJ_ERASED;
572 }

◆ insert() [1/6]

template<class T>
long Containers::KeyedObjectManager< T >::insert ( ObjectContainerBase * b,
ContainedObject * c,
void * o,
long * k )

Insert new object into container.

Definition at line 142 of file KeyedObjectManager.cpp.

143 {
144 *key = ++m_keyCtxt;
145 return insert( pBase, pObject, obj, *key );
146}
long insert(ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
Insert new object into container.

◆ insert() [2/6]

long Containers::KeyedObjectManager< __A >::insert ( ObjectContainerBase * b,
ContainedObject * c,
void * o,
long * k )

Definition at line 346 of file KeyedObjectManager.cpp.

346 {
347 // auto key creation only possible for direct access!
348 if ( 0 == m_direct ) {
349 m_seq->push_back( o );
350 m_setup.s->v.push_back( o );
351 if ( !c->parent() ) c->setParent( b );
352 *k = ++m_keyCtxt;
353 return OBJ_INSERTED;
354 }
356 return OBJ_CANNOT_INSERT;
357 }
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.

◆ insert() [3/6]

long Containers::KeyedObjectManager< __V >::insert ( ObjectContainerBase * b,
ContainedObject * c,
void * o,
long * k )

Definition at line 520 of file KeyedObjectManager.cpp.

520 {
521 m_seq->push_back( o );
522 m_setup.s->v.push_back( o );
523 if ( !c->parent() ) c->setParent( b );
524 *k = ( m_setup.s->v.size() - 1 );
525 return OBJ_INSERTED;
526 }

◆ insert() [4/6]

template<class T>
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 149 of file KeyedObjectManager.cpp.

150 {
152 if ( key > m_keyCtxt ) { m_keyCtxt = key; }
153 if ( 1 == m_direct ) {
154 if ( m_setup.s->insert( obj, key ) ) {
155 if ( !pObject->parent() ) { pObject->setParent( pBase ); }
156 m_seq->push_back( obj );
157 return OBJ_INSERTED;
158 }
159 } else if ( key == long( m_setup.s->v.size() ) ) {
160 m_setup.s->v.push_back( obj );
161 if ( !pObject->parent() ) { pObject->setParent( pBase ); }
162 m_seq->push_back( obj );
163 return OBJ_INSERTED;
164 } else {
165 // Document is dirty now...
166 // need to copy all pointers from the vector to the map
167 onDirty();
168 return insert( pBase, pObject, obj, key );
169 }
171 return OBJ_CANNOT_INSERT;
172}

◆ insert() [5/6]

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 361 of file KeyedObjectManager.cpp.

361 {
362 if ( 0 == m_direct ) {
363 if ( k == m_keyCtxt + 1 ) { return insert( b, c, o, &k ); }
364 onDirty();
365 return insert( b, c, o, k );
366 }
368 if ( k > m_keyCtxt ) m_keyCtxt = k;
370 if ( k + 1 > long( m_setup.s->m_idx.size() ) ) { m_setup.s->m_idx.resize( k + 1, -1 ); }
371 auto idx = m_setup.s->m_idx.begin() + k;
372 if ( *idx == -1 ) {
373 *idx = m_setup.s->v.size();
374 m_setup.s->v.push_back( o );
375 m_seq->push_back( o );
376 if ( !c->parent() ) c->setParent( b );
377 return OBJ_INSERTED;
378 }
380 return OBJ_CANNOT_INSERT;
381 }

◆ insert() [6/6]

long Containers::KeyedObjectManager< __V >::insert ( ObjectContainerBase * b,
ContainedObject * c,
void * o,
long k )

Definition at line 530 of file KeyedObjectManager.cpp.

530 {
531 if ( k == long( m_setup.s->v.size() ) ) { return insert( b, c, o, &k ); }
533 return OBJ_CANNOT_INSERT;
534 }

◆ insertDirect() [1/3]

template<class T>
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 175 of file KeyedObjectManager.cpp.

176 {
178 if ( key > m_keyCtxt ) { m_keyCtxt = key; }
179 if ( 1 == m_direct ) {
180 if ( m_setup.s->insert( obj, key ) ) {
181 if ( !pObject->parent() ) { pObject->setParent( pBase ); }
182 return OBJ_INSERTED;
183 }
184 } else if ( key == long( m_setup.s->v.size() ) ) {
185 m_setup.s->v.push_back( obj );
186 if ( !pObject->parent() ) { pObject->setParent( pBase ); }
187 return OBJ_INSERTED;
188 } else {
189 // Document is dirty now...
190 // need to copy all pointers from the vector to the map
191 onDirty();
192 return insertDirect( pBase, pObject, obj, key );
193 }
195 return OBJ_CANNOT_INSERT;
196}
long insertDirect(ObjectContainerBase *b, ContainedObject *c, void *o, long k)
Insert element into direct access map.

◆ insertDirect() [2/3]

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 385 of file KeyedObjectManager.cpp.

385 {
386 if ( 0 == m_direct ) {
387 if ( k == m_keyCtxt + 1 ) {
388 m_setup.s->v.push_back( o );
389 if ( !c->parent() ) c->setParent( b );
390 ++m_keyCtxt;
391 return OBJ_INSERTED;
392 }
393 onDirty();
394 return insertDirect( b, c, o, k );
395 }
397 if ( k > m_keyCtxt ) m_keyCtxt = k;
399 if ( k + 1 > long( m_setup.s->m_idx.size() ) ) { m_setup.s->m_idx.resize( k + 1, -1 ); }
400 auto idx = m_setup.s->m_idx.begin() + k;
401 if ( *idx == -1 ) {
402 *idx = m_setup.s->v.size();
403 m_setup.s->v.push_back( o );
404 if ( !c->parent() ) c->setParent( b );
405 return OBJ_INSERTED;
406 }
408 return OBJ_CANNOT_INSERT;
409 }

◆ insertDirect() [3/3]

long Containers::KeyedObjectManager< __V >::insertDirect ( ObjectContainerBase * b,
ContainedObject * c,
void * o,
long k )

Definition at line 538 of file KeyedObjectManager.cpp.

538 {
539 if ( k == long( m_setup.s->v.size() ) ) {
540 m_setup.s->v.push_back( o );
541 if ( !c->parent() ) c->setParent( b );
542 return OBJ_INSERTED;
543 }
545 return OBJ_CANNOT_INSERT;
546 }

◆ isDirect()

template<class SETUP>
long Containers::KeyedObjectManager< SETUP >::isDirect ( ) const
inline

Check if the container is dirty.

Definition at line 75 of file KeyedObjectManager.h.

75{ return m_direct; }

◆ object() [1/3]

template<class T>
void * Containers::KeyedObjectManager< T >::object ( long key) const

Retrieve object identified by a key from the container.

Definition at line 222 of file KeyedObjectManager.cpp.

222 {
223 if ( 0 == m_direct ) onDirty();
224 auto i = m_setup.s->m.find( key );
225 if ( i != m_setup.s->m.end() ) return ( *i ).second;
226 return nullptr;
227}

◆ object() [2/3]

void * Containers::KeyedObjectManager< __A >::object ( long value) const

Definition at line 321 of file KeyedObjectManager.cpp.

321 {
322#ifdef CHECK_KEYED_CONTAINER
323 unsigned long siz = m_setup.s->m_idx.size();
324 if ( value >= 0 && size_t( value ) < siz ) {
325 long ent = *( m_setup.s->m_idx.begin() + value );
326 if ( ent >= 0 ) { return *( m_setup.s->v.begin() + ent ); }
327 }
328 return nullptr;
329#else
330 return *( m_setup.s->v.begin() + ( *( m_setup.s->m_idx.begin() + value ) ) );
331#endif
332 }

◆ object() [3/3]

void * Containers::KeyedObjectManager< __V >::object ( long ) const

Definition at line 508 of file KeyedObjectManager.cpp.

508 {
510 return nullptr;
511 }

◆ onDirty() [1/3]

template<class T>
void Containers::KeyedObjectManager< T >::onDirty ( ) const
private

Callback when the container becomes dirty.

Definition at line 133 of file KeyedObjectManager.cpp.

133 {
134 m_direct = 1;
135 auto& s = *m_setup.s;
136 long i = 0;
137 for ( auto p : s.v ) s.insert( p, i++ );
138 s.v.clear();
139}

◆ onDirty() [2/3]

void Containers::KeyedObjectManager< __A >::onDirty ( ) const
private

Definition at line 335 of file KeyedObjectManager.cpp.

335 {
336 m_direct = 1;
337 m_setup.s->m_idx.reserve( m_setup.s->v.size() + 1 );
338 for ( size_t i = 0, stop = m_setup.s->v.size(); i < stop; ++i ) {
339 if ( !m_setup.s->v[i] ) { containerIsInconsistent(); }
340 m_setup.s->m_idx.push_back( i );
341 }
342 }

◆ onDirty() [3/3]

void Containers::KeyedObjectManager< __V >::onDirty ( ) const
private

Definition at line 514 of file KeyedObjectManager.cpp.

514 {
516 }

◆ reserve()

template<class T>
void Containers::KeyedObjectManager< T >::reserve ( long size)

Reserve buffer space.

Definition at line 230 of file KeyedObjectManager.cpp.

230 {
231 switch ( m_direct ) {
232 case 1:
233 break;
234 case 0:
235 m_setup.s->v.reserve( len );
236 break;
237 default:
238 break;
239 }
240 m_seq->reserve( len );
241}

◆ setup()

template<class T>
void Containers::KeyedObjectManager< T >::setup ( void * seq,
void ** rndm )

Setup of the Map and the parent object.

Definition at line 127 of file KeyedObjectManager.cpp.

127 {
128 m_seq = (seq_type*)seq;
129 *rndm = &m_setup.s->v;
130}

Member Data Documentation

◆ buffer

template<class SETUP>
char Containers::KeyedObjectManager< SETUP >::buffer[128]

Buffer space to hold keyed container.

Definition at line 57 of file KeyedObjectManager.h.

◆ m_direct

template<class SETUP>
long Containers::KeyedObjectManager< SETUP >::m_direct
mutableprivate

Dirty flag.

Definition at line 53 of file KeyedObjectManager.h.

◆ m_keyCtxt

template<class SETUP>
long Containers::KeyedObjectManager< SETUP >::m_keyCtxt
mutableprivate

Definition at line 54 of file KeyedObjectManager.h.

◆ m_seq

template<class SETUP>
seq_type* Containers::KeyedObjectManager< SETUP >::m_seq
private

Container holding array like container.

Definition at line 51 of file KeyedObjectManager.h.

◆ [union]

union { ... } Containers::KeyedObjectManager< SETUP >::m_setup

◆ s

template<class SETUP>
SETUP* Containers::KeyedObjectManager< SETUP >::s

Definition at line 58 of file KeyedObjectManager.h.


The documentation for this class was generated from the following files: