1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#ifndef DataFormats_Common_setPtr_h
#define DataFormats_Common_setPtr_h
// -*- C++ -*-
//
// Package: Common
// Class : setPtr
//
/**\class setPtr setPtr.h DataFormats/Common/interface/setPtr.h
Description: Helper function used to implement the edm::Ptr class
Usage:
This is an internal detail of edm::Ptr interaction with edm::Wrapper and should not be used by others
*/
//
// Original Author: Chris Jones
// Created: Sat Oct 20 11:45:38 CEST 2007
//
// user include files
#include "DataFormats/Common/interface/FillView.h"
#include "DataFormats/Common/interface/fwd_setPtr.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/OffsetToBase.h"
// system include files
#include <typeinfo>
#include <vector>
// forward declarations
namespace edm {
namespace detail {
template <typename COLLECTION>
void reallySetPtr(COLLECTION const& coll, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
typedef COLLECTION product_type;
typedef typename GetProduct<product_type>::element_type element_type;
typedef typename product_type::const_iterator iter;
if (iToType == typeid(element_type)) {
iter it = coll.begin();
std::advance(it, iIndex);
element_type const* address = GetProduct<product_type>::address(it);
oPtr = address;
} else {
iter it = coll.begin();
std::advance(it, iIndex);
element_type const* address = GetProduct<product_type>::address(it);
oPtr = pointerToBase(iToType, address);
if (nullptr == oPtr) {
Exception::throwThis(errors::LogicError,
"TypeConversionError"
"edm::Ptr<> : unable to convert type ",
typeid(element_type).name(),
" to ",
iToType.name(),
"\n");
}
}
}
} // namespace detail
template <typename T, typename A>
void setPtr(std::vector<T, A> const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
detail::reallySetPtr(obj, iToType, iIndex, oPtr);
}
template <typename T, typename A>
void setPtr(std::list<T, A> const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
detail::reallySetPtr(obj, iToType, iIndex, oPtr);
}
template <typename T, typename A>
void setPtr(std::deque<T, A> const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
detail::reallySetPtr(obj, iToType, iIndex, oPtr);
}
template <typename T, typename A, typename Comp>
void setPtr(std::set<T, A, Comp> const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
detail::reallySetPtr(obj, iToType, iIndex, oPtr);
}
} // namespace edm
#endif
|