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 <vector>
8 
9 // Forward declarations
10 template <class K> class KeyedObject;
11 template <class T, class M> class KeyedContainer;
12 
13 /*
14  Namespace for Key classes used by the Keyed Container
15 */
16 namespace Containers {
17 
18  // Status enumeration
19  enum {
25  };
26 
27  // Forward declarations
28 
30  template <class CONTAINER, class DATATYPE> struct traits;
32  template <class KEY> struct key_traits;
34  template <class SETUP> class KeyedObjectManager;
35 
39 
43 
48 
51 
63  template < class KEY > struct key_traits {
65  typedef KEY key_type;
72  static key_type makeKey(long k) {return key_type(k); }
73  static key_type makeKey(int k) {return key_type(k); }
75  static long identifier(const key_type& k) {return k; }
77  static long hash(const key_type& key_value) {return key_value; }
79  static void setKey(obj_type* v, const key_type& k) {if(v)v->setKey(k); }
84  static bool checkKey(obj_type* v,const key_type& k) {
85 #ifdef CHECK_KEYED_CONTAINER
86  return (v) ? (hash(v->key())==hash(k)) : false;
87 #else
88  return true;
89 #endif
90  }
92  static long addRef(obj_type* v) { return (v) ? v->addRef() : 0; }
94  static long release(obj_type* v) { return (v) ? v->release() : 0; }
95  };
96 
105  template < class CONTAINER, class DATATYPE >
106  struct traits : public key_traits < typename DATATYPE::key_type >
107  {
109  static bool checkBounds(const std::vector<DATATYPE*>* cnt,
110  const typename DATATYPE::key_type& k) {
111 #ifdef CHECK_KEYED_CONTAINER
112  return size_t(cnt->size()) > size_t(traits::hash(k));
113 #else
114  return true;
115 #endif
116  }
117  };
118 }
119 #endif // GAUDIKERNEL_KEYEDTRAITS_H
120 
Object was inserted into the container.
Definition: KeyedTraits.h:23
static long addRef(obj_type *v)
Add reference counter to object when inserted into the container.
Definition: KeyedTraits.h:92
Container traits class.
Definition: KeyedTraits.h:30
static key_type makeKey(int k)
Definition: KeyedTraits.h:73
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:109
Definition of the templated KeyedObject class.
Definition: KeyedObject.h:28
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent. ...
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:84
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:72
Key traits class.
Definition: KeyedTraits.h:32
Containers namespace.
Object was removed from the container and deleted.
Definition: KeyedTraits.h:21
KeyedObject< key_type > obj_type
Declaration of keyed object type.
Definition: KeyedTraits.h:67
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:119
KEY key_type
Declaration of key-type.
Definition: KeyedTraits.h:65
static long hash(const key_type &key_value)
Hash function for this key.
Definition: KeyedTraits.h:77
Cannot insert object into container.
Definition: KeyedTraits.h:24
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:69
unsigned long addRef()
Add reference to object (Increase reference counter).
Definition: KeyedObject.h:102
unsigned long release()
Release reference. If the reference count is ZERO, delete the object.
Definition: KeyedObject.h:108
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:75
Object was removed, but not deleted.
Definition: KeyedTraits.h:22
T size(T...args)
STL class.
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
KeyedObjectManager Class to manage keyed objects.
Object not present in the container.
Definition: KeyedTraits.h:20
static long release(obj_type *v)
Release reference to object.
Definition: KeyedTraits.h:94
#define GAUDI_API
Definition: Kernel.h:107
static void setKey(obj_type *v, const key_type &k)
Set object key when inserted into the container.
Definition: KeyedTraits.h:79