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
26 #include "Reflex/Object.h"
27 #include "Reflex/Type.h"
28 
30 
31 #include <typeinfo>
32 #include <vector>
33 
34 // forward declarations
35 namespace edm {
36  namespace detail {
37  template <typename COLLECTION>
38  void
39  reallyfillPtrVector(COLLECTION const& coll,
40  std::type_info const& iToType,
41  std::vector<unsigned long> const& iIndicies,
42  std::vector<void const*>& oPtr)
43  {
44  typedef COLLECTION product_type;
45  typedef typename GetProduct<product_type>::element_type element_type;
46  typedef typename product_type::const_iterator iter;
47  typedef typename product_type::size_type size_type;
48 
49  oPtr.reserve(iIndicies.size());
50  if(iToType == typeid(element_type)) {
51  for(std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(),
52  itEnd = iIndicies.end();
53  itIndex != itEnd;
54  ++itIndex) {
55  iter it = coll.begin();
56  std::advance(it, *itIndex);
57  element_type const* address = GetProduct<product_type>::address(it);
58  oPtr.push_back(address);
59  }
60  } else {
61  using Reflex::Type;
62  using Reflex::Object;
63  static Type const s_type(Type::ByTypeInfo(typeid(element_type)));
64  Type toType = Type::ByTypeInfo(iToType);
65 
66  for(std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(),
67  itEnd = iIndicies.end();
68  itIndex != itEnd;
69  ++itIndex) {
70  iter it = coll.begin();
71  std::advance(it, *itIndex);
72  element_type const* address = GetProduct<product_type>::address(it);
73  // The const_cast below is needed because
74  // Object's constructor requires a pointer to
75  // non-const void, although the implementation does not, of
76  // course, modify the object to which the pointer points.
77  Object obj(s_type, const_cast<void*>(static_cast<void const*>(address)));
78  Object cast = obj.CastObject(toType);
79  if(0 != cast.Address()) {
80  oPtr.push_back(cast.Address());// returns void*, after pointer adjustment
81  } else {
83  "TypeConversionError "
84  "edm::PtrVector<> : unable to convert type ",
85  typeid(element_type).name(),
86  " to ",
87  iToType.name(),
88  "\n");
89  }
90  }
91  }
92  }
93  }
94 
95  template <typename T, typename A>
96  void
97  fillPtrVector(std::vector<T, A> const& obj,
98  std::type_info const& iToType,
99  std::vector<unsigned long> const& iIndicies,
100  std::vector<void const*>& oPtr) {
101  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
102  }
103 
104  template <typename T, typename A>
105  void
106  fillPtrVector(std::list<T, A> const& obj,
107  std::type_info const& iToType,
108  std::vector<unsigned long> const& iIndicies,
109  std::vector<void const*>& oPtr) {
110  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
111  }
112 
113  template <typename T, typename A>
114  void
115  fillPtrVector(std::deque<T, A> const& obj,
116  std::type_info const& iToType,
117  std::vector<unsigned long> const& iIndicies,
118  std::vector<void const*>& oPtr) {
119  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
120  }
121 
122  template <typename T, typename A, typename Comp>
123  void
124  fillPtrVector(std::set<T, A, Comp> const& obj,
125  std::type_info const& iToType,
126  std::vector<unsigned long> const& iIndicies,
127  std::vector<void const*>& oPtr) {
128  detail::reallyfillPtrVector(obj, iToType, iIndicies, oPtr);
129  }
130 }
131 
132 #endif
char * address
Definition: mlp_lapack.h:14
static const element_type * address(const iter &i)
Definition: GetProduct.h:34
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:97
uint16_t size_type
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:39
COLLECTION::value_type element_type
Definition: GetProduct.h:32
JetCorrectorParametersCollection coll
Definition: classes.h:14