CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  typedef typename product_type::size_type size_type;
45 
46  if(iToType == typeid(element_type)) {
47  iter it = coll.begin();
48  std::advance(it,iIndex);
49  element_type const* address = GetProduct<product_type>::address( it );
50  oPtr = address;
51  } else {
52  static TypeWithDict const s_type(TypeWithDict(typeid(element_type)));
53 
54  iter it = coll.begin();
55  std::advance(it,iIndex);
56  element_type const* address = GetProduct<product_type>::address( it );
57 
58  oPtr = TypeWithDict(iToType).pointerToBaseType(address, s_type);
59 
60  if(0 == oPtr) {
62  "TypeConversionError"
63  "edm::Ptr<> : unable to convert type ",
64  typeid(element_type).name(),
65  " to ",
66  iToType.name(),
67  "\n");
68  }
69  }
70  }
71  }
72 
73  template <typename T, typename A>
74  void
75  setPtr(std::vector<T, A> const& obj,
76  std::type_info const& iToType,
77  unsigned long iIndex,
78  void const*& oPtr) {
79  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
80  }
81 
82  template <typename T, typename A>
83  void
84  setPtr(std::list<T, A> const& obj,
85  std::type_info const& iToType,
86  unsigned long iIndex,
87  void const*& oPtr) {
88  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
89  }
90 
91  template <typename T, typename A>
92  void
93  setPtr(std::deque<T, A> const& obj,
94  std::type_info const& iToType,
95  unsigned long iIndex,
96  void const*& oPtr) {
97  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
98  }
99 
100  template <typename T, typename A, typename Comp>
101  void
102  setPtr(std::set<T, A, Comp> const& obj,
103  std::type_info const& iToType,
104  unsigned long iIndex,
105  void const*& oPtr) {
106  detail::reallySetPtr(obj, iToType, iIndex, oPtr);
107  }
108 
109 }
110 
111 #endif
static const element_type * address(const iter &i)
Definition: GetProduct.h:33
void const * pointerToBaseType(void const *ptr, TypeWithDict const &derivedType) const
uint16_t size_type
void setPtr(std::vector< T, A > const &obj, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
Definition: setPtr.h:75
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