CMS 3D CMS Logo

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:
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) {
52  int offset = offsetToBase.offsetToBase(baseTypeInfo);
53  void const* ptr = address;
54  return static_cast<char const*>(ptr) + offset;
55  }
56 }
57 #endif
size_t offsetToBase(std::type_info const &baseTypeInfo) const
Definition: OffsetToBase.h:44
HLT enums.
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:50
long double T