1 #ifndef GAUDIKERNEL_KEYEDCONTAINER_H
2 #define GAUDIKERNEL_KEYEDCONTAINER_H
21 #define FORCE_INLINE __forceinline
23 #define FORCE_INLINE inline
62 template <
class DATATYPE,
class MAPPING=Containers::HashMap >
109 container_type m_cont;
117 #ifdef CHECK_KEYED_CONTAINER
118 value_type i_object(
const key_type& k)
const {
120 if ( traits::checkBounds(m_random, k) ) {
121 value_type p = *(m_random->
begin()+traits::hash(k));
122 if ( traits::checkKey(p, k) ) {
128 value_type p = value_type(m_cont.
object(traits::hash(k)));
129 return traits::checkKey(p, k) ? p : 0;
134 ? value_type(*(m_random->
begin()+traits::hash(k)))
135 : value_type(m_cont.
object(traits::hash(k)));
138 long i_erase(const_reference v,
const key_type& k) {
140 value_type p = value_type(m_cont.
erase(traits::hash(k), v));
142 if ( p->parent() == this ) {
166 if ( par == m_obj ) {
182 seq_type** rptr = &m_random;
183 seq_type* sptr = &m_sequential;
184 m_cont.
setup((
void*)sptr,(
void**)rptr);
199 static CLID clid = contained_type::classID() + container_type::classID();
253 return i_object( traits::makeKey( key_value ) );
272 size_type size()
const {
return m_sequential.
size(); }
306 iterator
begin() {
return m_sequential.
begin(); }
309 const_iterator
begin()
const {
return m_sequential.
begin(); }
311 iterator
end() {
return m_sequential.
end(); }
313 const_iterator
end()
const {
return m_sequential.
end(); }
317 const_reverse_iterator
rbegin()
const {
return m_sequential.
rbegin(); }
319 reverse_iterator
rend() {
return m_sequential.
rend(); }
321 const_reverse_iterator
rend()
const {
return m_sequential.
rend(); }
341 value_type
object(
const key_type& kval)
const {
return i_object(kval); }
352 value_type
operator()(
const key_type& kval)
const {
return i_object(kval); }
377 long erase(
const key_type& kval) {
return i_erase(0, kval); }
433 void erase(iterator pos_start, iterator pos_stop,
bool use_temp=
false);
453 const key_type& insert(
const value_type val,
const key_type& kval);
476 const key_type& insert(
const value_type val);
489 template <
class DATATYPE,
class MAPPING>
inline
497 template <
class DATATYPE,
class MAPPING>
inline
502 typename seq_type::iterator
i = m_sequential.
begin();
503 typename seq_type::iterator
s = m_sequential.
end();
504 for ( ; i !=
s; i++ ) {
505 typename seq_type::value_type v = *
i;
507 if ( !v->hasKey() ) {
508 traits::setKey(v, v->key());
511 long k0 = traits::hash(v->key());
527 template <
class DATATYPE,
class MAPPING>
inline
531 ((0==m_cont.
isDirect()) ? m_random : &m_sequential);
534 template <
class DATATYPE,
class MAPPING>
inline
537 const key_type& kval)
540 long k0 = traits::hash(kval);
541 if ( !val->hasKey() || (traits::hash(val->key()) == k0) ) {
543 if ( !val->hasKey() ) traits::setKey(val, kval);
555 template <
class DATATYPE,
class MAPPING>
560 if ( val->hasKey() ) {
561 if (m_cont.
insert(
this,val,val,traits::hash(val->key()))
569 traits::setKey(val, traits::makeKey(k0));
579 template <
class DATATYPE,
class MAPPING>
inline
582 const contained_type* ptr =
dynamic_cast<const contained_type*
>(p);
583 if ( ptr )
return traits::identifier(ptr->key());
588 template <
class DATATYPE,
class MAPPING>
inline
592 typename seq_type::const_iterator
i = m_sequential.
begin();
593 typename seq_type::const_iterator
s = m_sequential.
end();
596 for ( ; i !=
s; i++ ) {
604 template <
class DATATYPE,
class MAPPING>
inline
607 return traits::identifier(insert(dynamic_cast<typename seq_type::value_type>(pObject)));
611 template <
class DATATYPE,
class MAPPING>
inline
614 contained_type*
p1 =
dynamic_cast<contained_type*
>(p);
616 return this->erase(p1);
635 template <
class DATATYPE,
class MAPPING>
inline
641 bool is_start = start_pos == m_sequential.
begin();
642 bool is_stop = stop_pos == m_sequential.
end();
643 if ( is_start && is_stop ) {
646 else if ( is_start || is_stop || use_tmp ) {
648 tmp.
insert(tmp.end(), stop_pos, m_sequential.
end());
650 this->erase(m_sequential.
begin(), m_sequential.
end());
655 seq_type *sptr = &m_sequential;
661 m_cont.
erase(i1, i2);
665 #endif // GAUDIKERNEL_KEYEDCONTAINER_H
virtual const std::vector< const ContainedObject * > * containedObjects() const
Retrieve the full content of the object container by reference.
void operator()(value_type p)
reverse_iterator rbegin()
reverse_iterator returns the beginning of the reversed container
virtual StatusCode update()
Provide empty placeholder for internal object reconfiguration callback.
Object was inserted into the container.
seq_type::reverse_iterator reverse_iterator
Sequential access: reverse iterator type used in sequential container.
seq_type::const_reference const_reference
Sequential access: const reference type used in sequential container.
void reserve(size_type value)
Reserve place for "value" objects in the container.
value_type object(const key_type &kval) const
Object access by key.
static const CLID & classID()
Retrieve reference to class definition structure (static access)
long erase(iterator pos)
Remove/erase object (identified by iterator) from the container.
virtual StatusCode update()
Reconfigure direct access to elements (Needed by POOL data loading) This function reuses the "update"...
size_t size_type
size_type, to conform the STL container interface
const_reverse_iterator rbegin() const
const reverse_iterator returns the beginning of the reversed container
void clear()
Clear content of the vector.
virtual long add(ContainedObject *pObject)
ObjectContainerBase overload: Add an object to the container.
seq_type m_sequential
Array to allow sequential access to the object (can be ordered).
seq_type::reference reference
Sequential access: reference type used in sequential container.
int key_type
Definition of the key-type to access object.
virtual size_type numberOfObjects() const =0
Number of objects in the container.
ObjectContainerBase * m_obj
void clearDirect()
Clear all direct access fields.
template class KeyedContainer, KeyedContainer.h
KeyedContainer< DATATYPE, MAPPING > * m_obj
long erase(const key_type &kval)
Remove/erase object (identified by key) from the container.
Containers::traits< container_type, contained_type > traits
Traits class definition.
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)
static const CLID & classID()
Retrieve class ID.
seq_type::iterator iterator
Sequential access: iterator type used in sequential container.
virtual long add(ContainedObject *pObject)=0
Virtual functions (forwards to the concrete container definitions) Add an object to the container...
Internal functor for insertion of objects.
DATATYPE contained_type
Definition of the contained object type.
value_type operator()(const key_type &kval) const
STL algorithms support for object access.
Object was removed from the container and deleted.
const ObjectContainerBase * parent() const
Access to parent object.
const key_type & insert(const value_type val, const key_type &kval)
Insert entry to the container with a valid key.
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
virtual ~KeyedContainer()
Destructor.
auto begin(reverse_wrapper< T > &w)
const_reverse_iterator rend() const
const reverse_iterator pointing to the end of the reversed container
bool empty() const
For consistency with STL: check if container is empty.
void reserve(long size)
Reserve buffer space.
reverse_iterator rend()
reverse_iterator pointing to the end of the reversed container
_RemoveRelease(ObjectContainerBase *p)
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it's cont...
virtual const CLID & clID() const
Retrieve reference to class definition structure.
FORCE_INLINE value_type i_object(const key_type &k) const
Internal function to access objects within the container.
This class is used for returning status codes from appropriate routines.
const_iterator end() const
Retrieve terminating const iterator.
virtual ContainedObject * containedObject(long key_value) const
ObjectContainerBase overload: Retrieve the object by reference given the long integer representation ...
seq_type::value_type value_type
Sequential access: definition of type stored in sequential container.
auto end(reverse_wrapper< T > &w)
seq_type::const_iterator const_iterator
Sequential access: const iterator type used in sequential container.
long insert(ObjectContainerBase *b, ContainedObject *c, void *o, long *k)
Insert new object into container.
unsigned int CLID
Class ID definition.
Object was removed, but not deleted.
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
virtual long index(const ContainedObject *p) const
ObjectContainerBase overload: Retrieve the full long integer representation of the object's key from ...
long erase(const value_type val)
Remove/erase object (identified by pointer value) from the container.
_InsertRelease(KeyedContainer< DATATYPE, MAPPING > *p)
iterator end()
Retrieve terminating iterator.
virtual long index(const ContainedObject *obj) const =0
Distance of a given object from the beginning of its container.
Object not present in the container.
contained_type::key_type key_type
Definition of the key type: re-use definition of contained type.
Internal functor for insertion of objects.
void setup(void *seq, void **rndm)
Setup of the Map and the parent object.
const_iterator begin() const
Retrieve start const iterator.
virtual long remove(ContainedObject *pObject)
ObjectContainerBase overload: Remove an object from the container.
long isDirect() const
Check if the container is dirty.
ObjectContainerBase is the base class for Gaudi container classes.
void operator()(value_type p)
seq_type::const_reverse_iterator const_reverse_iterator
Sequential access: const reverse iterator type used in sequential container.
TO * reference(FROM *from)
MAPPING container_type
Definition of the implementing container type.
seq_type * m_random
Array to allow random access to objects (not exposed)
long insertDirect(ObjectContainerBase *b, ContainedObject *c, void *o, long k)
Insert element into direct access map.
void clear()
Clear the entire content and erase the objects from the container.