All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
KeyedTraits.h
Go to the documentation of this file.
1 // $Id: KeyedTraits.h,v 1.3 2006/12/10 20:29:17 leggett Exp $
2 #ifndef GAUDIKERNEL_KEYEDTRAITS_H
3 #define GAUDIKERNEL_KEYEDTRAITS_H
4 
5 #define CHECK_KEYED_CONTAINER
6 
7 // Include files
8 #include <vector>
9 
10 // Forward declarations
11 template <class K> class KeyedObject;
12 template <class T, class M> class KeyedContainer;
13 
14 /*
15  Namespace for Key classes used by the Keyed Container
16 */
17 namespace Containers {
18 
19  // Status enumeration
20  enum {
26  };
27 
28  // Forward declarations
29 
31  template <class CONTAINER, class DATATYPE> struct traits;
33  template <class KEY> struct key_traits;
35  template <class SETUP> class KeyedObjectManager;
36 
40 
44 
49 
52 
64  template < class KEY > struct key_traits {
66  typedef KEY key_type;
73  static key_type makeKey(long k) {return key_type(k); }
74  static key_type makeKey(int k) {return key_type(k); }
76  static long identifier(const key_type& k) {return k; }
78  static long hash(const key_type& key_value) {return key_value; }
80  static void setKey(obj_type* v, const key_type& k) {if(v)v->setKey(k); }
85  static bool checkKey(obj_type* v,const key_type& k) {
86 #ifdef CHECK_KEYED_CONTAINER
87  return (v) ? (hash(v->key())==hash(k)) : false;
88 #else
89  return true;
90 #endif
91  }
93  static long addRef(obj_type* v) { return (v) ? v->addRef() : 0; }
95  static long release(obj_type* v) { return (v) ? v->release() : 0; }
96  };
97 
106  template < class CONTAINER, class DATATYPE >
107  struct traits : public key_traits < typename DATATYPE::key_type >
108  {
110  static bool checkBounds(const std::vector<DATATYPE*>* cnt,
111  const typename DATATYPE::key_type& k) {
112 #ifdef CHECK_KEYED_CONTAINER
113  return size_t(cnt->size()) > size_t(traits::hash(k));
114 #else
115  return true;
116 #endif
117  }
118  };
119 }
120 #endif // GAUDIKERNEL_KEYEDTRAITS_H
121 
Object was inserted into the container.
Definition: KeyedTraits.h:24
static long addRef(obj_type *v)
Add reference counter to object when inserted into the container.
Definition: KeyedTraits.h:93
Container traits class.
Definition: KeyedTraits.h:31
static key_type makeKey(int k)
Definition: KeyedTraits.h:74
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:110
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's key.
Definition: KeyedTraits.h:85
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:73
Key traits class.
Definition: KeyedTraits.h:33
Object was removed from the container and deleted.
Definition: KeyedTraits.h:22
KeyedObject< key_type > obj_type
Declaration of keyed object type.
Definition: KeyedTraits.h:68
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:121
KEY key_type
Declaration of key-type.
Definition: KeyedTraits.h:66
static long hash(const key_type &key_value)
Hash function for this key.
Definition: KeyedTraits.h:78
Cannot insert object into container.
Definition: KeyedTraits.h:25
GAUDI_API void invalidContainerOperation()
Function to be called to indicate that an operation should be performed on the container or it'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:76
Object was removed, but not deleted.
Definition: KeyedTraits.h:23
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:21
static long release(obj_type *v)
Release reference to object.
Definition: KeyedTraits.h:95
#define GAUDI_API
Definition: Kernel.h:108
static void setKey(obj_type *v, const key_type &k)
Set object key when inserted into the container.
Definition: KeyedTraits.h:80