All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ()
 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...
 
virtual ~KeyedObject ()
 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...
 
virtual long index () const
 Distance in the parent container. More...
 
virtual StreamBufferserialize (StreamBuffer &s) const
 Serialize the object for writing. More...
 
virtual StreamBufferserialize (StreamBuffer &s)
 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::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 ()
 Constructors. More...
 
 ContainedObject (const ContainedObject &)
 Copy constructor. More...
 
virtual ~ContainedObject ()
 Destructor. More...
 

Protected Attributes

key_type m_key
 Object Key; It's initial value is not determined. More...
 
long m_refCount
 Reference counter. More...
 
bool m_hasKey
 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 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 ( )
inline

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

Definition at line 61 of file KeyedObject.h.

61 : m_key(), m_refCount(0), m_hasKey(false) { }
long m_refCount
Reference counter.
Definition: KeyedObject.h:47
key_type m_key
Object Key; It's initial value is not determined.
Definition: KeyedObject.h:45
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:49
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) { }
long m_refCount
Reference counter.
Definition: KeyedObject.h:47
key_type m_key
Object Key; It's initial value is not determined.
Definition: KeyedObject.h:45
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:49
template<class KEY >
KeyedObject< KEY >::~KeyedObject ( )
inlinevirtual

Standard destructor.

Definition at line 91 of file KeyedObject.h.

92 {
93  ObjectContainerBase* p = const_cast<ObjectContainerBase*>(parent());
94  if ( p ) {
95  setParent(0);
96  p->remove(this);
97  }
98 }
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 79 of file KeyedObject.h.

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

Member Function Documentation

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

Add reference to object (Increase reference counter).

Definition at line 102 of file KeyedObject.h.

102  {
103  return ++m_refCount;
104 }
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; }
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:49
template<class KEY>
virtual long KeyedObject< KEY >::index ( ) const
inlinevirtual

Distance in the parent container.

Reimplemented from ContainedObject.

Definition at line 72 of file KeyedObject.h.

72 { return traits::identifier(m_key); }
key_type m_key
Object Key; It's initial value is not determined.
Definition: KeyedObject.h:45
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:76
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; }
key_type m_key
Object Key; It's initial value is not determined.
Definition: KeyedObject.h:45
template<class KEY >
unsigned long KeyedObject< KEY >::release ( )
inlineprotected

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 ) {
111  delete this;
112  }
113  return cnt;
114 }
long m_refCount
Reference counter.
Definition: KeyedObject.h:47
template<class KEY >
StreamBuffer & KeyedObject< KEY >::serialize ( StreamBuffer s) const
inlinevirtual

Serialize the object for writing.

Reimplemented from ContainedObject.

Reimplemented in MyVertex.

Definition at line 132 of file KeyedObject.h.

132  {
134 }
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
key_type m_key
Object Key; It's initial value is not determined.
Definition: KeyedObject.h:45
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:76
template<class KEY >
StreamBuffer & KeyedObject< KEY >::serialize ( StreamBuffer s)
inlinevirtual

Serialize the object for reading.

Reimplemented from ContainedObject.

Reimplemented in MyVertex.

Definition at line 138 of file KeyedObject.h.

138  {
139  long k;
141  m_key = traits::makeKey(k);
142  m_hasKey = true;
143  return s;
144 }
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:73
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
key_type m_key
Object Key; It's initial value is not determined.
Definition: KeyedObject.h:45
bool m_hasKey
Boolean to indicate wether a key was already assigned.
Definition: KeyedObject.h:49
string s
Definition: gaudirun.py:210
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 121 of file KeyedObject.h.

121  {
122  if ( !m_hasKey ) {
123  m_key = key;
124  m_hasKey = true;
125  return;
126  }
128 }
const key_type & key() const
Retrieve Key of the object.
Definition: KeyedObject.h:69
key_type m_key
Object Key; It's initial value is not determined.
Definition: KeyedObject.h:45
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: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
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; It's initial value is not determined.

Definition at line 45 of file KeyedObject.h.

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

Reference counter.

Definition at line 47 of file KeyedObject.h.


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