The Gaudi Framework  master (37c0b60a)
KeyedObject< KEY > Class Template Reference

Definition of the templated KeyedObject class. More...

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

Inheritance diagram for KeyedObject< KEY >:
Collaboration diagram for KeyedObject< KEY >:

Public Types

typedef KEY key_type
 Definition of the key-type to access object. More...
 

Public Member Functions

 KeyedObject ()=default
 Standard Constructor. The object key is preset to the invalid value. More...
 
 KeyedObject (const key_type &kval)
 Standard Constructor accepting the object's key. More...
 
 ~KeyedObject () override
 Standard destructor. More...
 
const key_typekey () const
 Retrieve Key of the object. More...
 
bool hasKey () const
 Check if the object has a key assigned or not. More...
 
long index () const override
 Distance in the parent container. More...
 
StreamBufferserialize (StreamBuffer &s) const override
 Serialize the object for writing. More...
 
StreamBufferserialize (StreamBuffer &s) override
 Serialize the object for reading. More...
 
- Public Member Functions inherited from ContainedObject
virtual const CLIDclID () const
 Retrieve pointer to class identifier. More...
 
const ObjectContainerBaseparent () const
 Access to parent object. More...
 
void setParent (ObjectContainerBase *value)
 Update parent member. More...
 
virtual std::ostreamfillStream (std::ostream &s) const
 Fill the output stream (ASCII) More...
 

Protected Types

typedef Containers::key_traits< key_typetraits
 definition of the container key traits to be made friend More...
 

Protected Member Functions

unsigned long addRef ()
 Add reference to object (Increase reference counter). More...
 
unsigned long release ()
 Release reference. If the reference count is ZERO, delete the object. More...
 
void setKey (const key_type &key)
 Set object key. More...
 
- Protected Member Functions inherited from ContainedObject
 ContainedObject ()=default
 Constructors. More...
 
 ContainedObject (const ContainedObject &)
 Copy constructor and assignement: do NOT copy the parent reference... More...
 
ContainedObjectoperator= (const ContainedObject &)
 
virtual ~ContainedObject ()
 Destructor. More...
 

Protected Attributes

key_type m_key {}
 Object Key. More...
 
long m_refCount = 0
 Reference counter. More...
 
bool m_hasKey = false
 Boolean to indicate wether a key was already assigned. More...
 

Private Member Functions

 KeyedObject (const KeyedObject &copy)
 NOBODY may copy these objects. More...
 

Friends

struct GaudiDict::KeyedObjectDict< KEY >
 
struct Containers::key_traits< key_type >
 Allow the container traits to access full object properties. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ContainedObject
static const CLIDclassID ()
 

Detailed Description

template<class KEY>
class KeyedObject< KEY >

Definition of the templated KeyedObject class.

This object, which is of the basic containedObject type allows to be identified by key.

This implementation uses a reference count mechanism for insertion into multiple containers; Once the reference count is NULL, the object will automatically be deleted.

Author
M.Frank CERN/LHCb
Version
1.0

Definition at line 39 of file KeyedObject.h.

Member Typedef Documentation

◆ key_type

template<class KEY >
typedef KEY KeyedObject< KEY >::key_type

Definition of the key-type to access object.

Definition at line 44 of file KeyedObject.h.

◆ traits

template<class KEY >
typedef Containers::key_traits<key_type> KeyedObject< KEY >::traits
protected

definition of the container key traits to be made friend

Definition at line 48 of file KeyedObject.h.

Constructor & Destructor Documentation

◆ KeyedObject() [1/3]

template<class KEY >
KeyedObject< KEY >::KeyedObject ( )
default

Standard Constructor. The object key is preset to the invalid value.

◆ KeyedObject() [2/3]

template<class KEY >
KeyedObject< KEY >::KeyedObject ( const key_type kval)
inline

Standard Constructor accepting the object's key.

The key must be valid and cannot be changed later.

Definition at line 78 of file KeyedObject.h.

78 : m_key( kval ), m_refCount( 0 ), m_hasKey( true ) {}

◆ ~KeyedObject()

template<class KEY >
KeyedObject< KEY >::~KeyedObject
inlineoverride

Standard destructor.

Definition at line 105 of file KeyedObject.h.

105  {
106  ObjectContainerBase* p = const_cast<ObjectContainerBase*>( parent() );
107  if ( p ) {
108  setParent( nullptr );
109  p->remove( this );
110  }
111 }

◆ KeyedObject() [3/3]

template<class KEY >
KeyedObject< KEY >::KeyedObject ( const KeyedObject< KEY > &  copy)
inlineprivate

NOBODY may copy these objects.

