1 #ifndef GAUDIKERNEL_KEYEDCONTAINER_H 2 #define GAUDIKERNEL_KEYEDCONTAINER_H 23 #define FORCE_INLINE __forceinline 25 #define FORCE_INLINE inline 64 template <
class DATATYPE,
class MAPPING = Containers::HashMap>
84 typedef typename contained_type::key_type
key_type;
111 container_type m_cont;
119 #ifdef CHECK_KEYED_CONTAINER 120 value_type i_object(
const key_type& k )
const 122 if ( 0 == m_cont.isDirect() ) {
123 if ( traits::checkBounds( m_random, k ) ) {
124 value_type p = *( m_random->
begin() + traits::hash( k ) );
125 if ( traits::checkKey( p, k ) ) {
131 value_type p = value_type( m_cont.object( traits::hash( k ) ) );
132 return traits::checkKey( p, k ) ? p : 0;
137 return 0 == m_cont.isDirect() ? value_type( *( m_random->
begin() + traits::hash( k ) ) )
138 : value_type( m_cont.object( traits::hash( k ) ) );
141 long i_erase( const_reference v,
const key_type& k )
144 value_type p = value_type( m_cont.erase( traits::hash( k ), v ) );
146 if ( p->parent() == this ) {
160 traits::release( p );
171 if ( par == m_obj ) {
174 traits::release( p );
187 seq_type** rptr = &m_random;
188 seq_type* sptr = &m_sequential;
189 m_cont.setup( (
void*)sptr, (
void**)rptr );
193 , m_cont(
std::move( other.m_cont ) )
194 , m_sequential(
std::move( other.m_sequential ) )
196 m_cont.setup( (
void*)&m_sequential, (
void**)&m_random );
199 other.m_cont.setup( (
void*)&other.m_sequential, (
void**)&other.m_random );
211 const CLID& clID()
const override {
return this->classID(); }
216 static CLID clid = contained_type::classID() + container_type::classID();
237 size_type numberOfObjects()
const override {
return m_sequential.
size(); }
321 iterator
begin() {
return m_sequential.
begin(); }
324 const_iterator
begin()
const {
return m_sequential.
begin(); }
326 iterator
end() {
return m_sequential.
end(); }
328 const_iterator
end()
const {
return m_sequential.
end(); }
332 const_reverse_iterator
rbegin()
const {
return m_sequential.
rbegin(); }
334 reverse_iterator
rend() {
return m_sequential.
rend(); }
336 const_reverse_iterator
rend()
const {
return m_sequential.
rend(); }
356 value_type
object(
const key_type& kval )
const {
return i_object( kval ); }
367 value_type
operator()(
const key_type& kval )
const {
return i_object( kval ); }
392 long erase(
const key_type& kval ) {
return i_erase( 0, kval ); }
446 void erase( iterator pos_start, iterator pos_stop,
bool use_temp =
false );
466 const key_type&
insert(
const value_type val,
const key_type& kval );
489 const key_type&
insert(
const value_type val );
501 template <
class DATATYPE,
class MAPPING>
509 template <
class DATATYPE,
class MAPPING>
513 m_cont.clearDirect();
514 typename seq_type::iterator i = m_sequential.begin();
515 typename seq_type::iterator
s = m_sequential.end();
516 for ( ; i !=
s; i++ ) {
517 typename seq_type::value_type v = *i;
519 if ( !v->hasKey() ) {
520 traits::setKey( v, v->key() );
523 long k0 = traits::hash( v->key() );
537 template <
class DATATYPE,
class MAPPING>
543 template <
class DATATYPE,
class MAPPING>
548 long k0 = traits::hash( kval );
549 if ( !val->hasKey() || ( traits::hash( val->key() ) == k0 ) ) {
551 if ( !val->hasKey() ) traits::setKey( val, kval );
552 traits::addRef( val );
563 template <
class DATATYPE,
class MAPPING>
568 if ( val->hasKey() ) {
570 traits::addRef( val );
576 traits::setKey( val, traits::makeKey( k0 ) );
577 traits::addRef( val );
586 template <
class DATATYPE,
class MAPPING>
590 if ( ptr )
return traits::identifier( ptr->key() );
595 template <
class DATATYPE,
class MAPPING>
599 typename seq_type::const_iterator i = m_sequential.begin();
600 typename seq_type::const_iterator
s = m_sequential.end();
603 for ( ; i !=
s; i++ ) {
611 template <
class DATATYPE,
class MAPPING>
614 return traits::identifier(
insert( dynamic_cast<typename seq_type::value_type>( pObject ) ) );
618 template <
class DATATYPE,
class MAPPING>
623 return this->erase( p1 );
640 template <
class DATATYPE,
class MAPPING>
643 bool is_start = start_pos == m_sequential.begin();
644 bool is_stop = stop_pos == m_sequential.end();
645 if ( is_start && is_stop ) {
647 }
else if ( is_start || is_stop || use_tmp ) {
649 tmp.
insert( tmp.end(), stop_pos, m_sequential.end() );
651 this->erase( m_sequential.begin(), m_sequential.end() );
660 m_cont.erase( i1, i2 );
664 #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
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.
long erase(iterator pos)
Remove/erase object (identified by iterator) from the container.
long add(ContainedObject *pObject) override
ObjectContainerBase overload: Add an object to the container.
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
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.
constexpr struct Gaudi::Functional::details::insert_t insert
Object not present in the container.
ObjectContainerBase * m_obj
template class KeyedContainer, KeyedContainer.h
long erase(const key_type &kval)
Remove/erase object (identified by key) from the container.
long remove(ContainedObject *pObject) override
ObjectContainerBase overload: Remove an object from the container.
Containers::traits< container_type, contained_type > traits
Traits class definition.
static const CLID & classID()
Retrieve class ID.
seq_type::iterator iterator
Sequential access: iterator type used in sequential 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 inserted into the container.
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.
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
KeyedContainer< DATATYPE, MAPPING > * m_obj
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
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.
long index(const ContainedObject *p) const override
ObjectContainerBase overload: Retrieve the full long integer representation of the object's key from ...
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...
FORCE_INLINE value_type i_object(const key_type &k) const
Internal function to access objects within the container.
KeyedContainer(KeyedContainer &&other)
StatusCode update() override
Reconfigure direct access to elements (Needed by POOL data loading) This function reuses the "update"...
This class is used for returning status codes from appropriate routines.
const_iterator end() const
Retrieve terminating const iterator.
seq_type::value_type value_type
Sequential access: definition of type stored in sequential container.
Object was removed, but not deleted.
ContainedObject * containedObject(long key_value) const override
ObjectContainerBase overload: Retrieve the object by reference given the long integer representation ...
seq_type::const_iterator const_iterator
Sequential access: const iterator type used in sequential container.
unsigned int CLID
Class ID definition.
constexpr static const auto SUCCESS
~KeyedContainer() override
Destructor.
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
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.
void setParent(ObjectContainerBase *value)
Update parent member.
contained_type::key_type key_type
Definition of the key type: re-use definition of contained type.
Internal functor for insertion of objects.
const_iterator begin() const
Retrieve start const iterator.
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.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Object was removed from the container and deleted.
MAPPING container_type
Definition of the implementing container type.
seq_type * m_random
Array to allow random access to objects (not exposed)
void clear()
Clear the entire content and erase the objects from the container.