CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/DataFormats/Common/interface/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 ----------------------------------------------------------------------*/
00010 
00011 #include <string>
00012 #include <vector>
00013 #include <list>
00014 #include <deque>
00015 #include <set>
00016 #include "DataFormats/Common/interface/RefTraits.h"
00017 #include "DataFormats/Common/interface/RefVectorTraits.h"
00018 #include "DataFormats/Common/interface/GetProduct.h"
00019 
00020 namespace edm {
00021   template<typename C, typename T, typename F> class RefVector;
00022   template<typename C, typename T, typename F> class Ref;
00023   namespace detail {
00024 
00025     // Function template reallyFillView<C> can fill views for
00026     // standard-library collections of appropriate types (vector, list,
00027     // deque, set).
00028 
00029     template<typename C, typename T, typename F>
00030     struct FillViewRefTypeTrait {
00031       typedef Ref<C, T, F> type;
00032     };
00033     
00034     template<typename C, typename T, typename F, typename T1, typename F1>
00035     struct FillViewRefTypeTrait<RefVector<C, T, F>, T1, F1> {
00036       typedef typename refhelper::RefVectorTrait<C, T, F>::ref_type type;
00037     };
00038   }
00039 }
00040 
00041 #include "DataFormats/Common/interface/EDProductfwd.h"
00042 #include "DataFormats/Common/interface/RefVectorHolderBase.h"
00043 
00044 namespace edm {
00045   namespace detail {
00046 
00047     template <class COLLECTION>
00048     void
00049     reallyFillView(COLLECTION const& coll,
00050                    ProductID const& id,
00051                    std::vector<void const*>& ptrs,
00052                    helper_vector& helpers)
00053     {
00054       typedef COLLECTION                            product_type;
00055       typedef typename GetProduct<product_type>::element_type     element_type;
00056       typedef typename product_type::const_iterator iter;
00057       typedef typename product_type::size_type      size_type;
00058       typedef typename FillViewRefTypeTrait<product_type, 
00059         typename refhelper::ValueTrait<product_type>::value, 
00060         typename refhelper::FindTrait<product_type, 
00061         typename refhelper::ValueTrait<product_type>::value>::value>::type ref_type;
00062       typedef reftobase::RefHolder<ref_type>        holder_type;
00063       
00064       ptrs.reserve(ptrs.size() + coll.size());
00065       helpers.reserve(helpers.size() + coll.size());
00066       size_type key = 0;
00067       for (iter i = coll.begin(), e = coll.end(); i!=e; ++i, ++key) {
00068         element_type const* address = GetProduct<product_type>::address(i);
00069         ptrs.push_back(address);
00070         ref_type ref(id, address, key, GetProduct<product_type>::product(coll) );
00071         holder_type h(ref);
00072         helpers.push_back(&h);
00073       }
00074     }
00075   }
00076 
00077   template <class T, class A>
00078   void
00079   fillView(std::vector<T,A> const& obj,
00080            ProductID const& id,
00081            std::vector<void const*>& ptrs,
00082            helper_vector& helpers)
00083   {
00084     detail::reallyFillView(obj, id, ptrs, helpers);
00085   }
00086 
00087   template <class T, class A>
00088   void
00089   fillView(std::list<T,A> const& obj,
00090            ProductID const& id,
00091            std::vector<void const*>& ptrs,
00092            helper_vector& helpers)
00093   {
00094     detail::reallyFillView(obj, id, ptrs, helpers);
00095   }
00096 
00097   template <class T, class A>
00098   void
00099   fillView(std::deque<T,A> const& obj,
00100            ProductID const& id,
00101            std::vector<void const*>& ptrs,
00102            helper_vector& helpers)
00103   {
00104     detail::reallyFillView(obj, id, ptrs, helpers);
00105   }
00106 
00107   template <class T, class A, class Comp>
00108   void
00109   fillView(std::set<T,A,Comp> const& obj,
00110            ProductID const& id,
00111            std::vector<void const*>& ptrs,
00112            helper_vector& helpers)
00113   {
00114     detail::reallyFillView(obj, id, ptrs, helpers);
00115   }
00116 
00117 }
00118 
00119 #endif