Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:58

0001 #ifndef DataFormats_Common_FillView_h
0002 #define DataFormats_Common_FillView_h
0003 
0004 /*----------------------------------------------------------------------
0005   
0006 Several fillView function templates, to provide View support for 
0007 Standard Library containers.
0008 
0009 ----------------------------------------------------------------------*/
0010 
0011 #include <vector>
0012 #include <list>
0013 #include <deque>
0014 #include <set>
0015 #include "DataFormats/Common/interface/GetProduct.h"
0016 #include "DataFormats/Common/interface/FillViewHelperVector.h"
0017 
0018 namespace edm {
0019 
0020   class ProductID;
0021 
0022   namespace detail {
0023 
0024     template <class COLLECTION>
0025     void reallyFillView(COLLECTION const& coll,
0026                         ProductID const& id,
0027                         std::vector<void const*>& ptrs,
0028                         FillViewHelperVector& helpers) {
0029       typedef COLLECTION product_type;
0030       typedef typename GetProduct<product_type>::element_type element_type;
0031       typedef typename product_type::const_iterator iter;
0032       typedef typename product_type::size_type size_type;
0033 
0034       ptrs.reserve(ptrs.size() + coll.size());
0035       helpers.reserve(ptrs.size() + coll.size());
0036       size_type key = 0;
0037       for (iter i = coll.begin(), e = coll.end(); i != e; ++i, ++key) {
0038         element_type const* address = GetProduct<product_type>::address(i);
0039         ptrs.push_back(address);
0040         helpers.emplace_back(id, key);
0041       }
0042     }
0043   }  // namespace detail
0044   template <class T, class A>
0045   void fillView(std::vector<T, A> const& obj,
0046                 ProductID const& id,
0047                 std::vector<void const*>& ptrs,
0048                 FillViewHelperVector& helpers) {
0049     detail::reallyFillView(obj, id, ptrs, helpers);
0050   }
0051 
0052   template <class T, class A>
0053   void fillView(std::list<T, A> const& obj,
0054                 ProductID const& id,
0055                 std::vector<void const*>& ptrs,
0056                 FillViewHelperVector& helpers) {
0057     detail::reallyFillView(obj, id, ptrs, helpers);
0058   }
0059 
0060   template <class T, class A>
0061   void fillView(std::deque<T, A> const& obj,
0062                 ProductID const& id,
0063                 std::vector<void const*>& ptrs,
0064                 FillViewHelperVector& helpers) {
0065     detail::reallyFillView(obj, id, ptrs, helpers);
0066   }
0067 
0068   template <class T, class A, class Comp>
0069   void fillView(std::set<T, A, Comp> const& obj,
0070                 ProductID const& id,
0071                 std::vector<void const*>& ptrs,
0072                 FillViewHelperVector& helpers) {
0073     detail::reallyFillView(obj, id, ptrs, helpers);
0074   }
0075 
0076 }  // namespace edm
0077 
0078 #endif