The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
KeyedTraits.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 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
#define CHECK_KEYED_CONTAINER
14
15
#include <
GaudiKernel/Kernel.h
>
// GAUDI_API
16
#include <vector>
17
18
template
<
class
K>
19
class
KeyedObject
;
20
template
<
class
T,
class
M>
21
class
KeyedContainer
;
22
23
/*
24
Namespace for Key classes used by the Keyed Container
25
*/
26
namespace
Containers
{
27
28
// Status enumeration
29
enum
{
30
OBJ_NOT_FOUND
,
31
OBJ_DELETED
,
32
OBJ_ERASED
,
33
OBJ_INSERTED
,
34
OBJ_CANNOT_INSERT
35
};
36
38
template
<
class
CONTAINER,
class
DATATYPE>
39
struct
traits;
41
template
<
class
KEY>
42
struct
key_traits;
44
template
<
class
SETUP>
45
class
KeyedObjectManager;
46
49
GAUDI_API
void
cannotInsertToContainer
();
50
53
GAUDI_API
void
containerIsInconsistent
();
54
58
GAUDI_API
void
invalidContainerOperation
();
59
61
GAUDI_API
void
cannotAssignObjectKey
();
62
74
template
<
class
KEY>
75
struct
key_traits
{
77
typedef
KEY
key_type
;
79
typedef
KeyedObject<key_type>
obj_type
;
84
static
key_type
makeKey
(
long
k ) {
return
key_type
( k ); }
85
static
key_type
makeKey
(
int
k ) {
return
key_type
( k ); }
87
static
long
identifier
(
const
key_type
& k ) {
return
k; }
89
static
long
hash
(
const
key_type
& key_value ) {
return
key_value; }
91
static
void
setKey
(
obj_type
* v,
const
key_type
& k ) {
92
if
( v ) v->setKey( k );
93
}
94
98
static
bool
checkKey
(
obj_type
* v,
const
key_type
& k ) {
99
#ifdef CHECK_KEYED_CONTAINER
100
return
( v ) ? (
hash
( v->key() ) ==
hash
( k ) ) :
false
;
101
#else
102
return
true
;
103
#endif
104
}
105
106
static
long
addRef
(
obj_type
* v ) {
return
( v ) ? v->addRef() : 0; }
108
static
long
release
(
obj_type
* v ) {
return
( v ) ? v->release() : 0; }
109
};
110
119
template
<
class
CONTAINER,
class
DATATYPE>
120
struct
traits
:
public
key_traits
<typename DATATYPE::key_type> {
122
static
bool
checkBounds
(
const
std::vector<DATATYPE*>* cnt,
const
typename
DATATYPE::key_type& k ) {
123
#ifdef CHECK_KEYED_CONTAINER
124
return
size_t( cnt->size() ) > size_t(
traits::hash
( k ) );
125
#else
126
return
true
;
127
#endif
128
}
129
};
130
}
// namespace Containers
Kernel.h
GAUDI_API
#define GAUDI_API
Definition
Kernel.h:49
KeyedContainer
template class KeyedContainer, KeyedContainer.h
Definition
KeyedContainer.h:61
KeyedObject
Definition of the templated KeyedObject class.
Definition
KeyedObject.h:37
Containers
Definition
KeyedObjectManager.h:21
Containers::containerIsInconsistent
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent.
Definition
KeyedObjectManager.cpp:86
Containers::OBJ_DELETED
@ OBJ_DELETED
Object was removed from the container and deleted.
Definition
KeyedTraits.h:31
Containers::OBJ_INSERTED
@ OBJ_INSERTED
Object was inserted into the container.
Definition
KeyedTraits.h:33
Containers::OBJ_ERASED
@ OBJ_ERASED
Object was removed, but not deleted.
Definition
KeyedTraits.h:32
Containers::OBJ_NOT_FOUND
@ OBJ_NOT_FOUND
Object not present in the container.
Definition
KeyedTraits.h:30
Containers::OBJ_CANNOT_INSERT
@ OBJ_CANNOT_INSERT
Cannot insert object into container.
Definition
KeyedTraits.h:34
Containers::cannotAssignObjectKey
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
Definition
KeyedObjectManager.cpp:78
Containers::cannotInsertToContainer
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
Definition
KeyedObjectManager.cpp:82
Containers::invalidContainerOperation
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it's cont...
Definition
KeyedObjectManager.cpp:91
Containers::key_traits
Key traits class.
Definition
KeyedTraits.h:75
Containers::key_traits::identifier
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition
KeyedTraits.h:87
Containers::key_traits::checkKey
static bool checkKey(obj_type *v, const key_type &k)
Check the validity of the object's key.
Definition
KeyedTraits.h:98
Containers::key_traits::setKey
static void setKey(obj_type *v, const key_type &k)
Set object key when inserted into the container.
Definition
KeyedTraits.h:91
Containers::key_traits< key_type >::obj_type
KeyedObject< key_type > obj_type
Definition
KeyedTraits.h:79
Containers::key_traits::makeKey
static key_type makeKey(int k)
Definition
KeyedTraits.h:85
Containers::key_traits::release
static long release(obj_type *v)
Release reference to object.
Definition
KeyedTraits.h:108
Containers::key_traits< key_type >::key_type
key_type key_type
Definition
KeyedTraits.h:77
Containers::key_traits::hash
static long hash(const key_type &key_value)
Hash function for this key.
Definition
KeyedTraits.h:89
Containers::key_traits::makeKey
static key_type makeKey(long k)
Create key from its full integer representation.
Definition
KeyedTraits.h:84
Containers::key_traits::addRef
static long addRef(obj_type *v)
Add reference counter to object when inserted into the container.
Definition
KeyedTraits.h:106
Containers::traits
Container traits class.
Definition
KeyedTraits.h:120
Containers::traits::checkBounds
static bool checkBounds(const std::vector< DATATYPE * > *cnt, const typename DATATYPE::key_type &k)
Allow to check the access to container elements for consistency.
Definition
KeyedTraits.h:122
GaudiKernel
include
GaudiKernel
KeyedTraits.h
Generated on
for The Gaudi Framework by
1.17.0