Gaudi Framework, version v23r6
Home
Generated: Wed Jan 30 2013
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
GaudiKernel
GaudiKernel
KeyedObject.h
Go to the documentation of this file.
1
#ifndef GAUDIKERNEL_KEYEDOBJECT_H
2
#define GAUDIKERNEL_KEYEDOBJECT_H
3
4
namespace
GaudiDict {
5
template
<
class
T>
struct
KeyedObjectDict
;
6
}
7
8
// Framework include files
9
#include "
GaudiKernel/ContainedObject.h
"
10
#include "
GaudiKernel/KeyedTraits.h
"
11
#include "
GaudiKernel/KeyedContainer.h
"
12
27
template
<
class
KEY >
28
class
GAUDI_API
KeyedObject
:
public
ContainedObject
{
29
friend
struct
GaudiDict::KeyedObjectDict<KEY>;
30
public
:
32
typedef
KEY
key_type
;
33
34
protected
:
36
typedef
typename
Containers::key_traits<key_type>
traits
;
38
//#ifdef _WIN32
39
// friend traits;
40
//#else
41
friend
struct
Containers::key_traits
<
key_type
>;
42
//#endif
43
45
key_type
m_key
;
47
long
m_refCount
;
49
bool
m_hasKey
;
51
unsigned
long
addRef
();
53
unsigned
long
release
();
58
void
setKey
(
const
key_type
& key);
59
public
:
61
KeyedObject
(): m_key(), m_refCount(0), m_hasKey(false) { }
65
KeyedObject
(
const
key_type
& kval):m_key(kval),m_refCount(0),m_hasKey(true) { }
67
virtual
~
KeyedObject
();
69
const
key_type
&
key
()
const
{
return
m_key; }
71
bool
hasKey
()
const
{
return
m_hasKey; }
72
virtual
long
index
()
const
{
return
traits::identifier
(m_key); }
74
virtual
StreamBuffer
&
serialize
(
StreamBuffer
&
s
)
const
;
76
virtual
StreamBuffer
&
serialize
(
StreamBuffer
&
s
);
77
private
:
79
KeyedObject
(
const
KeyedObject
& copy) :
ContainedObject
(copy) { }
80
};
81
82
/*
83
*
84
*
85
* Inline code for keyed KeyedObject class
86
*
87
*/
88
89
// Standard destructor.
90
template
<
class
KEY>
inline
91
KeyedObject<KEY>::~KeyedObject
()
92
{
93
ObjectContainerBase
* p =
const_cast<
ObjectContainerBase
*
>
(parent());
94
if
( p ) {
95
setParent(0);
96
p->
remove
(
this
);
97
}
98
}
99
100
// Add reference to object (Increase reference counter).
101
template
<
class
KEY>
inline
102
unsigned
long
KeyedObject<KEY>::addRef
() {
103
return
++m_refCount;
104
}
105
106
// Release reference. If the reference count is ZERO, delete the object.
107
template
<
class
KEY>
inline
108
unsigned
long
KeyedObject<KEY>::release
() {
109
long
cnt = --m_refCount;
110
if
( cnt <= 0 ) {
111
delete
this
;
112
}
113
return
cnt;
114
}
115
116
/* Set object key. The key for consistency reasons
117
can be set only once for the object. Any attempt to
118
redefine the key results in an exception.
119
*/
120
template
<
class
KEY>
inline
121
void
KeyedObject<KEY>::setKey
(
const
key_type
& key) {
122
if
( !m_hasKey ) {
123
m_key = key;
124
m_hasKey =
true
;
125
return
;
126
}
127
Containers::cannotAssignObjectKey
();
128
}
129
130
// Serialize the object for writing
131
template
<
class
KEY>
inline
132
StreamBuffer
&
KeyedObject<KEY>::serialize
(
StreamBuffer
&
s
)
const
{
133
return
ContainedObject::serialize
(s) <<
traits::identifier
(m_key);
134
}
135
136
// Serialize the object for reading
137
template
<
class
KEY>
inline
138
StreamBuffer
&
KeyedObject<KEY>::serialize
(
StreamBuffer
&
s
) {
139
long
k;
140
ContainedObject::serialize
(s) >> k;
141
m_key =
traits::makeKey
(k);
142
m_hasKey =
true
;
143
return
s
;
144
}
145
#endif // GAUDIKERNEL_KEYEDOBJECT_H
Generated at Wed Jan 30 2013 17:13:39 for Gaudi Framework, version v23r6 by
Doxygen
version 1.8.2 written by
Dimitri van Heesch
, © 1997-2004