CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
reco::parser::MethodInvoker Class Reference

#include <MethodInvoker.h>

Public Member Functions

edm::ObjectWithDict invoke (const edm::ObjectWithDict &obj, edm::ObjectWithDict &retstore) const
 
bool isFunction () const
 
const edm::MemberWithDict member () const
 
const edm::FunctionWithDict method () const
 
 MethodInvoker (const edm::FunctionWithDict &method, const std::vector< AnyMethodArgument > &ints=std::vector< AnyMethodArgument >())
 
 MethodInvoker (const edm::MemberWithDict &)
 
 MethodInvoker (const MethodInvoker &)
 
std::string methodName () const
 
MethodInvokeroperator= (const MethodInvoker &)
 
std::string returnTypeName () const
 

Private Member Functions

void setArgs ()
 

Private Attributes

std::vector< void * > args_
 
std::vector< AnyMethodArgumentints_
 
bool isFunction_
 
edm::MemberWithDict member_
 
edm::FunctionWithDict method_
 
edm::TypeWithDict retTypeFinal_
 

Detailed Description

Definition at line 25 of file MethodInvoker.h.

Constructor & Destructor Documentation

◆ MethodInvoker() [1/3]

MethodInvoker::MethodInvoker ( const edm::FunctionWithDict method,
const std::vector< AnyMethodArgument > &  ints = std::vector<AnyMethodArgument>() 
)
explicit

Definition at line 13 of file MethodInvoker.cc.

14  : method_(method), member_(), ints_(ints), isFunction_(true) {
15  setArgs();
16  if (isFunction_) {
18  }
19  //std::cout <<
20  // "Booking " <<
21  // methodName() <<
22  // " from " <<
23  // method_.declaringType().name() <<
24  // " with " <<
25  // args_.size() <<
26  // " arguments" <<
27  // " (were " <<
28  // ints.size() <<
29  // ")" <<
30  // std::endl;
31 }

References edm::FunctionWithDict::finalReturnType(), isFunction_, method_, retTypeFinal_, and setArgs().

◆ MethodInvoker() [2/3]

MethodInvoker::MethodInvoker ( const edm::MemberWithDict member)
explicit

Definition at line 33 of file MethodInvoker.cc.

34  : method_(), member_(member), ints_(), isFunction_(false) {
35  setArgs();
36  //std::cout <<
37  // "Booking " <<
38  // methodName() <<
39  // " from " <<
40  // member_.declaringType().name() <<
41  // " with " <<
42  // args_.size() <<
43  // " arguments" <<
44  // " (were " <<
45  // ints.size() <<
46  // ")" <<
47  // std::endl;
48 }

References setArgs().

◆ MethodInvoker() [3/3]

MethodInvoker::MethodInvoker ( const MethodInvoker rhs)

Definition at line 50 of file MethodInvoker.cc.

51  : method_(rhs.method_),
52  member_(rhs.member_),
53  ints_(rhs.ints_),
56  setArgs();
57 }

References setArgs().

Member Function Documentation

◆ invoke()

edm::ObjectWithDict MethodInvoker::invoke ( const edm::ObjectWithDict obj,
edm::ObjectWithDict retstore 
) const

Invokes the method, putting the result in retval. Returns the Object that points to the result value, after removing any "*" and "&" Caller code is responsible for allocating retstore before calling 'invoke', and of deallocating it afterwards

Definition at line 92 of file MethodInvoker.cc.

