CMS 3D CMS Logo

fillPtrVector.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_fillPtrVector_h
2 #define DataFormats_Common_fillPtrVector_h
3 // -*- C++ -*-
4 //
5 // Package: Common
6 // Class : fillPtrVector
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Sat Oct 20 11:45:38 CEST 2007
19 //
20 
21 // system include files
22 
23 // user include files
27 
29 
30 #include <typeinfo>
31 #include <vector>
32 
33 // forward declarations
34 namespace edm {
35  namespace detail {
36  template <typename COLLECTION>
37  void reallyfillPtrVector(COLLECTION const& coll,
38  std::type_info const& iToType,
39  std::vector<unsigned long> const& iIndicies,
40  std::vector<void const*>& oPtr) {
41  typedef COLLECTION product_type;
42  typedef typename GetProduct<product_type>::element_type element_type;
43  typedef typename product_type::const_iterator iter;
44 
45  oPtr.reserve(iIndicies.size());
46  if (iToType == typeid(element_type)) {
47  for (std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(), itEnd = iIndicies.end();
48  itIndex != itEnd;
49  ++itIndex) {
50  iter it = coll.begin();
51  std::advance(it, *itIndex);
52  element_type const* address = GetProduct<product_type>::address(it);
53  oPtr.push_back(address);
54  }
55  } else {
56  for (std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(), itEnd = iIndicies.end();
57  itIndex != itEnd;
58  ++itIndex) {
59  iter it = coll.begin();
60  std::advance(it, *itIndex);
61  element_type const* address = GetProduct<product_type>::address(it);
62  void const* ptr = pointerToBase(iToType, address);
63  if (nullptr != ptr) {
64  oPtr.push_back(ptr);
65  } else {
67  "TypeConversionError "
68  "edm::PtrVector<> : unable to convert type ",
69  typeid(element_type).name(),
70  " to ",
71  iToType.name(),
72  "\n");
73  }
74  }
75  }
76  }
77  } // namespace detail
78 
79  template <typename T, typename A>
80  void fillPtrVector(std::vector<T, A> const& obj,
81  std::type_info const& iToType,
82  std::vector<unsigned long> const& iIndicies,
83  std::vector<void const*>& oPtr) {
84  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
85  }
86 
87  template <typename T, typename A>
88  void fillPtrVector(std::list<T, A> const& obj,
89  std::type_info const& iToType,
90  std::vector<unsigned long> const& iIndicies,
91  std::vector<void const*>& oPtr) {
92  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
93  }
94 
95  template <typename T, typename A>
96  void fillPtrVector(std::deque<T, A> const& obj,
97  std::type_info const& iToType,
98  std::vector<unsigned long> const& iIndicies,
99  std::vector<void const*>& oPtr) {
100  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
101  }
102 
103  template <typename T, typename A, typename Comp>
104  void fillPtrVector(std::set<T, A, Comp> const& obj,
105  std::type_info const& iToType,
106  std::vector<unsigned long> const& iIndicies,
107  std::vector<void const*>& oPtr) {
108  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
109  }
110 } // namespace edm
111 
112 #endif
static const element_type * address(const iter &i)
Definition: GetProduct.h:36
void fillPtrVector(std::vector< T, A > const &obj, std::type_info const &iToType, std::vector< unsigned long > const &iIndicies, std::vector< void const *> &oPtr)
Definition: fillPtrVector.h:80
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:86
COLLECTION::value_type element_type
Definition: GetProduct.h:34
void reallyfillPtrVector(COLLECTION const &coll, std::type_info const &iToType, std::vector< unsigned long > const &iIndicies, std::vector< void const *> &oPtr)
Definition: fillPtrVector.h:37
HLT enums.
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:47