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 reallySetPtr(COLLECTION const& coll, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
37  typedef COLLECTION product_type;
38  typedef typename GetProduct<product_type>::element_type element_type;
39  typedef typename product_type::const_iterator iter;
40 
41  if (iToType == typeid(element_type)) {
42  iter it = coll.begin();
43  std::advance(it, iIndex);
44  element_type const* address = GetProduct<product_type>::address(it);
45  oPtr = address;
46  } else {
47  iter it = coll.begin();
48  std::advance(it, iIndex);
49  element_type const* address = GetProduct<product_type>::address(it);
50 
51  oPtr = pointerToBase(iToType, address);
52 
53  if (nullptr == oPtr) {
55  "TypeConversionError"
56  "edm::Ptr<> : unable to convert type ",
57  typeid(element_type).name(),
58  " to ",
59  iToType.name(),
60  "\n");
61  }
62  }
63  }
64  } // namespace detail
65 
66  template <typename T, typename A>
67  void setPtr(std::vector<T, A> const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
68  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
69  }
70 
71  template <typename T, typename A>
72  void setPtr(std::list<T, A> const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
73  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
74  }
75 
76  template <typename T, typename A>
77  void setPtr(std::deque<T, A> const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
78  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
79  }
80 
81  template <typename T, typename A, typename Comp>
82  void setPtr(std::set<T, A, Comp> const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
83  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
84  }
85 
86 } // namespace edm
87 
88 #endif
static const element_type * address(const iter &i)
Definition: GetProduct.h:36
void setPtr(std::vector< T, A > const &obj, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
Definition: setPtr.h:67
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:84
COLLECTION::value_type element_type
Definition: GetProduct.h:34
void reallySetPtr(COLLECTION const &coll, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
Definition: setPtr.h:36
HLT enums.
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:47