| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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 28 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 32 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 36 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 65 of file KeyedObject.h.

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

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

Standard destructor.

Definition at line 91 of file KeyedObject.h.

92 {
93 ObjectContainerBase* p = const_cast<ObjectContainerBase*>(parent());
94 if ( p ) {
95 setParent(nullptr);
96 p->remove(this);
97 }
98 }
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:49
ContainedObject::setParent
void setParent(ObjectContainerBase *value)
Update parent member.
Definition: ContainedObject.h:51
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 79 of file KeyedObject.h.

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

## Member Function Documentation

template<class KEY >

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

Add reference to object (Increase reference counter).

Definition at line 102 of file KeyedObject.h.

102 {
103 return ++m_refCount;
104 }
KeyedObject::m_refCount
long m_refCount
Reference counter.
Definition: KeyedObject.h:47
template<class KEY >

bool KeyedObject< KEY >::hasKey | ( |  | ) | const
| inline

Check if the object has a key assigned or not.

Definition at line 71 of file KeyedObject.h.

71 { return m_hasKey; }
KeyedObject::m_hasKey
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:49
template<class KEY >

long KeyedObject< KEY >::index | ( |  | ) | const
| inline override virtual

Distance in the parent container.

Reimplemented from ContainedObject.

Definition at line 72 of file KeyedObject.h.

72 { return traits::identifier(m_key); }
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:45
Containers::key_traits::identifier
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:75
template<class KEY >

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

Retrieve Key of the object.

Definition at line 69 of file KeyedObject.h.

69 { return m_key; }
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:45
template<class KEY >

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

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

Definition at line 108 of file KeyedObject.h.

108 {
109 long cnt = --m_refCount;
110 if ( cnt <= 0 ) delete this;
111 return cnt;
112 }
KeyedObject::m_refCount
long m_refCount
Reference counter.
Definition: KeyedObject.h:47
template<class KEY >

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

Serialize the object for writing.

Reimplemented from ContainedObject.

Definition at line 130 of file KeyedObject.h.

130 {
131 return ContainedObject::serialize(s) << traits::identifier(m_key);
132 }
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:45
Containers::key_traits::identifier
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:75
template<class KEY >

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

Serialize the object for reading.

Reimplemented from ContainedObject.

Definition at line 136 of file KeyedObject.h.

136 {
137 long k;
138 ContainedObject::serialize(s) >> k;
139 m_key = traits::makeKey(k);
140 m_hasKey = true;
141 return s;
142 }
Containers::key_traits::makeKey
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:72
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:45
KeyedObject::m_hasKey
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:49
gaudirun.s
string s
Definition: gaudirun.py:245
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 119 of file KeyedObject.h.

119 {
120 if ( !m_hasKey ) {
121 m_key = key;
122 m_hasKey = true;
123 return;
124 }
125 Containers::cannotAssignObjectKey();
126 }
KeyedObject::key
const key_type & key() const
Retrieve Key of the object.
Definition: KeyedObject.h:69
KeyedObject::m_key
key_type m_key
Object Key.
Definition: KeyedObject.h:45
Containers::cannotAssignObjectKey
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
Definition: KeyedObjectManager.cpp:72
KeyedObject::m_hasKey
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:49

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

template<class KEY >

friend struct GaudiDict::KeyedObjectDict< KEY >
| friend

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

template<class KEY >

key_type KeyedObject< KEY >::m_key {}
| protected

Object Key.

Definition at line 45 of file KeyedObject.h.

template<class KEY >

long KeyedObject< KEY >::m_refCount = 0
| protected

Reference counter.

Definition at line 47 of file KeyedObject.h.

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

- GaudiKernel/GaudiKernel/KeyedObject.h