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