Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
KeyedTraits.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_KEYEDTRAITS_H
2 #define GAUDIKERNEL_KEYEDTRAITS_H
3 
4 #define CHECK_KEYED_CONTAINER
5 
6 // Include files
7 #include "GaudiKernel/Kernel.h" // GAUDI_API
8 #include <vector>
9 
10 // Forward declarations
11 template <class K>
12 class KeyedObject;
13 template <class T, class M>
14 class KeyedContainer;
15 
16 /*
17  Namespace for Key classes used by the Keyed Container
18 */
19 namespace Containers {
20 
21  // Status enumeration
22  enum {
28  };
29 
30  // Forward declarations
31 
33  template <class CONTAINER, class DATATYPE>
34  struct traits;
36  template <class KEY>
37  struct key_traits;
39  template <class SETUP>
40  class KeyedObjectManager;
41 
45 
49 
54 
57 
69  template <class KEY>
70  struct key_traits {
72  typedef KEY key_type;
79  static key_type makeKey( long k ) { return key_type( k ); }
80  static key_type makeKey( int k ) { return key_type( k ); }
82  static long identifier( const key_type& k ) { return k; }
84  static long hash( const key_type& key_value ) { return key_value; }
86  static void setKey( obj_type* v, const key_type& k ) {
87  if ( v ) v->setKey( k );
88  }
93  static bool checkKey( obj_type* v, const key_type& k ) {
94 #ifdef CHECK_KEYED_CONTAINER
95  return ( v ) ? ( hash( v->key() ) == hash( k ) ) : false;
96 #else
97  return true;
98 #endif
99  }
101  static long addRef( obj_type* v ) { return ( v ) ? v->addRef() : 0; }
103  static long release( obj_type* v ) { return ( v ) ? v->release() : 0; }
104  };
105 
114  template <class CONTAINER, class DATATYPE>
115  struct traits : public key_traits<typename DATATYPE::key_type> {
117  static bool checkBounds( const std::vector<DATATYPE*>* cnt, const typename DATATYPE::key_type& k ) {
118 #ifdef CHECK_KEYED_CONTAINER
119  return size_t( cnt->size() ) > size_t( traits::hash( k ) );
120 #else
121  return true;
122 #endif
123  }
124  };
125 } // namespace Containers
126 #endif // GAUDIKERNEL_KEYEDTRAITS_H
static long addRef(obj_type *v)
Add reference counter to object when inserted into the container.
Definition: KeyedTraits.h:101
Container traits class.
Definition: KeyedTraits.h:34
static key_type makeKey(int k)
Definition: KeyedTraits.h:80
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:117
Definition of the templated KeyedObject class.
Definition: KeyedObject.h:29
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:23
template class KeyedContainer, KeyedContainer.h
static bool checkKey(obj_type *v, const key_type &k)
Check the validity of the object&#39;s key.
Definition: KeyedTraits.h:93
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:79
Key traits class.
Definition: KeyedTraits.h:37
Containers namespace.
Object was inserted into the container.
Definition: KeyedTraits.h:26
KeyedObject< key_type > obj_type
Declaration of keyed object type.
Definition: KeyedTraits.h:74
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:122
KEY key_type
Declaration of key-type.
Definition: KeyedTraits.h:72
static long hash(const key_type &key_value)
Hash function for this key.
Definition: KeyedTraits.h:84
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it&#39;s cont...
const key_type & key() const
Retrieve Key of the object.
Definition: KeyedObject.h:72
unsigned long addRef()
Add reference to object (Increase reference counter).
Definition: KeyedObject.h:105
Object was removed, but not deleted.
Definition: KeyedTraits.h:25
unsigned long release()
Release reference. If the reference count is ZERO, delete the object.
Definition: KeyedObject.h:111
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:82
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:27
KeyedObjectManager Class to manage keyed objects.
static long release(obj_type *v)
Release reference to object.
Definition: KeyedTraits.h:103
#define GAUDI_API
Definition: Kernel.h:71
Object was removed from the container and deleted.
Definition: KeyedTraits.h:24
static void setKey(obj_type *v, const key_type &k)
Set object key when inserted into the container.
Definition: KeyedTraits.h:86