The Gaudi Framework  v30r3 (a5ef0a68)
KeyedObject< KEY > Class Template Reference

Definition of the templated KeyedObject class. More...

#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 – do NOT copy the parent reference... More...
 
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 30 of file KeyedObject.h.

Member Typedef Documentation

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

Definition of the key-type to access object.

Definition at line 36 of file KeyedObject.h.

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

Constructor & Destructor Documentation

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

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

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

70 : m_key( kval ), m_refCount( 0 ), m_hasKey( true ) {}
long m_refCount
Reference counter.
Definition: KeyedObject.h:51
key_type m_key
Object Key.
Definition: KeyedObject.h:49
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:53
template<class KEY >
KeyedObject< KEY >::~KeyedObject ( )
inlineoverride

Standard destructor.

Definition at line 97 of file KeyedObject.h.

98 {
99  ObjectContainerBase* p = const_cast<ObjectContainerBase*>( parent() );
100  if ( p ) {
101  setParent( nullptr );
102  p->remove( this );
103  }
104 }
const ObjectContainerBase * parent() const
Access to parent object.
void setParent(ObjectContainerBase *value)
Update parent member.
virtual long remove(ContainedObject *value)=0
Release object from the container (the pointer will be removed from the container, but the object itself will remain alive).
ObjectContainerBase is the base class for Gaudi container classes.
template<class KEY>
KeyedObject< KEY >::KeyedObject ( const KeyedObject< KEY > &  copy)
inlineprivate

NOBODY may copy these objects.

Definition at line 85 of file KeyedObject.h.

85 : ContainedObject( copy ), m_refCount( 0 ), m_hasKey( true ) {}
long m_refCount
Reference counter.
Definition: KeyedObject.h:51
ContainedObject()=default
Constructors.
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:53

Member Function Documentation

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

Add reference to object (Increase reference counter).

Definition at line 108 of file KeyedObject.h.

109 {
110  return ++m_refCount;
111 }
long m_refCount
Reference counter.
Definition: KeyedObject.h:51
template<class KEY>
bool KeyedObject< KEY >::hasKey ( ) const
inline

Check if the object has a key assigned or not.

Definition at line 76 of file KeyedObject.h.

76 { return m_hasKey; }
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:53
template<class KEY>
long KeyedObject< KEY >::index ( ) const
inlineoverridevirtual

Distance in the parent container.

Reimplemented from ContainedObject.

Definition at line 77 of file KeyedObject.h.

77 { return traits::identifier( m_key ); }
key_type m_key
Object Key.
Definition: KeyedObject.h:49
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:83
template<class KEY>
const key_type& KeyedObject< KEY >::key ( ) const
inline

Retrieve Key of the object.

Definition at line 74 of file KeyedObject.h.

74 { return m_key; }
key_type m_key
Object Key.
Definition: KeyedObject.h:49
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.

116 {
117  long cnt = --m_refCount;
118  if ( cnt <= 0 ) delete this;
119  return cnt;
120 }
long m_refCount
Reference counter.
Definition: KeyedObject.h:51
template<class KEY >
StreamBuffer & KeyedObject< KEY >::serialize ( StreamBuffer s) const
inlineoverridevirtual

Serialize the object for writing.

Reimplemented from ContainedObject.

Definition at line 139 of file KeyedObject.h.

140 {
142 }
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
key_type m_key
Object Key.
Definition: KeyedObject.h:49
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:83
template<class KEY >
StreamBuffer & KeyedObject< KEY >::serialize ( StreamBuffer s)
inlineoverridevirtual

Serialize the object for reading.

Reimplemented from ContainedObject.

Definition at line 146 of file KeyedObject.h.

147 {
148  long k;
149  ContainedObject::serialize( s ) >> k;
150  m_key = traits::makeKey( k );
151  m_hasKey = true;
152  return s;
153 }
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:80
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
key_type m_key
Object Key.
Definition: KeyedObject.h:49
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:53
string s
Definition: gaudirun.py:253
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 127 of file KeyedObject.h.

128 {
129  if ( !m_hasKey ) {
130  m_key = key;
131  m_hasKey = true;
132  return;
133  }
135 }
const key_type & key() const
Retrieve Key of the object.
Definition: KeyedObject.h:74
key_type m_key
Object Key.
Definition: KeyedObject.h:49
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:53

Friends And Related Function Documentation

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

Allow the container traits to access full object properties.

Definition at line 45 of file KeyedObject.h.

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

Definition at line 32 of file KeyedObject.h.

Member Data Documentation

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

Boolean to indicate wether a key was already assigned.

Definition at line 53 of file KeyedObject.h.

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

Object Key.

Definition at line 49 of file KeyedObject.h.

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

Reference counter.

Definition at line 51 of file KeyedObject.h.


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