Definition at line 93 of file KeyedObject.h.

93 : ContainedObject( copy ), m_refCount( 0 ), m_hasKey( true ) {}

Member Function Documentation

◆ addRef()

template<class KEY >
unsigned long KeyedObject< KEY >::addRef
inlineprotected

Add reference to object (Increase reference counter).

Definition at line 115 of file KeyedObject.h.

115  {
116  return ++m_refCount;
117 }

◆ hasKey()

template<class KEY >
bool KeyedObject< KEY >::hasKey ( ) const
inline

Check if the object has a key assigned or not.

Definition at line 84 of file KeyedObject.h.

84 { return m_hasKey; }

◆ index()

template<class KEY >
long KeyedObject< KEY >::index ( ) const
inlineoverridevirtual

Distance in the parent container.

Reimplemented from ContainedObject.

Definition at line 85 of file KeyedObject.h.

85 { return traits::identifier( m_key ); }

◆ key()

template<class KEY >
const key_type& KeyedObject< KEY >::key ( ) const
inline

Retrieve Key of the object.

Definition at line 82 of file KeyedObject.h.

82 { return m_key; }

◆ release()

template<class KEY >
unsigned long KeyedObject< KEY >::release
inlineprotected

Release reference. If the reference count is ZERO, delete the object.

Definition at line 121 of file KeyedObject.h.

121  {
122  long cnt = --m_refCount;
123  if ( cnt <= 0 ) delete this;
124  return cnt;
125 }

◆ serialize() [1/2]

template<class KEY >
StreamBuffer & KeyedObject< KEY >::serialize ( StreamBuffer s) const
inlineoverridevirtual

Serialize the object for writing.

Reimplemented from ContainedObject.

Definition at line 143 of file KeyedObject.h.

143  {
145 }

◆ serialize() [2/2]

template<class KEY >
StreamBuffer & KeyedObject< KEY >::serialize ( StreamBuffer s)
inlineoverridevirtual

Serialize the object for reading.

Reimplemented from ContainedObject.

Definition at line 149 of file KeyedObject.h.

149  {
150  long k;
152  m_key = traits::makeKey( k );
153  m_hasKey = true;
154  return s;
155 }

◆ setKey()

template<class KEY >
void KeyedObject< KEY >::setKey ( const key_type key)
inlineprotected

Set object key.

The key for consistency reasons can be set only once for the object. Any attempt to redefine the key results in an exception.

Definition at line 132 of file KeyedObject.h.

132  {
133  if ( !m_hasKey ) {
134  m_key = key;
135  m_hasKey = true;
136  return;
137  }
139 }

Friends And Related Function Documentation

◆ Containers::key_traits< key_type >

template<class KEY >
friend struct Containers::key_traits< key_type >
friend

Allow the container traits to access full object properties.

Definition at line 48 of file KeyedObject.h.

◆ GaudiDict::KeyedObjectDict< KEY >

template<class KEY >
friend struct GaudiDict::KeyedObjectDict< KEY >
friend

Definition at line 149 of file KeyedObject.h.

Member Data Documentation

◆ m_hasKey

template<class KEY >
bool KeyedObject< KEY >::m_hasKey = false
protected

Boolean to indicate wether a key was already assigned.

Definition at line 61 of file KeyedObject.h.

◆ m_key

template<class KEY >
key_type KeyedObject< KEY >::m_key {}
protected

Object Key.

Definition at line 57 of file KeyedObject.h.

◆ m_refCount

template<class KEY >
long KeyedObject< KEY >::m_refCount = 0
protected

Reference counter.

Definition at line 59 of file KeyedObject.h.


The documentation for this class was generated from the following file:
gaudirun.s
string s
Definition: gaudirun.py:346
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:57
KeyedObject::m_refCount
long m_refCount
Reference counter.
Definition: KeyedObject.h:59
ObjectContainerBase::remove
virtual long remove(ContainedObject *value)=0
Release object from the container (the pointer will be removed from the container,...
ContainedObject::ContainedObject
ContainedObject()=default
Constructors.
KeyedObject::m_hasKey
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:61
Containers::key_traits::identifier
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:92
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:63
Containers::key_traits::makeKey
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:89
ContainedObject::setParent
void setParent(ObjectContainerBase *value)
Update parent member.
Definition: ContainedObject.h:65
ObjectContainerBase
Definition: ObjectContainerBase.h:29
KeyedObject::key
const key_type & key() const
Retrieve Key of the object.
Definition: KeyedObject.h:82
Containers::cannotAssignObjectKey
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
Definition: KeyedObjectManager.cpp:79
ContainedObject::serialize
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
Definition: ContainedObject.h:70