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 (std::type_info const &, void *address)
 
 ObjectWithDict (TypeWithDict 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.

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

Referenced by castObject().

◆ ObjectWithDict() [2/3]

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

Definition at line 20 of file ObjectWithDict.cc.

20 : type_(type), address_(address) {}

◆ 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) {}

Member Function Documentation

◆ address()

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

◆ byType()

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

Definition at line 13 of file ObjectWithDict.cc.

13  {
14  ObjectWithDict obj(type.construct());
15  return obj;
16  }

References getGTfromDQMFile::obj.

Referenced by fwlite::DataGetterHelper::getBranchDataFor(), and reco::parser::ExpressionVar::makeStorage().

◆ castObject()

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

Definition at line 51 of file ObjectWithDict.cc.

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

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().

◆ destruct()

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

Definition at line 92 of file ObjectWithDict.cc.

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  }

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

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

◆ dynamicType()

TypeWithDict edm::ObjectWithDict::dynamicType ( ) const

Definition at line 38 of file ObjectWithDict.cc.

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  }

References address_, edm::TypeWithDict::byTypeInfo(), edm::TypeWithDict::isVirtual(), and 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.

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

References address_.

◆ operator bool()

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

Definition at line 25 of file ObjectWithDict.cc.

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

References electrons_cff::bool.

◆ typeOf()

TypeWithDict edm::ObjectWithDict::typeOf ( ) const

Definition at line 29 of file ObjectWithDict.cc.

29 { return type_; }

References type_.

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

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
electrons_cff.bool
bool
Definition: electrons_cff.py:366
edm::ObjectWithDict::address
void * address() const
Definition: ObjectWithDict.cc:27
to
GetRecoTauVFromDQM_MC_cff.cl
cl
Definition: GetRecoTauVFromDQM_MC_cff.py:38
edm::ObjectWithDict::type_
TypeWithDict type_
Definition: ObjectWithDict.h:19
edm::TypeWithDict::dataMemberByName
MemberWithDict dataMemberByName(std::string const &) const
Definition: TypeWithDict.cc:572
edm::ObjectWithDict::ObjectWithDict
ObjectWithDict()
Definition: ObjectWithDict.cc:18
edm::ObjectWithDict::address_
void * address_
Definition: ObjectWithDict.h:20
edm::MemberWithDict::get
ObjectWithDict get() const
Definition: MemberWithDict.cc:46
edm::TypeWithDict::isVirtual
bool isVirtual() const
Definition: TypeWithDict.cc:429
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::ObjectWithDict::typeOf
TypeWithDict typeOf() const
Definition: ObjectWithDict.cc:29
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
edm::TypeWithDict::getClass
TClass * getClass() const
Definition: TypeWithDict.cc:380
edm::TypeWithDict::byTypeInfo
static TypeWithDict byTypeInfo(std::type_info const &ti)
Definition: TypeWithDict.cc:62
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82