CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/FWCore/Framework/interface/produce_helpers.h

Go to the documentation of this file.
00001 #ifndef Framework_produce_helpers_h
00002 #define Framework_produce_helpers_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     produce_helpers
00007 // 
00016 //
00017 // Author:      Chris Jones
00018 // Created:     Fri Apr 15 10:25:20 EDT 2005
00019 // $Id: produce_helpers.h,v 1.6 2006/08/16 13:51:18 chrjones Exp $
00020 //
00021 
00022 // system include files
00023 #include <memory>
00024 // user include files
00025 #include "boost/shared_ptr.hpp"
00026 
00027 // forward declarations
00028 namespace edm {
00029    namespace eventsetup {
00030       
00031       namespace produce { struct Null;}
00032       
00033      template<typename FromT, typename ToT> void copyFromTo(FromT& iFrom,
00034                                                             ToT & iTo) {
00035        iTo = iFrom;
00036      }
00037 
00038      namespace produce { 
00039          struct Null {};
00040          template <typename T> struct EndList {
00041             typedef T tail_type;
00042             typedef Null head_type;
00043          };
00044          template <typename T> struct product_traits {
00045             typedef T type;
00046          };
00047          template< typename T> struct product_traits<T*> {
00048             typedef EndList<T*> type;
00049          };
00050          template< typename T> struct product_traits<std::auto_ptr<T> > {
00051             typedef EndList<std::auto_ptr<T> > type;
00052          };
00053          template< typename T> struct product_traits<boost::shared_ptr<T> > {
00054             typedef EndList<boost::shared_ptr<T> > type;
00055          };
00056          
00057          
00058          template<typename T> struct size {
00059             typedef typename product_traits<T>::type type;
00060             enum { value = size< typename type::head_type >::value + 1 };
00061          };
00062          template<> struct size<Null> {
00063             enum { value = 0 };
00064          };
00065          
00066          template<typename T> struct smart_pointer_traits {
00067             typedef typename T::element_type type;
00068          };
00069 
00070          template<typename T> struct smart_pointer_traits<T*> {
00071             typedef  T type;
00072          };
00073          template<typename T> struct smart_pointer_traits< T const *> {
00074             typedef  T type;
00075          };
00076          
00077          template<typename FromT, typename ToT> void copyFromTo(FromT& iFrom,
00078                                                                  ToT & iTo) {
00079             iTo = iFrom;
00080          }
00081 
00082          
00083          
00084          template<typename ContainerT, typename EntryT, typename FindT> struct find_index_impl {
00085             typedef typename product_traits<ContainerT>::type container_type;
00086             enum { value = find_index_impl<typename container_type::head_type, typename container_type::tail_type,  FindT>::value + 1 };
00087          };
00088          template<typename ContainerT, typename T> struct find_index_impl<ContainerT, T,T> {
00089             enum { value = 0 };
00090          };
00091          
00092          template<typename T, typename FindT> struct find_index {
00093             typedef typename product_traits<T>::type container_type;
00094             enum {value = find_index_impl<typename container_type::head_type, typename container_type::tail_type, FindT>::value };
00095          };
00096          namespace test {
00097             template<typename T> const char* name(const T*);
00098          }
00099          
00100       }
00101    }
00102 }
00103 
00104 #endif