CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HCMethods.h
Go to the documentation of this file.
1 #ifndef Framework_HCMethods_h
2 #define Framework_HCMethods_h
3 // -*- C++ -*-
4 //
5 // Package: HeteroContainer
6 // Module: HCMethods
7 //
8 // Description: Templated methods to be used to 'construct' a
9 // heterogenous container
10 //
11 // Usage:
12 // <usage>
13 //
14 // Author: Chris D. Jones
15 // Created: Sun Mar 27 15:58:05 EDT 2005
16 //
17 
18 // system include files
19 
21 #include "boost/type_traits/remove_const.hpp"
22 // user include files
23 
24 namespace edm {
25  namespace eventsetup {
26  namespace heterocontainer {
27  template< class Type, class Key, class IdTag >
28  inline Key makeKey(const IdTag& iIdTag) {
29  HCTypeTag typeTag = HCTypeTag::make<Type>();
30  return Key(typeTag, iIdTag);
31  }
32 
33  template< class Type, class Key>
34  inline Key makeKey() {
35  HCTypeTag typeTag = HCTypeTag::make<Type>();
36  return Key(typeTag);
37  }
38 
39  //NOTE: the following functions use this struct to determine
40  // how to find the 'Type' (what is returned from the Storage)
41  // when given only an ItemType (what is stored in Storage).
42  // This allows the Storage to be composed of proxies instead of
43  // the 'Type' themselves
44  template<class Key, class ItemType> struct type_from_itemtype {
46  };
47 
48  template<class Key, class ItemType, class Storage, class IdTag >
49  inline bool insert(Storage& iStorage, ItemType* iItem, const IdTag& iIdTag) {
50  return iStorage.insert(makeKey< typename type_from_itemtype<Key, ItemType>::Type,
51  Key>(iIdTag) , iItem);
52  }
53 
54  template< class Key, class ItemType, class Storage>
55  inline bool insert(Storage& iStorage, ItemType* iItem) {
56  return iStorage.insert(makeKey<ItemType,
57  Key>() , iItem);
58  }
59 
60 
61  template< class Key, class ItemType, class Storage, class IdTag >
62  inline ItemType* find(const Storage& iStorage, const IdTag& iIdTag) {
63  //The cast should be safe since the Key tells us the type
64  return static_cast<ItemType*>(iStorage.find(
65  makeKey<typename type_from_itemtype<Key,
66  ItemType>::Type,Key>(iIdTag)));
67  }
68 
69  template< class Key, class ItemType, class Storage>
70  inline ItemType* find(const Storage& iStorage) {
71  //The cast should be safe since the Key tells us the type
72  return static_cast<ItemType*>( iStorage.find(
73  makeKey<typename type_from_itemtype<Key,
74  ItemType>::Type,Key>()));
75  }
76  }
77  }
78 }
79 #endif
Key makeKey(const IdTag &iIdTag)
Definition: HCMethods.h:28
type
Definition: HCALResponse.h:21
ItemType * find(const Storage &iStorage, const IdTag &iIdTag)
Definition: HCMethods.h:62
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
boost::remove_const< ItemType >::type Type
Definition: HCMethods.h:45