The Gaudi Framework  master (37c0b60a)
KeyedTraits.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 #ifndef GAUDIKERNEL_KEYEDTRAITS_H
12 #define GAUDIKERNEL_KEYEDTRAITS_H
13 
14 #define CHECK_KEYED_CONTAINER
15 
16 // Include files
17 #include <GaudiKernel/Kernel.h> // GAUDI_API
18 #include <vector>
19 
20 // Forward declarations
21 template <class K>
22 class KeyedObject;
23 template <class T, class M>
24 class KeyedContainer;
25 
26 /*
27  Namespace for Key classes used by the Keyed Container
28 */
29 namespace Containers {
30 
31  // Status enumeration
32  enum {
38  };
39 
40  // Forward declarations
41 
43  template <class CONTAINER, class DATATYPE>
44  struct traits;
46  template <class KEY>
47  struct key_traits;
49  template <class SETUP>
50  class KeyedObjectManager;
51 
55 
59 
64 
67 
79  template <class KEY>
80  struct key_traits {
82  typedef KEY key_type;
89  static key_type makeKey( long k ) { return key_type( k ); }
90  static key_type makeKey( int k ) { return key_type( k ); }
92  static long identifier( const key_type& k ) { return k; }
94  static long hash( const key_type& key_value ) { return key_value; }
96  static void setKey( obj_type* v, const key_type& k ) {
97  if ( v ) v->setKey( k );
98  }
103  static bool checkKey( obj_type* v, const key_type& k ) {
104 #ifdef CHECK_KEYED_CONTAINER
105  return ( v ) ? ( hash( v->key() ) == hash( k ) ) : false;
106 #else
107  return true;
108 #endif
109  }
111  static long addRef( obj_type* v ) { return ( v ) ? v->addRef() : 0; }
113  static long release( obj_type* v ) { return ( v ) ? v->release() : 0; }
114  };
115 
124  template <class CONTAINER, class DATATYPE>
125  struct traits : public key_traits<typename DATATYPE::key_type> {
127  static bool checkBounds( const std::vector<DATATYPE*>* cnt, const typename DATATYPE::key_type& k ) {
128 #ifdef CHECK_KEYED_CONTAINER
129  return size_t( cnt->size() ) > size_t( traits::hash( k ) );
130 #else
131  return true;
132 #endif
133  }
134  };
135 } // namespace Containers
136 #endif // GAUDIKERNEL_KEYEDTRAITS_H
Containers::OBJ_ERASED
@ OBJ_ERASED
Object was removed, but not deleted
Definition: KeyedTraits.h:35
Containers::cannotInsertToContainer
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
Definition: KeyedObjectManager.cpp:83
Containers::KeyedObjectManager
KeyedObjectManager Class to manage keyed objects.
Definition: KeyedObjectManager.h:55
Containers::OBJ_INSERTED
@ OBJ_INSERTED
Object was inserted into the container.
Definition: KeyedTraits.h:36
Containers::key_traits::obj_type
KeyedObject< key_type > obj_type
Declaration of keyed object type.
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:111
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:127
std::vector
STL class.
std::vector::size
T size(T... args)
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:103
Containers
Containers namespace.
Definition: KeyedObjectManager.h:28
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:92
Containers::OBJ_CANNOT_INSERT
@ OBJ_CANNOT_INSERT
Cannot insert object into container.
Definition: KeyedTraits.h:37
Containers::key_traits::makeKey
static key_type makeKey(int k)
Definition: KeyedTraits.h:90
Containers::key_traits
Key traits class.
Definition: KeyedTraits.h:47
Containers::key_traits::identifier
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:92
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:96
Containers::OBJ_DELETED
@ OBJ_DELETED
Object was removed from the container and deleted.
Definition: KeyedTraits.h:34
Containers::OBJ_NOT_FOUND
@ OBJ_NOT_FOUND
Object not present in the container.
Definition: KeyedTraits.h:33
KeyedContainer
template class KeyedContainer, KeyedContainer.h
Definition: KeyedContainer.h:74
KeyedObject
Definition of the templated KeyedObject class.
Definition: KeyedObject.h:39
Containers::key_traits::release
static long release(obj_type *v)
Release reference to object.
Definition: KeyedTraits.h:113
Containers::key_traits::makeKey
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:89
Kernel.h
Containers::traits
Container traits class.
Definition: KeyedTraits.h:44
Containers::key_traits::key_type
KEY key_type
Declaration of key-type.
Definition: KeyedTraits.h:82
Properties.v
v
Definition: Properties.py:122
Containers::cannotAssignObjectKey
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
Definition: KeyedObjectManager.cpp:79
Containers::containerIsInconsistent
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent.
Definition: KeyedObjectManager.cpp:87
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Containers::key_traits::hash
static long hash(const key_type &key_value)
Hash function for this key.
Definition: KeyedTraits.h:94