|
Gaudi Framework, version v21r9 |
| Home | Generated: 3 May 2010 |
#include <KeyedObjectManager.h>

Public Member Functions | |
| KeyedObjectManager () | |
| Standard Constructor. | |
| 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. | |
| template<> | |
| CLID | classID () |
| template<> | |
| CLID | classID () |
| template<> | |
| void * | object (long value) const |
| template<> | |
| void | onDirty () const |
| template<> | |
| long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long *k) |
| template<> | |
| long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long k) |
| template<> | |
| long | insertDirect (ObjectContainerBase *b, ContainedObject *c, void *o, long k) |
| template<> | |
| void | clearDirect () |
| template<> | |
| void * | erase (long key, const void *obj) |
| template<> | |
| long | erase (seq_type::iterator beg, seq_type::iterator end) |
| template<> | |
| CLID | classID () |
| template<> | |
| void * | object (long) const |
| template<> | |
| void | onDirty () const |
| template<> | |
| long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long *k) |
| template<> | |
| long | insert (ObjectContainerBase *b, ContainedObject *c, void *o, long k) |
| template<> | |
| long | insertDirect (ObjectContainerBase *b, ContainedObject *c, void *o, long k) |
| template<> | |
| void | clearDirect () |
| template<> | |
| void * | erase (long, const void *) |
| template<> | |
| long | erase (seq_type::iterator beg, seq_type::iterator end) |
| template<> | |
| 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. | |
Private Attributes | |
| seq_type * | m_seq |
| Container holding array like container. | |
| long | m_direct |
| Dirty flag. | |
| long | m_keyCtxt |
| union { | |
| char buffer [128] | |
| Buffer space to hold keyed container. | |
| SETUP * s | |
| } | m_setup |
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.
Definition at line 46 of file KeyedObjectManager.h.
typedef std::vector<void*> Containers::KeyedObjectManager< SETUP >::seq_type [private] |
Definition at line 48 of file KeyedObjectManager.h.
| Containers::KeyedObjectManager< T >::KeyedObjectManager | ( | ) | [inline] |
Standard Constructor.
Definition at line 91 of file KeyedObjectManager.cpp.
00092 : m_direct(0) 00093 { 00094 if ( sizeof(typename T::map_type) > sizeof(m_setup.buffer) ) { 00095 throw GaudiException("Basic STL contaier sizes are incompatible", 00096 "KeyedContainer", 00097 0); 00098 } 00099 m_setup.s = ::new(m_setup.buffer+sizeof(m_setup.s)) T(); 00100 m_keyCtxt = -1; 00101 }
| Containers::KeyedObjectManager< T >::~KeyedObjectManager | ( | ) | [inline, virtual] |
Standard Destructor.
Definition at line 104 of file KeyedObjectManager.cpp.
00105 { 00106 m_setup.s->~T(); 00107 }
| void Containers::KeyedObjectManager< T >::onDirty | ( | ) | const [inline, private] |
| void Containers::KeyedObjectManager< T >::clearDirect | ( | ) | [inline] |
Clear all direct access fields.
Definition at line 272 of file KeyedObjectManager.cpp.
00273 { 00274 typedef typename T::map_type MTYP; 00275 switch( m_direct ) { 00276 case 1: 00277 m_setup.s->m.clear(); 00278 break; 00279 case 0: 00280 m_setup.s->v.clear(); 00281 break; 00282 default: 00283 break; 00284 } 00285 m_direct = 0; 00286 m_keyCtxt = -1; 00287 }
| long Containers::KeyedObjectManager< T >::insertDirect | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long | k | |||
| ) | [inline] |
Insert element into direct access map.
Keep major key value
Definition at line 176 of file KeyedObjectManager.cpp.
00181 { 00183 if ( key > m_keyCtxt ) { 00184 m_keyCtxt = key; 00185 } 00186 if ( 1==m_direct ) { 00187 if ( m_setup.s->insert(obj, key) ) { 00188 if ( !pObject->parent() ) { 00189 pObject->setParent(pBase); 00190 } 00191 return OBJ_INSERTED; 00192 } 00193 } 00194 else if ( key == long(m_setup.s->v.size()) ) { 00195 m_setup.s->v.push_back(obj); 00196 if ( !pObject->parent() ) { 00197 pObject->setParent(pBase); 00198 } 00199 return OBJ_INSERTED; 00200 } 00201 else { 00202 // Document is dirty now... 00203 // need to copy all pointers from the vector to the map 00204 onDirty(); 00205 return insertDirect(pBase, pObject, obj, key); 00206 } 00207 cannotInsertToContainer(); 00208 return OBJ_CANNOT_INSERT; 00209 }
| long Containers::KeyedObjectManager< SETUP >::isDirect | ( | ) | const [inline] |
Check if the container is dirty.
Definition at line 73 of file KeyedObjectManager.h.
00073 { return m_direct; }
| void * Containers::KeyedObjectManager< T >::object | ( | long | key | ) | const [inline] |
Retrieve object identified by a key from the container.
Definition at line 237 of file KeyedObjectManager.cpp.
00238 { 00239 if ( 0 == m_direct ) { 00240 onDirty(); 00241 } 00242 typename T::map_type::const_iterator i = m_setup.s->m.find(key); 00243 if ( i != m_setup.s->m.end() ) { 00244 return (*i).second; 00245 } 00246 return 0; 00247 }
| long Containers::KeyedObjectManager< T >::insert | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long * | k | |||
| ) | [inline] |
| long Containers::KeyedObjectManager< T >::insert | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long | k | |||
| ) | [inline] |
Insert new object into container.
Keep major key value
Definition at line 138 of file KeyedObjectManager.cpp.
00143 { 00145 if ( key > m_keyCtxt ) { 00146 m_keyCtxt = key; 00147 } 00148 if ( 1==m_direct ) { 00149 if ( m_setup.s->insert(obj, key) ) { 00150 if ( !pObject->parent() ) { 00151 pObject->setParent(pBase); 00152 } 00153 m_seq->push_back(obj); 00154 return OBJ_INSERTED; 00155 } 00156 } 00157 else if ( key == long(m_setup.s->v.size()) ) { 00158 m_setup.s->v.push_back(obj); 00159 if ( !pObject->parent() ) { 00160 pObject->setParent(pBase); 00161 } 00162 m_seq->push_back(obj); 00163 return OBJ_INSERTED; 00164 } 00165 else { 00166 // Document is dirty now... 00167 // need to copy all pointers from the vector to the map 00168 onDirty(); 00169 return insert(pBase, pObject, obj, key); 00170 } 00171 cannotInsertToContainer(); 00172 return OBJ_CANNOT_INSERT; 00173 }
| void * Containers::KeyedObjectManager< T >::erase | ( | long | key, | |
| const void * | obj | |||
| ) | [inline] |
Remove object from container (very inefficient if key is invalid).
Definition at line 213 of file KeyedObjectManager.cpp.
00214 { 00215 typedef typename T::map_type MTYP; 00216 typedef find<MTYP> FND; 00217 if ( 1 == m_direct ) { 00218 typename T::map_type& m = m_setup.s->m; 00219 typename T::map_type::iterator i = (0==obj) ? m_setup.s->m.find(key) 00220 : std::find_if(m.begin(),m.end(),FND(obj)); 00221 if ( i != m_setup.s->m.end() ) { 00222 void* o = (*i).second; 00223 seq_type::iterator j = std::find(m_seq->begin(),m_seq->end(),o); 00224 if ( j != m_seq->end() ) { 00225 m_seq->erase(j); 00226 m_setup.s->m.erase(i); 00227 return o; 00228 } 00229 } 00230 containerIsInconsistent(); 00231 } 00232 onDirty(); 00233 return erase(key, obj); 00234 }
| long Containers::KeyedObjectManager< T >::erase | ( | seq_type::iterator | beg, | |
| seq_type::iterator | end | |||
| ) | [inline] |
Remove object by sequential iterators.
Definition at line 291 of file KeyedObjectManager.cpp.
00293 { 00294 typedef typename T::map_type MTYP; 00295 typedef find<MTYP> FND; 00296 if ( 0 == m_direct ) { 00297 onDirty(); 00298 return erase(beg, end); 00299 } 00300 if ( beg == m_seq->begin() && end == m_seq->end() ) { 00301 clear(); 00302 } 00303 else { 00304 for ( seq_type::iterator j=beg; j != end; ++j) { 00305 typename T::map_type& m = m_setup.s->m; 00306 typename T::map_type::iterator i = std::find_if(m.begin(),m.end(),FND(*j)); 00307 if ( i != m_setup.s->m.end() ) { 00308 m_setup.s->m.erase(i); 00309 continue; 00310 } 00311 containerIsInconsistent(); 00312 } 00313 m_seq->erase(beg, end); 00314 } 00315 return OBJ_ERASED; 00316 }
| void Containers::KeyedObjectManager< T >::reserve | ( | long | size | ) | [inline] |
| void Containers::KeyedObjectManager< T >::clear | ( | void | ) | [inline] |
Clear content of the vector.
Definition at line 265 of file KeyedObjectManager.cpp.
00266 { 00267 clearDirect(); 00268 m_seq->clear(); 00269 }
| void Containers::KeyedObjectManager< T >::setup | ( | void * | seq, | |
| void ** | rndm | |||
| ) | [inline] |
| static CLID Containers::KeyedObjectManager< SETUP >::classID | ( | ) | [static] |
Access CLID for this type of container.
| CLID Containers::KeyedObjectManager< Containers::map >::classID | ( | ) | [inline] |
Definition at line 324 of file KeyedObjectManager.cpp.
00324 { 00325 return CLID_ObjectVector+0x00030000; 00326 }
| CLID Containers::KeyedObjectManager< Containers::hashmap >::classID | ( | ) | [inline] |
Definition at line 328 of file KeyedObjectManager.cpp.
00328 { 00329 return CLID_ObjectVector+0x00040000; 00330 }
| void * Containers::KeyedObjectManager< __A >::object | ( | long | value | ) | const [inline] |
Definition at line 348 of file KeyedObjectManager.cpp.
00349 { 00350 #ifdef CHECK_KEYED_CONTAINER 00351 unsigned long siz = m_setup.s->m_idx.size(); 00352 if ( value >= 0 && size_t(value) < siz ) { 00353 long ent = *(m_setup.s->m_idx.begin()+value); 00354 if ( ent >= 0 ) { 00355 return *(m_setup.s->v.begin() + ent); 00356 } 00357 } 00358 return 0; 00359 #else 00360 return *(m_setup.s->v.begin() + (*(m_setup.s->m_idx.begin()+value))); 00361 #endif 00362 }
| void Containers::KeyedObjectManager< __A >::onDirty | ( | ) | const [inline] |
Definition at line 365 of file KeyedObjectManager.cpp.
00365 { 00366 m_direct = 1; 00367 m_setup.s->m_idx.reserve(m_setup.s->v.size()+1); 00368 for(int i = 0, stop = m_setup.s->v.size(); i < stop; ++i) { 00369 if ( m_setup.s->v[i] == 0 ) { 00370 containerIsInconsistent(); 00371 } 00372 m_setup.s->m_idx.push_back(i); 00373 } 00374 }
| long Containers::KeyedObjectManager< __A >::insert | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long * | k | |||
| ) | [inline] |
Definition at line 378 of file KeyedObjectManager.cpp.
00382 { 00383 // auto key creation only possible for direct access! 00384 if ( 0 == m_direct ) { 00385 m_seq->push_back(o); 00386 m_setup.s->v.push_back(o); 00387 if ( !c->parent() ) c->setParent(b); 00388 *k = ++m_keyCtxt; 00389 return OBJ_INSERTED; 00390 } 00391 cannotInsertToContainer(); 00392 return OBJ_CANNOT_INSERT; 00393 }
| long Containers::KeyedObjectManager< __A >::insert | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long | k | |||
| ) | [inline] |
Keep major key value
Extend redirection array and insert
Definition at line 397 of file KeyedObjectManager.cpp.
00401 { 00402 if ( 0 == m_direct ) { 00403 if ( k == m_keyCtxt+1 ) { 00404 return insert(b, c, o, &k); 00405 } 00406 onDirty(); 00407 return insert(b, c, o, k); 00408 } 00410 if ( k > m_keyCtxt ) m_keyCtxt = k; 00412 if ( k+1 > long(m_setup.s->m_idx.size()) ) { 00413 m_setup.s->m_idx.resize(k+1, -1); 00414 } 00415 std::vector<long>::iterator idx = m_setup.s->m_idx.begin()+k; 00416 if ( *idx == -1 ) { 00417 *idx = m_setup.s->v.size(); 00418 m_setup.s->v.push_back(o); 00419 m_seq->push_back(o); 00420 if ( !c->parent() ) c->setParent(b); 00421 return OBJ_INSERTED; 00422 } 00423 cannotInsertToContainer(); 00424 return OBJ_CANNOT_INSERT; 00425 }
| long Containers::KeyedObjectManager< __A >::insertDirect | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long | k | |||
| ) | [inline] |
Keep major key value
Extend redirection array and insert
Definition at line 429 of file KeyedObjectManager.cpp.
00433 { 00434 if ( 0 == m_direct ) { 00435 if ( k == m_keyCtxt+1 ) { 00436 m_setup.s->v.push_back(o); 00437 if ( !c->parent() ) c->setParent(b); 00438 ++m_keyCtxt; 00439 return OBJ_INSERTED; 00440 } 00441 onDirty(); 00442 return insertDirect(b, c, o, k); 00443 } 00445 if ( k > m_keyCtxt ) m_keyCtxt = k; 00447 if ( k+1 > long(m_setup.s->m_idx.size()) ) { 00448 m_setup.s->m_idx.resize(k+1, -1); 00449 } 00450 std::vector<long>::iterator idx = m_setup.s->m_idx.begin()+k; 00451 if ( *idx == -1 ) { 00452 *idx = m_setup.s->v.size(); 00453 m_setup.s->v.push_back(o); 00454 if ( !c->parent() ) c->setParent(b); 00455 return OBJ_INSERTED; 00456 } 00457 cannotInsertToContainer(); 00458 return OBJ_CANNOT_INSERT; 00459 }
| void Containers::KeyedObjectManager< __A >::clearDirect | ( | ) | [inline] |
| void * Containers::KeyedObjectManager< __A >::erase | ( | long | key, | |
| const void * | obj | |||
| ) | [inline] |
Definition at line 472 of file KeyedObjectManager.cpp.
00474 { 00475 typedef std::vector<long> id_type; 00476 typedef id_type::iterator id_iter; 00477 typedef __A::map_type MTYP; 00478 typedef find<MTYP> FND; 00479 if ( 0 == m_direct ) { 00480 onDirty(); 00481 return erase(key, obj); 00482 } 00483 if ( 0 != obj ) { 00484 id_type& idx = m_setup.s->m_idx; 00485 for ( id_iter i=idx.begin(); i != idx.end(); i++ ) { 00486 seq_type::iterator j = m_setup.s->v.begin()+(*i); 00487 seq_type::iterator k = std::find(m_seq->begin(),m_seq->end(),*j); 00488 if ( *j == obj ) { 00489 void* o = *j; 00490 m_seq->erase(k); 00491 m_setup.s->v.erase(j); 00492 std::for_each(m_setup.s->m_idx.begin(), 00493 m_setup.s->m_idx.end(), 00494 array::decrement(*i)); 00495 *i = -1; 00496 return o; 00497 } 00498 } 00499 } 00500 else if ( key >= 0 && key < long(m_setup.s->m_idx.size()) ) { 00501 id_iter idx = m_setup.s->m_idx.begin()+key; 00502 if ( *idx != -1 ) { 00503 seq_type::iterator i = m_setup.s->v.begin()+(*idx); 00504 if ( i == m_setup.s->v.end() ) { 00505 containerIsInconsistent(); 00506 } 00507 void* o = *i; 00508 seq_type::iterator j=std::find(m_seq->begin(),m_seq->end(),o); 00509 if ( j == m_seq->end() ) { 00510 containerIsInconsistent(); 00511 } 00512 m_seq->erase(j); 00513 m_setup.s->v.erase(i); 00514 std::for_each(m_setup.s->m_idx.begin(), 00515 m_setup.s->m_idx.end(), 00516 array::decrement(*idx)); 00517 *idx = -1; 00518 return o; 00519 } 00520 } 00521 containerIsInconsistent(); 00522 return 0; 00523 }
| long Containers::KeyedObjectManager< __A >::erase | ( | seq_type::iterator | beg, | |
| seq_type::iterator | end | |||
| ) | [inline] |
Definition at line 527 of file KeyedObjectManager.cpp.
00529 { 00530 typedef std::vector<long> id_type; 00531 typedef id_type::iterator id_iter; 00532 if ( beg == m_seq->begin() && end == m_seq->end() ) { 00533 clear(); 00534 return OBJ_ERASED; 00535 } 00536 else if ( 0 == m_direct ) { 00537 onDirty(); 00538 return erase(beg, end); 00539 } 00540 else { 00541 long cnt = 0, nobj = end-beg; 00542 id_type& idx = m_setup.s->m_idx; 00543 for ( id_iter i=idx.begin(); i != idx.end(); i++ ) { 00544 seq_type::iterator j = m_setup.s->v.begin()+(*i); 00545 seq_type::iterator k = std::find(beg,end,*j); 00546 if ( k != end ) { 00547 m_setup.s->v.erase(j); 00548 std::for_each(m_setup.s->m_idx.begin(), 00549 m_setup.s->m_idx.end(), 00550 array::decrement(*i)); 00551 *i = -1; 00552 cnt++; 00553 if ( cnt == nobj ) break; 00554 } 00555 } 00556 m_seq->erase(beg, end); 00557 if ( cnt != nobj ) { 00558 containerIsInconsistent(); 00559 } 00560 return OBJ_ERASED; 00561 } 00562 // cannot reach this point 00563 }
| CLID Containers::KeyedObjectManager< __A >::classID | ( | ) | [inline] |
Definition at line 566 of file KeyedObjectManager.cpp.
00566 { 00567 return CLID_ObjectVector+0x00050000; 00568 }
| void * Containers::KeyedObjectManager< __V >::object | ( | long | ) | const [inline] |
Definition at line 583 of file KeyedObjectManager.cpp.
00584 { 00585 invalidContainerOperation(); 00586 return 0; 00587 }
| void Containers::KeyedObjectManager< __V >::onDirty | ( | ) | const [inline] |
Definition at line 590 of file KeyedObjectManager.cpp.
00590 { 00591 invalidContainerOperation(); 00592 }
| long Containers::KeyedObjectManager< __V >::insert | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long * | k | |||
| ) | [inline] |
| long Containers::KeyedObjectManager< __V >::insert | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long | k | |||
| ) | [inline] |
Definition at line 610 of file KeyedObjectManager.cpp.
00614 { 00615 if ( k == long(m_setup.s->v.size()) ) { 00616 return insert(b, c, o, &k); 00617 } 00618 cannotInsertToContainer(); 00619 return OBJ_CANNOT_INSERT; 00620 }
| long Containers::KeyedObjectManager< __V >::insertDirect | ( | ObjectContainerBase * | b, | |
| ContainedObject * | c, | |||
| void * | o, | |||
| long | k | |||
| ) | [inline] |
Definition at line 624 of file KeyedObjectManager.cpp.
00628 { 00629 if ( k == long(m_setup.s->v.size()) ) { 00630 m_setup.s->v.push_back(o); 00631 if ( !c->parent() ) c->setParent(b); 00632 return OBJ_INSERTED; 00633 } 00634 cannotInsertToContainer(); 00635 return OBJ_CANNOT_INSERT; 00636 }
| void Containers::KeyedObjectManager< __V >::clearDirect | ( | ) | [inline] |
| void * Containers::KeyedObjectManager< __V >::erase | ( | long | , | |
| const void * | ||||
| ) | [inline] |
Definition at line 648 of file KeyedObjectManager.cpp.
00650 { 00651 invalidContainerOperation(); 00652 return 0; 00653 }
| long Containers::KeyedObjectManager< __V >::erase | ( | seq_type::iterator | beg, | |
| seq_type::iterator | end | |||
| ) | [inline] |
Definition at line 657 of file KeyedObjectManager.cpp.
00659 { 00660 if ( beg == m_seq->begin() && end == m_seq->end() ) { 00661 clear(); 00662 return OBJ_ERASED; 00663 } 00664 invalidContainerOperation(); 00665 return OBJ_ERASED; 00666 }
| CLID Containers::KeyedObjectManager< __V >::classID | ( | ) | [inline] |
Definition at line 669 of file KeyedObjectManager.cpp.
00669 { 00670 return CLID_ObjectVector+0x00060000; 00671 }
seq_type* Containers::KeyedObjectManager< SETUP >::m_seq [private] |
long Containers::KeyedObjectManager< SETUP >::m_direct [mutable, private] |
long Containers::KeyedObjectManager< SETUP >::m_keyCtxt [mutable, private] |
Definition at line 53 of file KeyedObjectManager.h.
| char Containers::KeyedObjectManager< SETUP >::buffer[128] |
| SETUP* Containers::KeyedObjectManager< SETUP >::s |
Definition at line 57 of file KeyedObjectManager.h.
union { ... } Containers::KeyedObjectManager< SETUP >::m_setup [private] |