CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 17 of file ObjectWithDict.cc.

Referenced by castObject().

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

Definition at line 20 of file ObjectWithDict.cc.

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

Definition at line 25 of file ObjectWithDict.cc.

25  :
26  type_(TypeWithDict(ti)),
27  address_(address) {
28  }
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 68 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().

68  {
69  TypeWithDict from = typeOf();
70 
71  // Same type
72  if (from == to) {
73  return *this;
74  }
75 
76  if (to.hasBase(from)) { // down cast
77  // use the internal dynamic casting of the compiler (e.g. libstdc++.so)
78  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);
79  return ObjectWithDict(to, address);
80  }
81 
82  if (from.hasBase(to)) { // up cast
83  size_t offset = from.getBaseClassOffset(to);
84  size_t address = reinterpret_cast<size_t>(address_) + offset;
85  return ObjectWithDict(to, reinterpret_cast<void*>(address));
86  }
87 
88  // if everything fails return the dummy object
89  return ObjectWithDict();
90  } // castObject
void * address() const
TypeWithDict typeOf() const
void edm::ObjectWithDict::destruct ( bool  dealloc) const

Definition at line 103 of file ObjectWithDict.cc.

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

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

103  {
104  TClass* cl = type_.getClass();
105  if (cl != nullptr) {
106  cl->Destructor(address_, !dealloc);
107  //if (dealloc) {
108  // address_ = nullptr;
109  //}
110  return;
111  }
112  if (dealloc) {
113  delete[] reinterpret_cast<char*>(address_);
114  //address_ = nullptr;
115  }
116  }
TClass * getClass() const
TypeWithDict type_
TypeWithDict edm::ObjectWithDict::dynamicType ( ) const

Definition at line 53 of file ObjectWithDict.cc.

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

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

53  {
54  if (!type_.isVirtual()) {
55  return type_;
56  }
57  // Use a dirty trick, force the typeid() operator
58  // to consult the virtual table stored at address_.
59  return TypeWithDict(typeid(*(DummyVT*)address_));
60  }
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 30 of file ObjectWithDict.cc.

30  {
31  return bool(type_) && (address_ != nullptr);
32  }
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(), and objectCast().

TypeWithDict edm::ObjectWithDict::type_
private