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 26 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 14 of file MethodInvoker.cc.

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

15  : method_(method), member_(), ints_(ints), isFunction_(true) {
16  setArgs();
17  if (isFunction_) {
19  }
20  //std::cout <<
21  // "Booking " <<
22  // methodName() <<
23  // " from " <<
24  // method_.declaringType().name() <<
25  // " with " <<
26  // args_.size() <<
27  // " arguments" <<
28  // " (were " <<
29  // ints.size() <<
30  // ")" <<
31  // std::endl;
32 }
TypeWithDict finalReturnType() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:29
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:30
edm::FunctionWithDict const method() const
Definition: MethodInvoker.h:46
edm::FunctionWithDict method_
Definition: MethodInvoker.h:28
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:34
ROOT::VecOps::RVec< int > ints
Definition: Resolutions.cc:4

◆ MethodInvoker() [2/3]

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

Definition at line 34 of file MethodInvoker.cc.

References setArgs().

35  : method_(), member_(member), ints_(), isFunction_(false) {
36  setArgs();
37  //std::cout <<
38  // "Booking " <<
39  // methodName() <<
40  // " from " <<
41  // member_.declaringType().name() <<
42  // " with " <<
43  // args_.size() <<
44  // " arguments" <<
45  // " (were " <<
46  // ints.size() <<
47  // ")" <<
48  // std::endl;
49 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:29
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:30
edm::FunctionWithDict method_
Definition: MethodInvoker.h:28
edm::MemberWithDict const member() const
Definition: MethodInvoker.h:47

◆ MethodInvoker() [3/3]

MethodInvoker::MethodInvoker ( const MethodInvoker rhs)

Definition at line 51 of file MethodInvoker.cc.

References setArgs().

52  : method_(rhs.method_),
53  member_(rhs.member_),
54  ints_(rhs.ints_),
57  setArgs();
58 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:29
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:30
edm::FunctionWithDict method_
Definition: MethodInvoker.h:28
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:34

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

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

◆ isFunction()

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

Definition at line 48 of file MethodInvoker.h.

References isFunction_.

48 { return isFunction_; }

◆ member()

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

Definition at line 47 of file MethodInvoker.h.

References member_.

47 { return member_; }
edm::MemberWithDict member_
Definition: MethodInvoker.h:29

◆ method()

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

Definition at line 46 of file MethodInvoker.h.

References method_.

46 { return method_; }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:28

◆ methodName()

std::string MethodInvoker::methodName ( ) const

Definition at line 79 of file MethodInvoker.cc.

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

Referenced by invoke().

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

◆ operator=()

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

Definition at line 60 of file MethodInvoker.cc.

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

60  {
61  if (this != &rhs) {
62  method_ = rhs.method_;
63  member_ = rhs.member_;
64  ints_ = rhs.ints_;
67 
68  setArgs();
69  }
70  return *this;
71 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:29
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:30
edm::FunctionWithDict method_
Definition: MethodInvoker.h:28
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:34

◆ returnTypeName()

std::string MethodInvoker::returnTypeName ( ) const

Definition at line 86 of file MethodInvoker.cc.

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

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

◆ setArgs()

void MethodInvoker::setArgs ( )
private

Definition at line 73 of file MethodInvoker.cc.

References args_, mps_fire::i, and ints_.

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

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

Member Data Documentation

◆ args_

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

Definition at line 31 of file MethodInvoker.h.

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

◆ ints_

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

Definition at line 30 of file MethodInvoker.h.

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

◆ isFunction_

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

Definition at line 33 of file MethodInvoker.h.

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

◆ member_

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

Definition at line 29 of file MethodInvoker.h.

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

◆ method_

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

Definition at line 28 of file MethodInvoker.h.

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

◆ retTypeFinal_

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

Definition at line 34 of file MethodInvoker.h.

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