The Gaudi Framework
master (bb4415cc)
Toggle main menu visibility
Loading...
Searching...
No Matches
KeyedObject.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#pragma once
12
13
#include <
GaudiKernel/ContainedObject.h
>
14
#include <
GaudiKernel/KeyedContainer.h
>
15
#include <
GaudiKernel/KeyedTraits.h
>
16
17
namespace
GaudiDict
{
18
template
<
class
T>
19
struct
KeyedObjectDict
;
20
}
21
36
template
<
class
KEY>
37
class
GAUDI_API
KeyedObject
:
public
ContainedObject
{
38
friend
struct
GaudiDict::KeyedObjectDict
<KEY>;
39
40
public
:
42
typedef
KEY
key_type
;
43
44
protected
:
46
using
traits
=
Containers::key_traits<key_type>
;
48
friend
struct
Containers::key_traits
<
key_type
>;
49
51
key_type
m_key
{};
53
long
m_refCount
= 0;
55
bool
m_hasKey
=
false
;
57
unsigned
long
addRef
();
59
unsigned
long
release
();
64
void
setKey
(
const
key_type
&
key
);
65
66
public
:
68
KeyedObject
() =
default
;
72
KeyedObject
(
const
key_type
& kval ) :
m_key
( kval ),
m_refCount
( 0 ),
m_hasKey
( true ) {}
74
~KeyedObject
()
override
;
76
const
key_type
&
key
()
const
{
return
m_key
; }
78
bool
hasKey
()
const
{
return
m_hasKey
; }
79
long
index
()
const override
{
return
traits::identifier
(
m_key
); }
81
StreamBuffer
&
serialize
(
StreamBuffer
& s )
const override
;
83
StreamBuffer
&
serialize
(
StreamBuffer
& s )
override
;
84
85
private
:
87
KeyedObject
(
const
KeyedObject
& copy ) :
ContainedObject
( copy ),
m_refCount
( 0 ),
m_hasKey
( true ) {}
88
};
89
90
/*
91
*
92
*
93
* Inline code for keyed KeyedObject class
94
*
95
*/
96
97
// Standard destructor.
98
template
<
class
KEY>
99
inline
KeyedObject<KEY>::~KeyedObject
() {
100
ObjectContainerBase
* p =
const_cast<
ObjectContainerBase
*
>
(
parent
() );
101
if
( p ) {
102
setParent
(
nullptr
);
103
p->
remove
(
this
);
104
}
105
}
106
107
// Add reference to object (Increase reference counter).
108
template
<
class
KEY>
109
inline
unsigned
long
KeyedObject<KEY>::addRef
() {
110
return
++
m_refCount
;
111
}
112
113
// Release reference. If the reference count is ZERO, delete the object.
114
template
<
class
KEY>
115
inline
unsigned
long
KeyedObject<KEY>::release
() {
116
long
cnt = --
m_refCount
;
117
if
( cnt <= 0 )
delete
this
;
118
return
cnt;
119
}
120
121
/* Set object key. The key for consistency reasons
122
can be set only once for the object. Any attempt to
123
redefine the key results in an exception.
124
*/
125
template
<
class
KEY>
126
inline
void
KeyedObject<KEY>::setKey
(
const
key_type
&
key
) {
127
if
( !
m_hasKey
) {
128
m_key
=
key
;
129
m_hasKey
=
true
;
130
return
;
131
}
132
Containers::cannotAssignObjectKey
();
133
}
134
135
// Serialize the object for writing
136
template
<
class
KEY>
137
inline
StreamBuffer
&
KeyedObject<KEY>::serialize
(
StreamBuffer
& s )
const
{
138
return
ContainedObject::serialize
( s ) <<
traits::identifier
(
m_key
);
139
}
140
141
// Serialize the object for reading
142
template
<
class
KEY>
143
inline
StreamBuffer
&
KeyedObject<KEY>::serialize
(
StreamBuffer
& s ) {
144
long
k;
145
ContainedObject::serialize
( s ) >> k;
146
m_key
=
traits::makeKey
( k );
147
m_hasKey
=
true
;
148
return
s;
149
}
ContainedObject.h
GAUDI_API
#define GAUDI_API
Definition
Kernel.h:49
KeyedContainer.h
KeyedTraits.h
ContainedObject::setParent
void setParent(ObjectContainerBase *value)
Update parent member.
Definition
ContainedObject.h:61
ContainedObject::ContainedObject
ContainedObject()=default
Constructors.
ContainedObject::serialize
virtual StreamBuffer & serialize(StreamBuffer &s) const
Serialize the object for writing.
Definition
ContainedObject.h:66
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition
ContainedObject.h:59
KeyedObject::addRef
unsigned long addRef()
Add reference to object (Increase reference counter).
Definition
KeyedObject.h:109
KeyedObject::KeyedObject
KeyedObject()=default
Standard Constructor. The object key is preset to the invalid value.
KeyedObject::index
long index() const override
Distance in the parent container.
Definition
KeyedObject.h:79
KeyedObject::setKey
void setKey(const key_type &key)
Set object key.
Definition
KeyedObject.h:126
KeyedObject< key_type >::m_refCount
long m_refCount
Definition
KeyedObject.h:53
KeyedObject< key_type >::key
const key_type & key() const
Definition
KeyedObject.h:76
KeyedObject< key_type >::m_hasKey
bool m_hasKey
Definition
KeyedObject.h:55
KeyedObject::KeyedObject
KeyedObject(const KeyedObject ©)
NOBODY may copy these objects.
Definition
KeyedObject.h:87
KeyedObject::serialize
StreamBuffer & serialize(StreamBuffer &s) const override
Serialize the object for writing.
Definition
KeyedObject.h:137
KeyedObject::KeyedObject
KeyedObject(const key_type &kval)
Standard Constructor accepting the object's key.
Definition
KeyedObject.h:72
KeyedObject::traits
Containers::key_traits< key_type > traits
definition of the container key traits to be made friend
Definition
KeyedObject.h:46
KeyedObject::release
unsigned long release()
Release reference. If the reference count is ZERO, delete the object.
Definition
KeyedObject.h:115
KeyedObject::~KeyedObject
~KeyedObject() override
Standard destructor.
Definition
KeyedObject.h:99
KeyedObject::serialize
StreamBuffer & serialize(StreamBuffer &s) override
Serialize the object for reading.
Definition
KeyedObject.h:143
KeyedObject::hasKey
bool hasKey() const
Check if the object has a key assigned or not.
Definition
KeyedObject.h:78
KeyedObject< key_type >::m_key
key_type m_key
Definition
KeyedObject.h:51
KeyedObject< key_type >::key_type
key_type key_type
Definition
KeyedObject.h:42
ObjectContainerBase
ObjectContainerBase is the base class for Gaudi container classes.
Definition
ObjectContainerBase.h:26
ObjectContainerBase::remove
virtual long remove(ContainedObject *value)=0
Release object from the container (the pointer will be removed from the container,...
StreamBuffer
The stream buffer is a small object collecting object data.
Definition
StreamBuffer.h:48
Containers::cannotAssignObjectKey
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
Definition
KeyedObjectManager.cpp:78
GaudiDict
Definition
KeyedContainer.h:19
Containers::key_traits
Key traits class.
Definition
KeyedTraits.h:75
Containers::key_traits< key_type >::identifier
static long identifier(const key_type &k)
Definition
KeyedTraits.h:87
Containers::key_traits< DATATYPE::key_type >::makeKey
static key_type makeKey(long k)
Definition
KeyedTraits.h:84
GaudiDict::KeyedObjectDict
Definition
KeyedObject.h:19
GaudiKernel
include
GaudiKernel
KeyedObject.h
Generated on
for The Gaudi Framework by
1.17.0