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
edm::errors::LogicError
Definition: EDMException.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
OffsetToBase.h
detail
Definition: ConvertingESProducerWithDependenciesT.h:23
edm::pointerToBase
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:47
EDMException.h
edm::setPtr
void setPtr(std::vector< T, A > const &obj, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
Definition: setPtr.h:67
edm::detail::reallySetPtr
void reallySetPtr(COLLECTION const &coll, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
Definition: setPtr.h:36
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::detail::GetProduct::address
static const element_type * address(const iter &i)
Definition: GetProduct.h:36
FillView.h
edm::detail::GetProduct::element_type
COLLECTION::value_type element_type
Definition: GetProduct.h:34
edm::Exception::throwThis
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
fwd_setPtr.h