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 18 of file ObjectWithDict.cc.

Referenced by castObject().

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

Definition at line 20 of file ObjectWithDict.cc.

20 : type_(type), address_(address) {}
type
Definition: HCALResponse.h:21
void * address() const
TypeWithDict type_
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

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

Definition at line 13 of file ObjectWithDict.cc.

References edm::TypeWithDict::construct(), and haddnano::obj.

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

13  {
14  ObjectWithDict obj(type.construct());
15  return obj;
16  }
type
Definition: HCALResponse.h:21
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(), PFRecoTauDiscriminationByIsolation_cfi::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
void * address() const
TypeWithDict typeOf() const
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 reco::parser::ExpressionLazyVar::value(), and 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_
TypeWithDict edm::ObjectWithDict::dynamicType ( ) const

Definition at line 38 of file ObjectWithDict.cc.

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

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

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_
ObjectWithDict edm::ObjectWithDict::get ( std::string const &  memberName) const
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
edm::ObjectWithDict::operator bool ( ) const
explicit

Definition at line 25 of file ObjectWithDict.cc.

References address_, electrons_cff::bool, and type_.

25 { return bool(type_) && (address_ != nullptr); }
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