Main Page
Namespaces
Classes
Package Documentation
FWCore
Utilities
interface
OffsetToBase.h
Go to the documentation of this file.
1
#ifndef FWCore_Utilities_OffsetToBase_h
2
#define FWCore_Utilities_OffsetToBase_h
3
#include <cstddef>
4
#include <typeinfo>
5
6
/*
7
* For any class used in Views, RefToBase, or Ptr,
8
* class template OffsetToBase must be specialized for any class
9
* with multiple inheritance (i.e. with non-zero offset to
10
* at least one base class).
11
* A specialization would look something like this
12
* (in YourClass.h"
13
*
14
* #include "FWCore/Utilities/interface/OffsetToBase.h"
15
* namespace edm {
16
* template<>
17
* class OffsetToBase<YourClass> {
18
* public OffsetToBase() {}
19
* size_t offsetToBase(std::type_info const& baseTypeInfo) const {
20
* int const dummy = 0;
21
* YourClass const* object = reinterpret_cast<YourClass const*>(&dummy);
22
* void const* objectPtr = object;
23
* if(baseTypeInfo == typeid(BaseClass1)) {
24
* BaseClass1 const* base = object;
25
* void const* basePtr = base;
26
* return static_cast<char const*>(basePtr) - static_cast<char const*>(objectPtr);
27
* }
28
* if(baseTypeInfo == typeid(BaseClass2)) {
29
* ...
30
* }
31
* etc.
32
* }
33
* };
34
* }
35
*
36
*/
37
38
39
namespace
edm
{
40
template
<
typename
T>
41
class
OffsetToBase
{
42
public
:
43
OffsetToBase
() {}
44
size_t
offsetToBase
(std::type_info
const
& baseTypeInfo)
const
{
45
return
0;
46
}
47
};
48
49
template
<
typename
T>
50
void
const
*
pointerToBase
(std::type_info
const
& baseTypeInfo,
T
const
* address) {
51
OffsetToBase<T>
offsetToBase
;
52
int
offset
= offsetToBase.
offsetToBase
(baseTypeInfo);
53
void
const
* ptr = address;
54
return
static_cast<
char
const*
>
(ptr) + offset;
55
}
56
}
57
#endif
edm::OffsetToBase::OffsetToBase
OffsetToBase()
Definition:
OffsetToBase.h:43
edm::OffsetToBase
Definition:
OffsetToBase.h:41
edm::OffsetToBase::offsetToBase
size_t offsetToBase(std::type_info const &baseTypeInfo) const
Definition:
OffsetToBase.h:44
PFRecoTauDiscriminationByIsolation_cfi.offset
offset
Definition:
PFRecoTauDiscriminationByIsolation_cfi.py:61
edm
HLT enums.
Definition:
AlignableModifier.h:17
edm::pointerToBase
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition:
OffsetToBase.h:50
T
long double T
Definition:
Basic3DVectorLD.h:66
Generated for CMSSW Reference Manual by
1.8.11