92  {
93  edm::ObjectWithDict ret = retstore;
94  edm::TypeWithDict retType;
95  if (isFunction_) {
96  //std::cout << "Invoking " << methodName()
97  // << " from " << method_.declaringType().qualifiedName()
98  // << " on an instance of " << o.dynamicType().qualifiedName()
99  // << " at " << o.address()
100  // << " with " << args_.size() << " arguments"
101  // << std::endl;
102  method_.invoke(o, &ret, args_);
103  // this is correct, it takes pointers and refs into account
104  retType = retTypeFinal_;
105  } else {
106  //std::cout << "Invoking " << methodName()
107  // << " from " << member_.declaringType().qualifiedName()
108  // << " on an instance of " << o.dynamicType().qualifiedName()
109  // << " at " << o.address()
110  // << " with " << args_.size() << " arguments"
111  // << std::endl;
112  ret = member_.get(o);
113  retType = member_.typeOf();
114  }
115  void* addr = ret.address();
116  //std::cout << "Stored result of " << methodName() << " (type " <<
117  // returnTypeName() << ") at " << addr << std::endl;
118  if (addr == nullptr) {
120  << "method \"" << methodName() << "\" called with " << args_.size() << " arguments returned a null pointer ";
121  }
122  //std::cout << "Return type is " << retType.qualifiedName() << std::endl;
123  if (retType.isPointer() || retType.isReference()) {
124  // both need void** -> void* conversion
125  if (retType.isPointer()) {
126  retType = retType.toType();
127  } else {
128  // strip cv & ref flags
129  // FIXME: This is only true if the propery passed to the constructor
130  // overrides the const and reference flags.
131  retType = retType.stripConstRef();
132  }
133  ret = edm::ObjectWithDict(retType, *static_cast<void**>(addr));
134  //std::cout << "Now type is " << retType.qualifiedName() << std::endl;
135  }
136  if (!bool(ret)) {
138  << "method \"" << methodName() << "\" returned void invoked on object of type \"" << o.typeOf().qualifiedName()
139  << "\"\n";
140  }
141  return ret;
142 }

References generateTowerEtThresholdLUT::addr, args_, edm::errors::Configuration, Exception, edm::MemberWithDict::get(), edm::errors::InvalidReference, edm::FunctionWithDict::invoke(), isFunction_, edm::TypeWithDict::isPointer(), edm::TypeWithDict::isReference(), member_, method_, methodName(), EcalTangentSkim_cfg::o, runTheMatrix::ret, retTypeFinal_, edm::TypeWithDict::stripConstRef(), edm::TypeWithDict::toType(), and edm::MemberWithDict::typeOf().

◆ isFunction()

bool reco::parser::MethodInvoker::isFunction ( ) const
inline

Definition at line 47 of file MethodInvoker.h.

47 { return isFunction_; }

References isFunction_.

◆ member()

const edm::MemberWithDict reco::parser::MethodInvoker::member ( ) const
inline

Definition at line 46 of file MethodInvoker.h.

46 { return member_; }

References member_.

◆ method()

const edm::FunctionWithDict reco::parser::MethodInvoker::method ( ) const
inline

Definition at line 45 of file MethodInvoker.h.

45 { return method_; }

References method_.

◆ methodName()

std::string MethodInvoker::methodName ( ) const

Definition at line 78 of file MethodInvoker.cc.

78  {
79  if (isFunction_) {
80  return method_.name();
81  }
82  return member_.name();
83 }

References isFunction_, member_, method_, edm::MemberWithDict::name(), and edm::FunctionWithDict::name().

Referenced by invoke().

◆ operator=()

MethodInvoker & MethodInvoker::operator= ( const MethodInvoker rhs)

Definition at line 59 of file MethodInvoker.cc.

59  {
60  if (this != &rhs) {
61  method_ = rhs.method_;
62  member_ = rhs.member_;
63  ints_ = rhs.ints_;
66 
67  setArgs();
68  }
69  return *this;
70 }

References ints_, isFunction_, member_, method_, retTypeFinal_, and setArgs().

◆ returnTypeName()

std::string MethodInvoker::returnTypeName ( ) const

Definition at line 85 of file MethodInvoker.cc.

85  {
86  if (isFunction_) {
87  return method_.typeName();
88  }
89  return member_.typeOf().qualifiedName();
90 }

References isFunction_, member_, method_, edm::TypeWithDict::qualifiedName(), edm::FunctionWithDict::typeName(), and edm::MemberWithDict::typeOf().

◆ setArgs()

void MethodInvoker::setArgs ( )
private

Definition at line 72 of file MethodInvoker.cc.

72  {
73  for (size_t i = 0; i < ints_.size(); ++i) {
74  args_.push_back(std::visit(AnyMethodArgument2VoidPtr(), ints_[i]));
75  }
76 }

References args_, mps_fire::i, and ints_.

Referenced by MethodInvoker(), and operator=().

Member Data Documentation

◆ args_

