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
 
edm::MemberWithDict const member () const
 
edm::FunctionWithDict const 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.

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

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 }
TypeWithDict finalReturnType() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:28
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:29
edm::FunctionWithDict const method() const
Definition: MethodInvoker.h:45
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:33

◆ MethodInvoker() [2/3]

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

Definition at line 33 of file MethodInvoker.cc.

References setArgs().

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 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:28
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:29
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
edm::MemberWithDict const member() const
Definition: MethodInvoker.h:46

◆ MethodInvoker() [3/3]

MethodInvoker::MethodInvoker ( const MethodInvoker rhs)

Definition at line 50 of file MethodInvoker.cc.

References setArgs().

51  : method_(rhs.method_),
52  member_(rhs.member_),
53  ints_(rhs.ints_),
56  setArgs();
57 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:28
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:29
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:33

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.

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

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 }
TypeWithDict typeOf() const
ret
prodAgent to be discontinued
std::string methodName() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:28
ObjectWithDict get() const
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:33
void invoke(ObjectWithDict const &obj, ObjectWithDict *ret=nullptr, std::vector< void *> const &values=std::vector< void *>()) const
Call a member function.
TypeWithDict & stripConstRef()
std::vector< void * > args_
Definition: MethodInvoker.h:30
TypeWithDict toType() const
bool isPointer() const
bool isReference() const

◆ isFunction()

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

Definition at line 47 of file MethodInvoker.h.

References isFunction_.

47 { return isFunction_; }

◆ member()

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

Definition at line 46 of file MethodInvoker.h.

References member_.

46 { return member_; }
edm::MemberWithDict member_
Definition: MethodInvoker.h:28

◆ method()

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

Definition at line 45 of file MethodInvoker.h.

References method_.

45 { return method_; }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27

◆ methodName()

std::string MethodInvoker::methodName ( ) const

Definition at line 78 of file MethodInvoker.cc.

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

Referenced by invoke().

78  {
79  if (isFunction_) {
80  return method_.name();
81  }
82  return member_.name();
83 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:28
std::string name() const
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
std::string name() const

◆ operator=()

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

Definition at line 59 of file MethodInvoker.cc.

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

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 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:28
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:29
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:33

◆ returnTypeName()

std::string MethodInvoker::returnTypeName ( ) const

Definition at line 85 of file MethodInvoker.cc.

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

85  {
86  if (isFunction_) {
87  return method_.typeName();
88  }
89  return member_.typeOf().qualifiedName();
90 }
TypeWithDict typeOf() const
std::string qualifiedName() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:28
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
std::string typeName() const

◆ setArgs()

void MethodInvoker::setArgs ( )
private

Definition at line 72 of file MethodInvoker.cc.

References args_, mps_fire::i, and ints_.

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

72  {
73  for (size_t i = 0; i < ints_.size(); ++i) {
74  args_.push_back(std::visit(AnyMethodArgument2VoidPtr(), ints_[i]));
75  }
76 }
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:29
std::vector< void * > args_
Definition: MethodInvoker.h:30

Member Data Documentation

◆ args_

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

Definition at line 30 of file MethodInvoker.h.

Referenced by invoke(), batchmanager.BatchManager::ParseOptions(), and setArgs().

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