CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
38  reallyfillPtrVector(COLLECTION const& coll,
39  std::type_info const& iToType,
40  std::vector<unsigned long> const& iIndicies,
41  std::vector<void const*>& oPtr)
42  {
43  typedef COLLECTION product_type;
44  typedef typename GetProduct<product_type>::element_type element_type;
45  typedef typename product_type::const_iterator iter;
46 
47  oPtr.reserve(iIndicies.size());
48  if(iToType == typeid(element_type)) {
49  for(std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(),
50  itEnd = iIndicies.end();
51  itIndex != itEnd;
52  ++itIndex) {
53  iter it = coll.begin();
54  std::advance(it, *itIndex);
55  element_type const* address = GetProduct<product_type>::address(it);
56  oPtr.push_back(address);
57  }
58  } else {
59  for(std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(),
60  itEnd = iIndicies.end();
61  itIndex != itEnd;
62  ++itIndex) {
63  iter it = coll.begin();
64  std::advance(it, *itIndex);
65  element_type const* address = GetProduct<product_type>::address(it);
66  void const* ptr = pointerToBase(iToType,address);
67  if(nullptr != ptr) {
68  oPtr.push_back(ptr);
69  } else {
71  "TypeConversionError "
72  "edm::PtrVector<> : unable to convert type ",
73  typeid(element_type).name(),
74  " to ",
75  iToType.name(),
76  "\n");
77  }
78  }
79  }
80  }
81  }
82 
83  template <typename T, typename A>
84  void
85  fillPtrVector(std::vector<T, A> const& obj,
86  std::type_info const& iToType,
87  std::vector<unsigned long> const& iIndicies,
88  std::vector<void const*>& oPtr) {
89  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
90  }
91 
92  template <typename T, typename A>
93  void
94  fillPtrVector(std::list<T, A> const& obj,
95  std::type_info const& iToType,
96  std::vector<unsigned long> const& iIndicies,
97  std::vector<void const*>& oPtr) {
98  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
99  }
100 
101  template <typename T, typename A>
102  void
103  fillPtrVector(std::deque<T, A> const& obj,
104  std::type_info const& iToType,
105  std::vector<unsigned long> const& iIndicies,
106  std::vector<void const*>& oPtr) {
107  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
108  }
109 
110  template <typename T, typename A, typename Comp>
111  void
112  fillPtrVector(std::set<T, A, Comp> const& obj,
113  std::type_info const& iToType,
114  std::vector<unsigned long> const& iIndicies,
115  std::vector<void const*>& oPtr) {
116  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
117  }
118 }
119 
120 #endif
static const element_type * address(const iter &i)
Definition: GetProduct.h:33
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:85
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
void reallyfillPtrVector(COLLECTION const &coll, std::type_info const &iToType, std::vector< unsigned long > const &iIndicies, std::vector< void const * > &oPtr)
Definition: fillPtrVector.h:38
COLLECTION::value_type element_type
Definition: GetProduct.h:31
JetCorrectorParametersCollection coll
Definition: classes.h:10
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:49