CMS 3D CMS Logo

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 <type_traits>
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>
47  };
48 
49  template <class Key, class ItemType, class Storage, class IdTag>
50  inline bool insert(Storage& iStorage, ItemType* iItem, const IdTag& iIdTag) {
51  return iStorage.insert(makeKey<typename type_from_itemtype<Key, ItemType>::Type, 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, Key>(), iItem);
57  }
58 
59  template <class Key, class ItemType, class Storage, class IdTag>
60  inline ItemType* find(const Storage& iStorage, const IdTag& iIdTag) {
61  //The cast should be safe since the Key tells us the type
62  return static_cast<ItemType*>(
63  iStorage.find(makeKey<typename type_from_itemtype<Key, ItemType>::Type, Key>(iIdTag)));
64  }
65 
66  template <class Key, class ItemType, class Storage>
67  inline ItemType* find(const Storage& iStorage) {
68  //The cast should be safe since the Key tells us the type
69  return static_cast<ItemType*>(iStorage.find(makeKey<typename type_from_itemtype<Key, ItemType>::Type, Key>()));
70  }
71  } // namespace heterocontainer
72  } // namespace eventsetup
73 } // namespace edm
74 #endif
edm::eventsetup::heterocontainer::type_from_itemtype
Definition: HCMethods.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
Key
Definition: GoldenPattern.h:15
edm::eventsetup::heterocontainer::HCTypeTag
Definition: HCTypeTag.h:38
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:39
edm::eventsetup::heterocontainer::makeKey
Key makeKey(const IdTag &iIdTag)
Definition: HCMethods.h:28
edm::eventsetup::heterocontainer::find
ItemType * find(const Storage &iStorage, const IdTag &iIdTag)
Definition: HCMethods.h:60
edm::eventsetup::heterocontainer::insert
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50
edm::eventsetup::heterocontainer::type_from_itemtype::Type
std::remove_const< ItemType >::type Type
Definition: HCMethods.h:46
Storage
Definition: Storage.h:20
HCTypeTag.h