std::vector<void*> reco::parser::MethodInvoker::args_
private

◆ ints_

std::vector<AnyMethodArgument> reco::parser::MethodInvoker::ints_
private

Definition at line 29 of file MethodInvoker.h.

Referenced by operator=(), and setArgs().

◆ isFunction_

bool reco::parser::MethodInvoker::isFunction_
private

Definition at line 32 of file MethodInvoker.h.

Referenced by invoke(), isFunction(), MethodInvoker(), methodName(), operator=(), and returnTypeName().

◆ member_

edm::MemberWithDict reco::parser::MethodInvoker::member_
private

Definition at line 28 of file MethodInvoker.h.

Referenced by invoke(), member(), methodName(), operator=(), and returnTypeName().

◆ method_

edm::FunctionWithDict reco::parser::MethodInvoker::method_
private

Definition at line 27 of file MethodInvoker.h.

Referenced by invoke(), method(), MethodInvoker(), methodName(), operator=(), and returnTypeName().

◆ retTypeFinal_

edm::TypeWithDict reco::parser::MethodInvoker::retTypeFinal_
private

Definition at line 33 of file MethodInvoker.h.

Referenced by invoke(), MethodInvoker(), and operator=().

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
mps_fire.i
i
Definition: mps_fire.py:428
reco::parser::MethodInvoker::retTypeFinal_
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:33
reco::parser::MethodInvoker::methodName
std::string methodName() const
Definition: MethodInvoker.cc:78
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::ObjectWithDict
Definition: ObjectWithDict.h:17
reco::parser::MethodInvoker::member
const edm::MemberWithDict member() const
Definition: MethodInvoker.h:46
edm::FunctionWithDict::invoke
void invoke(ObjectWithDict const &obj, ObjectWithDict *ret=nullptr, std::vector< void * > const &values=std::vector< void * >()) const
Call a member function.
Definition: FunctionWithDict.cc:74
reco::parser::MethodInvoker::method_
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
edm::TypeWithDict::stripConstRef
TypeWithDict & stripConstRef()
Definition: TypeWithDict.cc:254
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
edm::TypeWithDict::qualifiedName
std::string qualifiedName() const
Definition: TypeWithDict.cc:441
reco::parser::MethodInvoker::method
const edm::FunctionWithDict method() const
Definition: MethodInvoker.h:45
reco::parser::MethodInvoker::isFunction_
bool isFunction_
Definition: MethodInvoker.h:32
generateTowerEtThresholdLUT.addr
addr
Definition: generateTowerEtThresholdLUT.py:57
edm::TypeWithDict::isPointer
bool isPointer() const
Definition: TypeWithDict.cc:416
edm::TypeWithDict::isReference
bool isReference() const
Definition: TypeWithDict.cc:418
edm::MemberWithDict::get
ObjectWithDict get() const
Definition: MemberWithDict.cc:46
edm::MemberWithDict::typeOf
TypeWithDict typeOf() const
Definition: MemberWithDict.cc:18
edm::FunctionWithDict::typeName
std::string typeName() const
Definition: FunctionWithDict.cc:38
reco::parser::MethodInvoker::args_
std::vector< void * > args_
Definition: MethodInvoker.h:30
edm::TypeWithDict
Definition: TypeWithDict.h:38
edm::TypeWithDict::toType
TypeWithDict toType() const
Definition: TypeWithDict.cc:633
reco::parser::AnyMethodArgument2VoidPtr
Definition: AnyMethodArgument.h:132
reco::parser::MethodInvoker::setArgs
void setArgs()
Definition: MethodInvoker.cc:72
edm::MemberWithDict::name
std::string name() const
Definition: MemberWithDict.cc:16
reco::parser::MethodInvoker::ints_
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:29
Exception
Definition: hltDiff.cc:245
reco::parser::MethodInvoker::member_
edm::MemberWithDict member_
Definition: MethodInvoker.h:28
edm::FunctionWithDict::name
std::string name() const
Definition: FunctionWithDict.cc:36
edm::FunctionWithDict::finalReturnType
TypeWithDict finalReturnType() const
Definition: FunctionWithDict.cc:40
edm::errors::Configuration
Definition: EDMException.h:36