CMS 3D CMS Logo

setPtr.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_setPtr_h
2 #define DataFormats_Common_setPtr_h
3 // -*- C++ -*-
4 //
5 // Package: Common
6 // Class : setPtr
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Sat Oct 20 11:45:38 CEST 2007
19 //
20 
21 // user include files
26 
27 // system include files
28 #include <typeinfo>
29 #include <vector>
30 
31 // forward declarations
32 namespace edm {
33  namespace detail {
34 
35  template <typename COLLECTION>
36  void
37  reallySetPtr(COLLECTION const& coll,
38  std::type_info const& iToType,
39  unsigned long iIndex,
40  void const*& oPtr) {
41  typedef COLLECTION product_type;
42  typedef typename GetProduct<product_type>::element_type element_type;
43  typedef typename product_type::const_iterator iter;
44 
45  if(iToType == typeid(element_type)) {
46  iter it = coll.begin();
47  std::advance(it,iIndex);
48  element_type const* address = GetProduct<product_type>::address(it);
49  oPtr = address;
50  } else {
51  iter it = coll.begin();
52  std::advance(it,iIndex);
53  element_type const* address = GetProduct<product_type>::address(it);
54 
55  oPtr = pointerToBase(iToType,address);
56 
57  if(nullptr == oPtr) {
59  "TypeConversionError"
60  "edm::Ptr<> : unable to convert type ",
61  typeid(element_type).name(),
62  " to ",
63  iToType.name(),
64  "\n");
65  }
66  }
67  }
68  }
69 
70  template <typename T, typename A>
71  void
72  setPtr(std::vector<T, A> const& obj,
73  std::type_info const& iToType,
74  unsigned long iIndex,
75  void const*& oPtr) {
76  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
77  }
78 
79  template <typename T, typename A>
80  void
81  setPtr(std::list<T, A> const& obj,
82  std::type_info const& iToType,
83  unsigned long iIndex,
84  void const*& oPtr) {
85  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
86  }
87 
88  template <typename T, typename A>
89  void
90  setPtr(std::deque<T, A> const& obj,
91  std::type_info const& iToType,
92  unsigned long iIndex,
93  void const*& oPtr) {
94  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
95  }
96 
97  template <typename T, typename A, typename Comp>
98  void
99  setPtr(std::set<T, A, Comp> const& obj,
100  std::type_info const& iToType,
101  unsigned long iIndex,
102  void const*& oPtr) {
103  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
104  }
105 
106 }
107 
108 #endif
static const element_type * address(const iter &i)
Definition: GetProduct.h:33
void setPtr(std::vector< T, A > const &obj, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
Definition: setPtr.h:72
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
COLLECTION::value_type element_type
Definition: GetProduct.h:31
void reallySetPtr(COLLECTION const &coll, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
Definition: setPtr.h:37
JetCorrectorParametersCollection coll
Definition: classes.h:10
HLT enums.
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:50