CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
edm::ObjectWithDict Class Reference

#include <ObjectWithDict.h>

Public Member Functions

void * address () const
 
ObjectWithDict castObject (TypeWithDict const &) const
 
void destruct (bool dealloc) const
 
TypeWithDict dynamicType () const
 
ObjectWithDict get (std::string const &memberName) const
 
template<typename T >
T objectCast ()
 
 ObjectWithDict ()
 
 ObjectWithDict (TypeWithDict const &, void *address)
 
 ObjectWithDict (std::type_info const &, void *address)
 
 operator bool () const
 
TypeWithDict typeOf () const
 

Static Public Member Functions

static ObjectWithDict byType (TypeWithDict const &)
 

Private Attributes

void * address_
 
TypeWithDict type_
 

Detailed Description

Definition at line 17 of file ObjectWithDict.h.

Constructor & Destructor Documentation

◆ ObjectWithDict() [1/3]

edm::ObjectWithDict::ObjectWithDict ( )

Definition at line 18 of file ObjectWithDict.cc.

Referenced by castObject().

18 : type_(), address_(nullptr) {}
TypeWithDict type_

◆ ObjectWithDict() [2/3]

edm::ObjectWithDict::ObjectWithDict ( TypeWithDict const &  type,
void *  address 
)
explicit

Definition at line 20 of file ObjectWithDict.cc.

◆ ObjectWithDict() [3/3]

edm::ObjectWithDict::ObjectWithDict ( std::type_info const &  ti,
void *  address 
)
explicit

Definition at line 22 of file ObjectWithDict.cc.

23  : type_(TypeWithDict(ti)), address_(address) {}
void * address() const
TypeWithDict type_

Member Function Documentation

◆ address()

void * edm::ObjectWithDict::address ( ) const

◆ byType()

ObjectWithDict edm::ObjectWithDict::byType ( TypeWithDict const &  type)
static

◆ castObject()

ObjectWithDict edm::ObjectWithDict::castObject ( TypeWithDict const &  to) const

Definition at line 51 of file ObjectWithDict.cc.

References address(), address_, edm::TypeWithDict::getBaseClassOffset(), edm::TypeWithDict::hasBase(), ObjectWithDict(), hltrates_dqm_sourceclient-live_cfg::offset, edm::TypeWithDict::typeInfo(), and typeOf().

Referenced by edm::root::FWLiteDelayedReader::getTheProduct().

51  {
52  TypeWithDict from = typeOf();
53 
54  // Same type
55  if (from == to) {
56  return *this;
57  }
58 
59  if (to.hasBase(from)) { // down cast
60 #ifndef _LIBCPP_VERSION
61  // use the internal dynamic casting of the compiler (e.g. libstdc++.so)
62  void* address = abi::__dynamic_cast(address_,
63  static_cast<abi::__class_type_info const*>(&from.typeInfo()),
64  static_cast<abi::__class_type_info const*>(&to.typeInfo()),
65  -1);
66  return ObjectWithDict(to, address);
67 #else
68  return ObjectWithDict(to, address_);
69 #endif
70  }
71 
72  if (from.hasBase(to)) { // up cast
73  size_t offset = from.getBaseClassOffset(to);
74  size_t address = reinterpret_cast<size_t>(address_) + offset;
75  return ObjectWithDict(to, reinterpret_cast<void*>(address));
76  }
77 
78  // if everything fails return the dummy object
79  return ObjectWithDict();
80  } // castObject
TypeWithDict typeOf() const
void * address() const

◆ destruct()

void edm::ObjectWithDict::destruct ( bool  dealloc) const

Definition at line 92 of file ObjectWithDict.cc.

References address_, haddnano::cl, edm::TypeWithDict::getClass(), and type_.

Referenced by fwlite::internal::Data::~Data().

92  {
93  TClass* cl = type_.getClass();
94  if (cl != nullptr) {
95  cl->Destructor(address_, !dealloc);
96  //if (dealloc) {
97  // address_ = nullptr;
98  //}
99  return;
100  }
101  if (dealloc) {
102  delete[] reinterpret_cast<char*>(address_);
103  //address_ = nullptr;
104  }
105  }
TClass * getClass() const
TypeWithDict type_

◆ dynamicType()

TypeWithDict edm::ObjectWithDict::dynamicType ( ) const

Definition at line 38 of file ObjectWithDict.cc.

References address_, edm::TypeWithDict::byTypeInfo(), edm::TypeWithDict::isVirtual(), and type_.

38  {
39  if (!type_.isVirtual()) {
40  return type_;
41  }
42  // Use a dirty trick, force the typeid() operator
43  // to consult the virtual table stored at address_.
44  return TypeWithDict::byTypeInfo(typeid(*(DummyVT*)address_));
45  }
bool isVirtual() const
static TypeWithDict byTypeInfo(std::type_info const &ti)
Definition: TypeWithDict.cc:62
TypeWithDict type_

◆ get()

ObjectWithDict edm::ObjectWithDict::get ( std::string const &  memberName) const

◆ objectCast()

template<typename T >
T edm::ObjectWithDict::objectCast ( )
inline

Definition at line 38 of file ObjectWithDict.h.

References address_.

38  {
39  return *reinterpret_cast<T*>(address_);
40  }
long double T

◆ operator bool()

edm::ObjectWithDict::operator bool ( ) const
explicit

Definition at line 25 of file ObjectWithDict.cc.

References nano_mu_local_reco_cff::bool.

25 { return bool(type_) && (address_ != nullptr); }
TypeWithDict type_

◆ typeOf()

TypeWithDict edm::ObjectWithDict::typeOf ( ) const

Definition at line 29 of file ObjectWithDict.cc.

References type_.

Referenced by castObject(), and fwlite::DataGetterHelper::wrapperBasePtr().

29 { return type_; }
TypeWithDict type_

Member Data Documentation

◆ address_

void* edm::ObjectWithDict::address_
private

Definition at line 20 of file ObjectWithDict.h.

Referenced by address(), castObject(), destruct(), dynamicType(), and objectCast().

◆ type_

TypeWithDict edm::ObjectWithDict::type_
private