The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
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.
 

Public Member Functions

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

Protected Types

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

Protected Member Functions

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

Protected Attributes

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

Private Member Functions

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

Friends

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

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 37 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 42 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 46 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 72 of file KeyedObject.h.

72: m_key( kval ), m_refCount( 0 ), m_hasKey( true ) {}
Definition of the templated KeyedObject class.
Definition KeyedObject.h:37
long m_refCount
Reference counter.
Definition KeyedObject.h:53
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition KeyedObject.h:55
key_type m_key
Object Key.
Definition KeyedObject.h:51

◆ ~KeyedObject()

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

Standard destructor.

Definition at line 99 of file KeyedObject.h.

99 {
100 ObjectContainerBase* p = const_cast<ObjectContainerBase*>( parent() );
101 if ( p ) {
102 setParent( nullptr );
103 p->remove( this );
104 }
105}
void setParent(ObjectContainerBase *value)
Update parent member.
const ObjectContainerBase * parent() const
Access to parent object.

◆ KeyedObject() [3/3]

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

NOBODY may copy these objects.

Definition at line 87 of file KeyedObject.h.

87: ContainedObject( copy ), m_refCount( 0 ), m_hasKey( true ) {}
ContainedObject()=default
Constructors.

Member Function Documentation

◆ addRef()

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

Add reference to object (Increase reference counter).

Definition at line 109 of file KeyedObject.h.

109 {
110 return ++m_refCount;
111}

◆ hasKey()

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

Check if the object has a key assigned or not.

Definition at line 78 of file KeyedObject.h.

78{ return m_hasKey; }

◆ index()

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

Distance in the parent container.

Reimplemented from ContainedObject.

Definition at line 79 of file KeyedObject.h.

79{ return traits::identifier( m_key ); }
static long identifier(const key_type &k)
Definition KeyedTraits.h:87

◆ key()

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

Retrieve Key of the object.

Definition at line 76 of file KeyedObject.h.

76{ 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 115 of file KeyedObject.h.

115 {
116 long cnt = --m_refCount;
117 if ( cnt <= 0 ) delete this;
118 return cnt;
119}

◆ serialize() [1/2]

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

Serialize the object for writing.

Reimplemented from ContainedObject.

Reimplemented in Gaudi::TestSuite::MyTrack, and Gaudi::TestSuite::MyVertex.

Definition at line 137 of file KeyedObject.h.

137 {
139}
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.

◆ serialize() [2/2]

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

Serialize the object for reading.

Reimplemented from ContainedObject.

Reimplemented in Gaudi::TestSuite::MyTrack, and Gaudi::TestSuite::MyVertex.

Definition at line 143 of file KeyedObject.h.

143 {
144 long k;
147 m_hasKey = true;
148 return s;
149}
static key_type makeKey(long k)
Definition KeyedTraits.h:84

◆ 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 126 of file KeyedObject.h.

126 {
127 if ( !m_hasKey ) {
128 m_key = key;
129 m_hasKey = true;
130 return;
131 }
133}
const key_type & key() const
Retrieve Key of the object.
Definition KeyedObject.h:76
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.

Friends And Related Symbol 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 46 of file KeyedObject.h.

◆ GaudiDict::KeyedObjectDict< KEY >

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

Definition at line 143 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 55 of file KeyedObject.h.

◆ m_key

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

Object Key.

Definition at line 51 of file KeyedObject.h.

51{};

◆ m_refCount

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

Reference counter.

Definition at line 53 of file KeyedObject.h.


The documentation for this class was generated from the following file: