CMS 3D CMS Logo

FillView.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_FillView_h
00002 #define DataFormats_Common_FillView_h
00003 
00004 /*----------------------------------------------------------------------
00005   
00006 Several fillView function templates, to provide View support for 
00007 Standard Library containers.
00008 
00009 $Id: FillView.h,v 1.9 2007/12/21 22:42:30 wmtan Exp $
00010 
00011 ----------------------------------------------------------------------*/
00012 
00013 #include <string>
00014 #include <vector>
00015 #include <list>
00016 #include <deque>
00017 #include <set>
00018 #include "DataFormats/Common/interface/RefTraits.h"
00019 #include "DataFormats/Common/interface/RefVectorTraits.h"
00020 #include "DataFormats/Common/interface/GetProduct.h"
00021 
00022 namespace edm {
00023   template<typename C, typename T, typename F> class RefVector;
00024   template<typename C, typename T, typename F> class Ref;
00025   namespace detail {
00026 
00027     // Function template reallyFillView<C> can fill views for
00028     // standard-library collections of appropriate types (vector, list,
00029     // deque, set).
00030 
00031     template<typename C, typename T, typename F>
00032     struct FillViewRefTypeTrait {
00033       typedef Ref<C, T, F> type;
00034     };
00035     
00036     template<typename C, typename T, typename F, typename T1, typename F1>
00037     struct FillViewRefTypeTrait<RefVector<C, T, F>, T1, F1> {
00038       typedef typename refhelper::RefVectorTrait<C, T, F>::ref_type type;
00039     };
00040   }
00041 }
00042 
00043 #include "DataFormats/Common/interface/EDProductfwd.h"
00044 #include "DataFormats/Common/interface/RefHolder_.h"
00045 #include "DataFormats/Provenance/interface/ProductID.h"
00046 #include "DataFormats/Common/interface/RefVectorHolderBase.h"
00047 
00048 namespace edm {
00049   namespace detail {
00050 
00051     template <class COLLECTION>
00052     void
00053     reallyFillView(COLLECTION const& coll,
00054                    ProductID const& id,
00055                    std::vector<void const*>& ptrs,
00056                    helper_vector& helpers)
00057     {
00058       typedef COLLECTION                            product_type;
00059       typedef typename GetProduct<product_type>::element_type     element_type;
00060       typedef typename product_type::const_iterator iter;
00061       typedef typename product_type::size_type      size_type;
00062       typedef typename FillViewRefTypeTrait<product_type, 
00063         typename refhelper::ValueTrait<product_type>::value, 
00064         typename refhelper::FindTrait<product_type, 
00065         typename refhelper::ValueTrait<product_type>::value>::value>::type ref_type;
00066       typedef reftobase::RefHolder<ref_type>        holder_type;
00067       
00068       size_type key = 0;
00069       for (iter i = coll.begin(), e = coll.end(); i!=e; ++i, ++key) {
00070         element_type const* address = GetProduct<product_type>::address(i);
00071         ptrs.push_back(address);
00072         ref_type ref(id, address, key, GetProduct<product_type>::product(coll) );
00073         holder_type h(ref);
00074         helpers.push_back(&h);
00075       }
00076     }
00077   }
00078 
00079   template <class T, class A>
00080   void
00081   fillView(std::vector<T,A> const& obj,
00082            ProductID const& id,
00083            std::vector<void const*>& ptrs,
00084            helper_vector& helpers)
00085   {
00086     detail::reallyFillView(obj, id, ptrs, helpers);
00087   }
00088 
00089   template <class T, class A>
00090   void
00091   fillView(std::list<T,A> const& obj,
00092            ProductID const& id,
00093            std::vector<void const*>& ptrs,
00094            helper_vector& helpers)
00095   {
00096     detail::reallyFillView(obj, id, ptrs, helpers);
00097   }
00098 
00099   template <class T, class A>
00100   void
00101   fillView(std::deque<T,A> const& obj,
00102            ProductID const& id,
00103            std::vector<void const*>& ptrs,
00104            helper_vector& helpers)
00105   {
00106     detail::reallyFillView(obj, id, ptrs, helpers);
00107   }
00108 
00109   template <class T, class A, class Comp>
00110   void
00111   fillView(std::set<T,A,Comp> const& obj,
00112            ProductID const& id,
00113            std::vector<void const*>& ptrs,
00114            helper_vector& helpers)
00115   {
00116     detail::reallyFillView(obj, id, ptrs, helpers);
00117   }
00118 
00119 }
00120 
00121 #include "DataFormats/Common/interface/RefHolder.h"
00122 
00123 /*
00124 #include "DataFormats/Common/interface/Ref.h"
00125 #include "DataFormats/Common/interface/RefVector.h"
00126 #include "DataFormats/Common/interface/RefToBase.h"
00127 */
00128 
00129 #endif

Generated on Tue Jun 9 17:28:54 2009 for CMSSW by  doxygen 1.5.4