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

edm::ObjectWithDict::ObjectWithDict ( )

Definition at line 19 of file ObjectWithDict.cc.

Referenced by castObject().

19  : type_(), address_(nullptr) {
20  }
TypeWithDict type_
edm::ObjectWithDict::ObjectWithDict ( TypeWithDict const &  type,
void *  address 
)
explicit

Definition at line 22 of file ObjectWithDict.cc.

22  :
23  type_(type),
24  address_(address) {
25  }
type
Definition: HCALResponse.h:21
void * address() const
TypeWithDict type_
edm::ObjectWithDict::ObjectWithDict ( std::type_info const &  ti,
void *  address 
)
explicit

Definition at line 27 of file ObjectWithDict.cc.

27  :
28  type_(TypeWithDict(ti)),
29  address_(address) {
30  }
void * address() const
TypeWithDict type_

Member Function Documentation

void * edm::ObjectWithDict::address ( ) const
ObjectWithDict edm::ObjectWithDict::byType ( TypeWithDict const &  type)
static
ObjectWithDict edm::ObjectWithDict::castObject ( TypeWithDict const &  to) const

Definition at line 70 of file ObjectWithDict.cc.

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

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

70  {
71  TypeWithDict from = typeOf();
72 
73  // Same type
74  if (from == to) {
75  return *this;
76  }
77 
78  if (to.hasBase(from)) { // down cast
79 #ifndef _LIBCPP_VERSION
80  // use the internal dynamic casting of the compiler (e.g. libstdc++.so)
81  void* address = abi::__dynamic_cast(address_, static_cast<abi::__class_type_info const*>(&from.typeInfo()), static_cast<abi::__class_type_info const*>(&to.typeInfo()), -1);
82  return ObjectWithDict(to, address);
83 #else
84  return ObjectWithDict(to, address_);
85 #endif
86  }
87 
88  if (from.hasBase(to)) { // up cast
89  size_t offset = from.getBaseClassOffset(to);
90  size_t address = reinterpret_cast<size_t>(address_) + offset;
91  return ObjectWithDict(to, reinterpret_cast<void*>(address));
92  }
93 
94  // if everything fails return the dummy object
95  return ObjectWithDict();
96  } // castObject
void * address() const
TypeWithDict typeOf() const
void edm::ObjectWithDict::destruct ( bool  dealloc) const

Definition at line 109 of file ObjectWithDict.cc.

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

Referenced by reco::parser::ExpressionLazyVar::value(), and fwlite::internal::Data::~Data().

109  {
110  TClass* cl = type_.getClass();
111  if (cl != nullptr) {
112  cl->Destructor(address_, !dealloc);
113  //if (dealloc) {
114  // address_ = nullptr;
115  //}
116  return;
117  }
118  if (dealloc) {
119  delete[] reinterpret_cast<char*>(address_);
120  //address_ = nullptr;
121  }
122  }
TClass * getClass() const
TypeWithDict type_
TypeWithDict edm::ObjectWithDict::dynamicType ( ) const

Definition at line 55 of file ObjectWithDict.cc.

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

Referenced by fwlite::RecordWriter::update().

55  {
56  if (!type_.isVirtual()) {
57  return type_;
58  }
59  // Use a dirty trick, force the typeid() operator
60  // to consult the virtual table stored at address_.
61  return TypeWithDict(typeid(*(DummyVT*)address_));
62  }
bool isVirtual() const
TypeWithDict type_
ObjectWithDict edm::ObjectWithDict::get ( std::string const &  memberName) const
template<typename T >
T edm::ObjectWithDict::objectCast ( )
inline

Definition at line 37 of file ObjectWithDict.h.

References address_.

37  {
38  return *reinterpret_cast<T*>(address_);
39  }
long double T
edm::ObjectWithDict::operator bool ( ) const
explicit

Definition at line 32 of file ObjectWithDict.cc.

References address_, electrons_cff::bool, and type_.

32  {
33  return bool(type_) && (address_ != nullptr);
34  }
TypeWithDict type_
TypeWithDict edm::ObjectWithDict::typeOf ( ) const

Member Data Documentation

void* edm::ObjectWithDict::address_
private

Definition at line 20 of file ObjectWithDict.h.

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

TypeWithDict edm::ObjectWithDict::type_
private