Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:03

0001 #ifndef Framework_HCMethods_h
0002 #define Framework_HCMethods_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     HeteroContainer
0006 // Module:      HCMethods
0007 //
0008 // Description: Templated methods to be used to 'construct' a
0009 //              heterogenous container
0010 //
0011 // Usage:
0012 //    <usage>
0013 //
0014 // Author:      Chris D. Jones
0015 // Created:     Sun Mar 27 15:58:05 EDT 2005
0016 //
0017 
0018 // system include files
0019 
0020 #include "FWCore/Framework/interface/HCTypeTag.h"
0021 #include <type_traits>
0022 // user include files
0023 
0024 namespace edm {
0025   namespace eventsetup {
0026     namespace heterocontainer {
0027       template <class Type, class Key, class IdTag>
0028       inline Key makeKey(const IdTag& iIdTag) {
0029         HCTypeTag typeTag = HCTypeTag::make<Type>();
0030         return Key(typeTag, iIdTag);
0031       }
0032 
0033       template <class Type, class Key>
0034       inline Key makeKey() {
0035         HCTypeTag typeTag = HCTypeTag::make<Type>();
0036         return Key(typeTag);
0037       }
0038 
0039       //NOTE: the following functions use this struct to determine
0040       //  how to find the 'Type' (what is returned from the Storage)
0041       //  when given only an ItemType (what is stored in Storage).
0042       //  This allows the Storage to be composed of proxies instead of
0043       //  the 'Type' themselves
0044       template <class Key, class ItemType>
0045       struct type_from_itemtype {
0046         typedef typename std::remove_const<ItemType>::type Type;
0047       };
0048 
0049       template <class Key, class ItemType, class Storage, class IdTag>
0050       inline bool insert(Storage& iStorage, ItemType* iItem, const IdTag& iIdTag) {
0051         return iStorage.insert(makeKey<typename type_from_itemtype<Key, ItemType>::Type, Key>(iIdTag), iItem);
0052       }
0053 
0054       template <class Key, class ItemType, class Storage>
0055       inline bool insert(Storage& iStorage, ItemType* iItem) {
0056         return iStorage.insert(makeKey<ItemType, Key>(), iItem);
0057       }
0058 
0059       template <class Key, class ItemType, class Storage, class IdTag>
0060       inline ItemType* find(const Storage& iStorage, const IdTag& iIdTag) {
0061         //The cast should be safe since the Key tells us the type
0062         return static_cast<ItemType*>(
0063             iStorage.find(makeKey<typename type_from_itemtype<Key, ItemType>::Type, Key>(iIdTag)));
0064       }
0065 
0066       template <class Key, class ItemType, class Storage>
0067       inline ItemType* find(const Storage& iStorage) {
0068         //The cast should be safe since the Key tells us the type
0069         return static_cast<ItemType*>(iStorage.find(makeKey<typename type_from_itemtype<Key, ItemType>::Type, Key>()));
0070       }
0071     }  // namespace heterocontainer
0072   }    // namespace eventsetup
0073 }  // namespace edm
0074 #endif