| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
22 // Status enumeration
23 enum {
24 OBJ_NOT_FOUND,
25 OBJ_DELETED,
26 OBJ_ERASED,
27 OBJ_INSERTED,
28 OBJ_CANNOT_INSERT
29 };
30
31 // Forward declarations
32
34 template <class CONTAINER, class DATATYPE>
35 struct traits;
37 template <class KEY>
38 struct key_traits;
40 template <class SETUP>
41 class KeyedObjectManager;
42
45 GAUDI_API void cannotInsertToContainer();
46
49 GAUDI_API void containerIsInconsistent();
50
54 GAUDI_API void invalidContainerOperation();
55
57 GAUDI_API void cannotAssignObjectKey();
58
70 template <class KEY>
71 struct key_traits {
73 typedef KEY key_type;
75 typedef KeyedObject<key_type> obj_type;
80 static key_type makeKey( long k ) { return key_type( k ); }
81 static key_type makeKey( int k ) { return key_type( k ); }
83 static long identifier( const key_type& k ) { return k; }
85 static long hash( const key_type& key_value ) { return key_value; }
87 static void setKey( obj_type* v, const key_type& k )
88 {
89 if ( v ) v->setKey( k );
90 }
95 static bool checkKey( obj_type* v, const key_type& k )
96 {
97 #ifdef CHECK_KEYED_CONTAINER
98 return ( v ) ? ( hash( v->key() ) == hash( k ) ) : false;
99 #else
100 return true;
101 #endif
102 }
104 static long addRef( obj_type* v ) { return ( v ) ? v->addRef() : 0; }
106 static long release( obj_type* v ) { return ( v ) ? v->release() : 0; }
107 };
108
117 template <class CONTAINER, class DATATYPE>
118 struct traits : public key_traits<typename DATATYPE::key_type> {
120 static bool checkBounds( const std::vector<DATATYPE*>* cnt, const typename DATATYPE::key_type& k )
121 {
122 #ifdef CHECK_KEYED_CONTAINER
123 return size_t( cnt->size() ) > size_t( traits::hash( k ) );
124 #else
125 return true;
126 #endif
127 }
128 };
129 }
130 #endif // GAUDIKERNEL_KEYEDTRAITS_H
Containers::OBJ_INSERTED
Object was inserted into the container.
Definition: KeyedTraits.h:27
Kernel.h
Containers::key_traits::addRef
static long addRef(obj_type *v)
Add reference counter to object when inserted into the container.
Definition: KeyedTraits.h:104
Containers::traits
Container traits class.
Definition: KeyedTraits.h:35
Containers::key_traits::makeKey
static key_type makeKey(int k)
Definition: KeyedTraits.h:81
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:120
KeyedObject
Definition of the templated KeyedObject class.
Definition: KeyedObject.h:30
Containers::containerIsInconsistent
GAUDI_API void containerIsInconsistent()
Function to be called to indicate that the container is found to be inconsistent. ...
Definition: KeyedObjectManager.cpp:83
KeyedContainer
template class KeyedContainer, KeyedContainer.h
Definition: KeyedContainer.h:65
Containers::key_traits::checkKey
static bool checkKey(obj_type *v, const key_type &k)
Check the validity of the object&#39;s key.
Definition: KeyedTraits.h:95
Containers::key_traits::makeKey
static key_type makeKey(long k)
Create key from its full integer representation.
Definition: KeyedTraits.h:80
Containers::key_traits
Key traits class.
Definition: KeyedTraits.h:38
Containers
Containers namespace.
Definition: KeyedObjectManager.h:18
Containers::OBJ_DELETED
Object was removed from the container and deleted.
Definition: KeyedTraits.h:25
Containers::key_traits::obj_type
KeyedObject< key_type > obj_type
Declaration of keyed object type.
Definition: KeyedTraits.h:75
Containers::cannotInsertToContainer
GAUDI_API void cannotInsertToContainer()
Function to be called to indicate that an object cannot be inserted to the container.
Definition: KeyedObjectManager.cpp:78
KeyedObject::setKey
void setKey(const key_type &key)
Set object key.
Definition: KeyedObject.h:127
Containers::key_traits::key_type
KEY key_type
Declaration of key-type.
Definition: KeyedTraits.h:73
Containers::key_traits::hash
static long hash(const key_type &key_value)
Hash function for this key.
Definition: KeyedTraits.h:85
Containers::OBJ_CANNOT_INSERT
Cannot insert object into container.
Definition: KeyedTraits.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&#39;s cont...
Definition: KeyedObjectManager.cpp:88
KeyedObject::key
const key_type & key() const
Retrieve Key of the object.
Definition: KeyedObject.h:74
KeyedObject::addRef
unsigned long addRef()
Add reference to object (Increase reference counter).
Definition: KeyedObject.h:108
KeyedObject::release
unsigned long release()
Release reference. If the reference count is ZERO, delete the object.
Definition: KeyedObject.h:115
Containers::key_traits::identifier
static long identifier(const key_type &k)
Full unhashed key identifier.
Definition: KeyedTraits.h:83
Containers::OBJ_ERASED
Object was removed, but not deleted.
Definition: KeyedTraits.h:26
std::vector::size
T size(T...args)
std::vector
STL class.
Containers::cannotAssignObjectKey
GAUDI_API void cannotAssignObjectKey()
Function to be called when an object key cannot be assigned.
Definition: KeyedObjectManager.cpp:74
Containers::KeyedObjectManager
KeyedObjectManager Class to manage keyed objects.
Definition: KeyedObjectManager.h:46
Containers::OBJ_NOT_FOUND
Object not present in the container.
Definition: KeyedTraits.h:24
Containers::key_traits::release
static long release(obj_type *v)
Release reference to object.
Definition: KeyedTraits.h:106
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
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:87