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  static TypeWithDict const s_type(typeid(element_type));
60 
61  for(std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(),
62  itEnd = iIndicies.end();
63  itIndex != itEnd;
64  ++itIndex) {
65  iter it = coll.begin();
66  std::advance(it, *itIndex);
67  element_type const* address = GetProduct<product_type>::address(it);
68  void const* ptr = TypeWithDict(iToType).pointerToBaseType(address, s_type);
69  if(0 != ptr) {
70  oPtr.push_back(ptr);
71  } else {
73  "TypeConversionError "
74  "edm::PtrVector<> : unable to convert type ",
75  typeid(element_type).name(),
76  " to ",
77  iToType.name(),
78  "\n");
79  }
80  }
81  }
82  }
83  }
84 
85  template <typename T, typename A>
86  void
87  fillPtrVector(std::vector<T, A> const& obj,
88  std::type_info const& iToType,
89  std::vector<unsigned long> const& iIndicies,
90  std::vector<void const*>& oPtr) {
91  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
92  }
93 
94  template <typename T, typename A>
95  void
96  fillPtrVector(std::list<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>
104  void
105  fillPtrVector(std::deque<T, A> const& obj,
106  std::type_info const& iToType,
107  std::vector<unsigned long> const& iIndicies,
108  std::vector<void const*>& oPtr) {
109  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
110  }
111 
112  template <typename T, typename A, typename Comp>
113  void
114  fillPtrVector(std::set<T, A, Comp> const& obj,
115  std::type_info const& iToType,
116  std::vector<unsigned long> const& iIndicies,
117  std::vector<void const*>& oPtr) {
118  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
119  }
120 }
121 
122 #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:87
void const * pointerToBaseType(void const *ptr, TypeWithDict const &derivedType) const
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