CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FWCore/Framework/interface/HCMethods.h

Go to the documentation of this file.
00001 #ifndef Framework_HCMethods_h
00002 #define Framework_HCMethods_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     HeteroContainer
00006 // Module:      HCMethods
00007 // 
00008 // Description: Templated methods to be used to 'construct' a 
00009 //              heterogenous container
00010 //
00011 // Usage:
00012 //    <usage>
00013 //
00014 // Author:      Chris D. Jones
00015 // Created:     Sun Mar 27 15:58:05 EDT 2005
00016 //
00017 
00018 // system include files
00019 
00020 #include "FWCore/Framework/interface/HCTypeTag.h"
00021 #include "boost/type_traits/remove_const.hpp"
00022 // user include files
00023 
00024 namespace edm {
00025   namespace eventsetup {
00026     namespace heterocontainer {
00027       template< class Type, class Key, class IdTag >
00028       inline Key makeKey(const IdTag& iIdTag) {
00029         HCTypeTag typeTag = HCTypeTag::make<Type>();
00030         return Key(typeTag, iIdTag);
00031       }
00032       
00033       template< class Type, class Key>
00034       inline Key makeKey() {
00035         HCTypeTag typeTag = HCTypeTag::make<Type>();
00036         return Key(typeTag);
00037       }
00038       
00039       //NOTE: the following functions use this struct to determine
00040       //  how to find the 'Type' (what is returned from the Storage)
00041       //  when given only an ItemType (what is stored in Storage). 
00042       //  This allows the Storage to be composed of proxies instead of
00043       //  the 'Type' themselves
00044       template<class Key, class ItemType> struct type_from_itemtype {
00045         typedef typename boost::remove_const<ItemType>::type Type;
00046       };
00047 
00048       template<class Key, class ItemType, class Storage, class IdTag >
00049       inline bool insert(Storage& iStorage, ItemType* iItem, const IdTag& iIdTag) {
00050         return iStorage.insert(makeKey< typename type_from_itemtype<Key, ItemType>::Type, 
00051                                Key>(iIdTag) , iItem);
00052       }
00053       
00054       template<  class Key, class ItemType, class Storage>
00055       inline bool insert(Storage& iStorage, ItemType* iItem) {
00056         return iStorage.insert(makeKey<ItemType,
00057                                Key>() , iItem);
00058          }
00059       
00060       
00061       template< class Key, class ItemType, class Storage, class IdTag >
00062       inline ItemType* find(const Storage& iStorage, const IdTag& iIdTag) {
00063         //The cast should be safe since the Key tells us the type
00064         return static_cast<ItemType*>(iStorage.find(
00065                                                     makeKey<typename type_from_itemtype<Key,
00066                                                     ItemType>::Type,Key>(iIdTag)));
00067       }
00068       
00069       template< class Key, class ItemType, class Storage>
00070       inline ItemType* find(const Storage& iStorage) {
00071         //The cast should be safe since the Key tells us the type
00072         return static_cast<ItemType*>( iStorage.find(
00073                                                      makeKey<typename type_from_itemtype<Key,
00074                                                      ItemType>::Type,Key>()));
00075          }
00076     }
00077   }
00078 }
00079 #endif