The Gaudi Framework  master (b9786168)
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
18template <class K>
19class KeyedObject;
20template <class T, class M>
21class KeyedContainer;
22
23/*
24 Namespace for Key classes used by the Keyed Container
25*/
26namespace Containers {
27
28 // Status enumeration
29 enum {
35 };
36
38 template <class CONTAINER, class DATATYPE>
39 struct traits;
41 template <class KEY>
42 struct key_traits;
44 template <class SETUP>
46
50
54
59
62
74 template <class KEY>
75 struct key_traits {
77 typedef KEY key_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
#define GAUDI_API
Definition Kernel.h:49
KeyedObjectManager()
Standard Constructor.
template class KeyedContainer, KeyedContainer.h
Definition of the templated KeyedObject class.
Definition KeyedObject.h:37
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent.
@ OBJ_DELETED
Object was removed from the container and deleted.
Definition KeyedTraits.h:31
@ OBJ_INSERTED
Object was inserted into the container.
Definition KeyedTraits.h:33
@ OBJ_ERASED
Object was removed, but not deleted.
Definition KeyedTraits.h:32
@ OBJ_NOT_FOUND
Object not present in the container.
Definition KeyedTraits.h:30
@ OBJ_CANNOT_INSERT
Cannot insert object into container.
Definition KeyedTraits.h:34
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it's cont...
Key traits class.
Definition KeyedTraits.h:75
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition KeyedTraits.h:87
static bool checkKey(obj_type *v, const key_type &k)
Check the validity of the object's key.
Definition KeyedTraits.h:98
static void setKey(obj_type *v, const key_type &k)
Set object key when inserted into the container.
Definition KeyedTraits.h:91
KeyedObject< key_type > obj_type
Definition KeyedTraits.h:79
static key_type makeKey(int k)
Definition KeyedTraits.h:85
static long release(obj_type *v)
Release reference to object.
static long hash(const key_type &key_value)
Hash function for this key.
Definition KeyedTraits.h:89
static key_type makeKey(long k)
Create key from its full integer representation.
Definition KeyedTraits.h:84
static long addRef(obj_type *v)
Add reference counter to object when inserted into the container.
Container traits class.
static bool checkBounds(const std::vector< DATATYPE * > *cnt, const typename DATATYPE::key_type &k)
Allow to check the access to container elements for consistency.