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  typedef typename product_type::size_type size_type;
47 
48  oPtr.reserve(iIndicies.size());
49  if(iToType == typeid(element_type)) {
50  for(std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(),
51  itEnd = iIndicies.end();
52  itIndex != itEnd;
53  ++itIndex) {
54  iter it = coll.begin();
55  std::advance(it, *itIndex);
56  element_type const* address = GetProduct<product_type>::address(it);
57  oPtr.push_back(address);
58  }
59  } else {
60  static TypeWithDict const s_type(typeid(element_type));
61 
62  for(std::vector<unsigned long>::const_iterator itIndex = iIndicies.begin(),
63  itEnd = iIndicies.end();
64  itIndex != itEnd;
65  ++itIndex) {
66  iter it = coll.begin();
67  std::advance(it, *itIndex);
68  element_type const* address = GetProduct<product_type>::address(it);
69  void const* ptr = TypeWithDict(iToType).pointerToBaseType(address, s_type);
70  if(0 != ptr) {
71  oPtr.push_back(ptr);
72  } else {
74  "TypeConversionError "
75  "edm::PtrVector<> : unable to convert type ",
76  typeid(element_type).name(),
77  " to ",
78  iToType.name(),
79  "\n");
80  }
81  }
82  }
83  }
84  }
85 
86  template <typename T, typename A>
87  void
88  fillPtrVector(std::vector<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
97  fillPtrVector(std::list<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::deque<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, typename Comp>
114  void
115  fillPtrVector(std::set<T, A, Comp> 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 
123 #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:88
void const * pointerToBaseType(void const *ptr, TypeWithDict const &derivedType) const
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:38
COLLECTION::value_type element_type
Definition: GetProduct.h:32
JetCorrectorParametersCollection coll
Definition: classes.h:16