1 #ifndef GAUDIKERNEL_KEYEDCONTAINER_H 2 #define GAUDIKERNEL_KEYEDCONTAINER_H 22 # define FORCE_INLINE __forceinline 24 # define FORCE_INLINE inline 63 template <
class DATATYPE,
class MAPPING = Containers::HashMap>
82 typedef typename contained_type::key_type
key_type;
117 #ifdef CHECK_KEYED_CONTAINER 119 if ( 0 == m_cont.isDirect() ) {
120 if ( traits::checkBounds( m_random, k ) ) {
122 if ( traits::checkKey( p, k ) ) {
return p; }
127 return traits::checkKey( p, k ) ? p : 0;
131 return 0 == m_cont.isDirect() ?
value_type( *( m_random->
begin() + traits::hash( k ) ) )
132 :
value_type( m_cont.object( traits::hash( k ) ) );
135 long i_erase( const_reference v,
const key_type& k ) {
137 value_type p = value_type( m_cont.erase( traits::hash( k ), v ) );
139 if ( p->parent() == this ) { p->setParent( 0 ); }
150 traits::release( p );
160 if (
par == m_obj ) { p->setParent( 0 ); }
161 traits::release( p );
173 seq_type** rptr = &m_random;
174 seq_type* sptr = &m_sequential;
175 m_cont.setup( (
void*)sptr, (
void**)rptr );
179 , m_cont(
std::move( other.m_cont ) )
180 , m_sequential(
std::move( other.m_sequential ) ) {
181 m_cont.setup( (
void*)&m_sequential, (
void**)&m_random );
184 other.m_cont.setup( (
void*)&other.m_sequential, (
void**)&other.m_random );
200 static CLID clid = contained_type::classID() + container_type::classID();
255 return i_object( traits::makeKey( key_value ) );
274 size_type
size()
const {
return m_sequential.
size(); }
308 iterator
begin() {
return m_sequential.
begin(); }
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 );
488 template <
class DATATYPE,
class MAPPING>
495 template <
class DATATYPE,
class MAPPING>
498 m_cont.clearDirect();
499 typename seq_type::iterator i = m_sequential.
begin();
500 typename seq_type::iterator
s = m_sequential.
end();
501 for ( ; i !=
s; i++ ) {
502 typename seq_type::value_type v = *i;
504 if ( !v->hasKey() ) {
505 traits::setKey( v, v->key() );
508 long k0 = traits::hash( v->key() );
519 template <
class DATATYPE,
class MAPPING>
524 template <
class DATATYPE,
class MAPPING>
528 long k0 = traits::hash( kval );
529 if ( !val->hasKey() || ( traits::hash( val->key() ) == k0 ) ) {
531 if ( !val->hasKey() ) traits::setKey( val, kval );
532 traits::addRef( val );
543 template <
class DATATYPE,
class MAPPING>
547 if ( val->hasKey() ) {
549 traits::addRef( val );
555 traits::setKey( val, traits::makeKey( k0 ) );
556 traits::addRef( val );
565 template <
class DATATYPE,
class MAPPING>
567 const contained_type* ptr = dynamic_cast<const contained_type*>( p );
568 if ( ptr )
return traits::identifier( ptr->key() );
573 template <
class DATATYPE,
class MAPPING>
576 typename seq_type::const_iterator i = m_sequential.
begin();
577 typename seq_type::const_iterator
s = m_sequential.
end();
580 for ( ; i !=
s; i++ ) {
588 template <
class DATATYPE,
class MAPPING>
590 return traits::identifier(
insert( dynamic_cast<typename seq_type::value_type>( pObject ) ) );
594 template <
class DATATYPE,
class MAPPING>
598 return this->erase( p1 );
613 template <
class DATATYPE,
class MAPPING>
615 bool is_start = start_pos == m_sequential.
begin();
616 bool is_stop = stop_pos == m_sequential.
end();
617 if ( is_start && is_stop ) {
619 }
else if ( is_start || is_stop || use_tmp ) {
621 tmp.
insert( tmp.end(), stop_pos, m_sequential.
end() );
623 this->erase( m_sequential.
begin(), m_sequential.
end() );
632 m_cont.erase( i1, i2 );
636 #endif // GAUDIKERNEL_KEYEDCONTAINER_H
constexpr auto size(const T &, Args &&...) noexcept
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.
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.
static const CLID & classID()
Retrieve reference to class definition structure (static access)
const_reverse_iterator rend() const
const reverse_iterator pointing to the end of the reversed container
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
ContainedObject const * containedObject(long key_value) const override
Pointer to an object of a given distance.
FORCE_INLINE value_type i_object(const key_type &k) const
Internal function to access objects within 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.
virtual size_type numberOfObjects() const =0
Number of objects in the container.
ContainedObject * containedObject(long key_value) override
ObjectContainerBase overload: Retrieve the object by reference given the long integer representation ...
Object not present in the container.
ObjectContainerBase * m_obj
constexpr static const auto SUCCESS
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.
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.
const_reverse_iterator rbegin() const
const reverse_iterator returns the beginning of the reversed container
Object was inserted into the container.
const key_type & insert(const value_type val, const key_type &kval)
Insert entry to the container with a valid key.
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_iterator begin() const
Retrieve start const iterator.
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...
KeyedContainer(KeyedContainer &&other)
virtual const std::vector< const ContainedObject * > * containedObjects() const
Retrieve the full content of the object container by reference.
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.
value_type operator()(const key_type &kval) const
STL algorithms support for object access.
seq_type::value_type value_type
Sequential access: definition of type stored in sequential container.
Object was removed, but not deleted.
seq_type::const_iterator const_iterator
Sequential access: const iterator type used in sequential container.
unsigned int CLID
Class ID definition.
~KeyedContainer() override
Destructor.
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
value_type object(const key_type &kval) const
Object access by key.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
long erase(const value_type val)
Remove/erase object (identified by pointer value) from the container.
_InsertRelease(KeyedContainer< DATATYPE, MAPPING > *p)
bool empty() const
For consistency with STL: check if container is empty.
iterator end()
Retrieve terminating iterator.
constexpr struct ranges::Gaudi::Functional::details::insert_t insert
virtual long index(const ContainedObject *obj) const =0
Distance of a given object from the beginning of its container.
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.
virtual long remove(ContainedObject *value)=0
Release object from the container (the pointer will be removed from the container,...
const ObjectContainerBase * parent() const
Access to parent object.
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)
long index(const ContainedObject *p) const override
ObjectContainerBase overload: Retrieve the full long integer representation of the object's key from ...
Object was removed from the container and deleted.
const_iterator end() const
Retrieve terminating const iterator.
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.