| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
KeyedObject< KEY > Class Template Reference

Definition of the templated KeyedObject class. More...

`#include <GaudiKernel/KeyedObject.h>`

Inheritance diagram for KeyedObject< KEY >:
[legend]
Collaboration diagram for KeyedObject< KEY >:
[legend]

## 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_type & | key () 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...
StreamBuffer & | serialize (StreamBuffer &s) const override
| Serialize the object for writing. More...
StreamBuffer & | serialize (StreamBuffer &s) override
| Serialize the object for reading. More...
Public Member Functions inherited from ContainedObject
virtual const CLID & | clID () const
| Retrieve pointer to class identifier. More...
const ObjectContainerBase * | parent () const
| Access to parent object. More...
void | setParent (ObjectContainerBase *value)
| Update parent member. More...
virtual std::ostream & | fillStream (std::ostream &s) const
| Fill the output stream (ASCII) More...

## Protected Types
typedef Containers::key_traits< key_type > | traits
| 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 CLID & | classID ()

## 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 ) {}
KeyedObject::m_refCount
long m_refCount
Reference counter.
Definition: KeyedObject.h:51
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:49
KeyedObject::m_hasKey
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:53
template<class KEY >

KeyedObject< KEY >::~KeyedObject | ( |  | ) |
| inline override

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 }
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:52
ContainedObject::setParent
void setParent(ObjectContainerBase *value)
Update parent member.
Definition: ContainedObject.h:54
ObjectContainerBase::remove
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
ObjectContainerBase is the base class for Gaudi container classes.
Definition: ObjectContainerBase.h:19
template<class KEY >

KeyedObject< KEY >::KeyedObject | ( | const KeyedObject< KEY > & | copy | ) |
| inline private

NOBODY may copy these objects.

Definition at line 85 of file KeyedObject.h.

85 : ContainedObject( copy ), m_refCount( 0 ), m_hasKey( true ) {}
KeyedObject::m_refCount
long m_refCount
Reference counter.
Definition: KeyedObject.h:51
ContainedObject::ContainedObject
ContainedObject()=default
Constructors.
KeyedObject::m_hasKey
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 | ( |  | ) |
| inline protected

Add reference to object (Increase reference counter).

Definition at line 108 of file KeyedObject.h.

109 {
110 return ++m_refCount;
111 }
KeyedObject::m_refCount
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; }
KeyedObject::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
| inline override virtual

Distance in the parent container.

Reimplemented from ContainedObject.

Definition at line 77 of file KeyedObject.h.

77 { return traits::identifier( m_key ); }
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:49
Containers::key_traits::identifier
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; }
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:49
template<class KEY >

unsigned long KeyedObject< KEY >::release | ( |  | ) |
| inline protected

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 }
KeyedObject::m_refCount
long m_refCount
Reference counter.
Definition: KeyedObject.h:51
template<class KEY >

StreamBuffer & KeyedObject< KEY >::serialize | ( | StreamBuffer & | s | ) | const
| inline override virtual

Serialize the object for writing.

Reimplemented from ContainedObject.

Definition at line 139 of file KeyedObject.h.

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

StreamBuffer & KeyedObject< KEY >::serialize | ( | StreamBuffer & | s | ) |
| inline override virtual

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 }
Containers::key_traits::makeKey
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:80
ContainedObject::serialize
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
Definition: ContainedObject.h:59
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:49
KeyedObject::m_hasKey
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:53
gaudirun.s
string s
Definition: gaudirun.py:253
template<class KEY >

void KeyedObject< KEY >::setKey | ( | const key_type & | key | ) |
| inline protected

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 }
134 Containers::cannotAssignObjectKey();
135 }
KeyedObject::key
const key_type & key() const
Retrieve Key of the object.
Definition: KeyedObject.h:74
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:49
Containers::cannotAssignObjectKey
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
Definition: KeyedObjectManager.cpp:74
KeyedObject::m_hasKey
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:

- GaudiKernel/GaudiKernel/KeyedObject.h