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