The Gaudi Framework  v33r0 (d5ea422b)
KeyedTraits.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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
static long addRef(obj_type *v)
Add reference counter to object when inserted into the container.
Definition: KeyedTraits.h:111
Container traits class.
Definition: KeyedTraits.h:44
static key_type makeKey(int k)
Definition: KeyedTraits.h:90
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
Definition of the templated KeyedObject class.
Definition: KeyedObject.h:39
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent.
Object not present in the container.
Definition: KeyedTraits.h:33
template class KeyedContainer, KeyedContainer.h
static bool checkKey(obj_type *v, const key_type &k)
Check the validity of the object's key.
Definition: KeyedTraits.h:103
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:89
Key traits class.
Definition: KeyedTraits.h:47
Containers namespace.
Object was inserted into the container.
Definition: KeyedTraits.h:36
KeyedObject< key_type > obj_type
Declaration of keyed object type.
Definition: KeyedTraits.h:84
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
void setKey(const key_type &key)
Set object key.
Definition: KeyedObject.h:132
KEY key_type
Declaration of key-type.
Definition: KeyedTraits.h:82
static long hash(const key_type &key_value)
Hash function for this key.
Definition: KeyedTraits.h:94
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it's cont...
unsigned long addRef()
Add reference to object (Increase reference counter).
Definition: KeyedObject.h:115
Object was removed, but not deleted.
Definition: KeyedTraits.h:35
unsigned long release()
Release reference. If the reference count is ZERO, delete the object.
Definition: KeyedObject.h:121
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:92
T size(T... args)
STL class.
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
Cannot insert object into container.
Definition: KeyedTraits.h:37
KeyedObjectManager Class to manage keyed objects.
static long release(obj_type *v)
Release reference to object.
Definition: KeyedTraits.h:113
#define GAUDI_API
Definition: Kernel.h:81
const key_type & key() const
Retrieve Key of the object.
Definition: KeyedObject.h:82
Object was removed from the container and deleted.
Definition: KeyedTraits.h:34
static void setKey(obj_type *v, const key_type &k)
Set object key when inserted into the container.
Definition: KeyedTraits.h:96