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 31 of file MethodInvoker.h.

Constructor & Destructor Documentation

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

Referenced by MethodInvoker().

16  : method_(method)
17  , member_()
18  , ints_(ints)
19  , isFunction_(true)
20 {
21  setArgs();
22  if (isFunction_) {
24  }
25  //std::cout <<
26  // "Booking " <<
27  // methodName() <<
28  // " from " <<
29  // method_.declaringType().name() <<
30  // " with " <<
31  // args_.size() <<
32  // " arguments" <<
33  // " (were " <<
34  // ints.size() <<
35  // ")" <<
36  // std::endl;
37 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:35
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:39
TypeWithDict finalReturnType() const
MethodInvoker::MethodInvoker ( const edm::MemberWithDict member)
explicit

Definition at line 40 of file MethodInvoker.cc.

References MethodInvoker(), and setArgs().

41  : method_()
42  , member_(member)
43  , ints_()
44  , isFunction_(false)
45 {
46  setArgs();
47  //std::cout <<
48  // "Booking " <<
49  // methodName() <<
50  // " from " <<
51  // member_.declaringType().name() <<
52  // " with " <<
53  // args_.size() <<
54  // " arguments" <<
55  // " (were " <<
56  // ints.size() <<
57  // ")" <<
58  // std::endl;
59 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:35
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
MethodInvoker::MethodInvoker ( const MethodInvoker rhs)

Definition at line 62 of file MethodInvoker.cc.

References operator=(), and setArgs().

63  : method_(rhs.method_)
64  , member_(rhs.member_)
65  , ints_(rhs.ints_)
68 {
69  setArgs();
70 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:35
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:39

Member Function Documentation

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

References edm::ObjectWithDict::address(), args_, edm::errors::Configuration, Exception, edm::MemberWithDict::get(), edm::errors::InvalidReference, edm::FunctionWithDict::invoke(), isFunction_, edm::TypeWithDict::isPointer(), edm::TypeWithDict::isReference(), reco::parser::LazyInvoker::LazyInvoker(), member_, method_, methodName(), edm::TypeWithDict::qualifiedName(), retTypeFinal_, edm::TypeWithDict::stripConstRef(), edm::TypeWithDict::toType(), edm::ObjectWithDict::typeOf(), and edm::MemberWithDict::typeOf().

Referenced by returnTypeName().

120 {
121  edm::ObjectWithDict ret = retstore;
122  edm::TypeWithDict retType;
123  if (isFunction_) {
124  //std::cout << "Invoking " << methodName()
125  // << " from " << method_.declaringType().qualifiedName()
126  // << " on an instance of " << o.dynamicType().qualifiedName()
127  // << " at " << o.address()
128  // << " with " << args_.size() << " arguments"
129  // << std::endl;
130  method_.invoke(o, &ret, args_);
131  // this is correct, it takes pointers and refs into account
132  retType = retTypeFinal_;
133  }
134  else {
135  //std::cout << "Invoking " << methodName()
136  // << " from " << member_.declaringType().qualifiedName()
137  // << " on an instance of " << o.dynamicType().qualifiedName()
138  // << " at " << o.address()
139  // << " with " << args_.size() << " arguments"
140  // << std::endl;
141  ret = member_.get(o);
142  retType = member_.typeOf();
143  }
144  void* addr = ret.address();
145  //std::cout << "Stored result of " << methodName() << " (type " <<
146  // returnTypeName() << ") at " << addr << std::endl;
147  if (addr == nullptr) {
149  << "method \"" << methodName() << "\" called with " << args_.size()
150  << " arguments returned a null pointer ";
151  }
152  //std::cout << "Return type is " << retType.qualifiedName() << std::endl;
153  if (retType.isPointer() || retType.isReference()) {
154  // both need void** -> void* conversion
155  if (retType.isPointer()) {
156  retType = retType.toType();
157  }
158  else {
159  // strip cv & ref flags
160  // FIXME: This is only true if the propery passed to the constructor
161  // overrides the const and reference flags.
162  retType = retType.stripConstRef();
163  }
164  ret = edm::ObjectWithDict(retType, *static_cast<void**>(addr));
165  //std::cout << "Now type is " << retType.qualifiedName() << std::endl;
166  }
167  if (!bool(ret)) {
169  << "method \"" << methodName()
170  << "\" returned void invoked on object of type \""
171  << o.typeOf().qualifiedName() << "\"\n";
172  }
173  return ret;
174 }
void * address() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
TypeWithDict toType() const
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
ObjectWithDict get() const
TypeWithDict typeOf() const
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:39
void invoke(ObjectWithDict const &obj, ObjectWithDict *ret=nullptr, std::vector< void * > const &values=std::vector< void * >()) const
Call a member function.
bool isReference() const
TypeWithDict & stripConstRef()
std::string methodName() const
std::vector< void * > args_
Definition: MethodInvoker.h:36
bool isPointer() const
bool reco::parser::MethodInvoker::isFunction ( ) const
inline

Definition at line 52 of file MethodInvoker.h.

References hgcalPlots::obj, and AlCaHLTBitMon_QueryRunRegistry::string.

52 { return isFunction_; }
edm::MemberWithDict const reco::parser::MethodInvoker::member ( ) const
inline

Definition at line 51 of file MethodInvoker.h.

51 { return member_; }
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
edm::FunctionWithDict const reco::parser::MethodInvoker::method ( ) const
inline

Definition at line 50 of file MethodInvoker.h.

50 { return method_; }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
std::string MethodInvoker::methodName ( ) const

Definition at line 99 of file MethodInvoker.cc.

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

Referenced by invoke(), and setArgs().

100 {
101  if (isFunction_) {
102  return method_.name();
103  }
104  return member_.name();
105 }
std::string name() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
std::string name() const
MethodInvoker & MethodInvoker::operator= ( const MethodInvoker rhs)

Definition at line 74 of file MethodInvoker.cc.

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

Referenced by MethodInvoker().

75 {
76  if (this != &rhs) {
77  method_ = rhs.method_;
78  member_ = rhs.member_;
79  ints_ = rhs.ints_;
82 
83  setArgs();
84  }
85  return *this;
86 }
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:35
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:39
std::string MethodInvoker::returnTypeName ( ) const

Definition at line 109 of file MethodInvoker.cc.

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

Referenced by methodName().

110 {
111  if (isFunction_) {
112  return method_.typeName();
113  }
114  return member_.typeOf().qualifiedName();
115 }
std::string qualifiedName() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
std::string typeName() const
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
TypeWithDict typeOf() const
void MethodInvoker::setArgs ( )
private

Definition at line 90 of file MethodInvoker.cc.

References args_, mps_fire::i, ints_, methodName(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

91 {
92  for (size_t i = 0; i < ints_.size(); ++i) {
93  args_.push_back(boost::apply_visitor(AnyMethodArgument2VoidPtr(), ints_[i]));
94  }
95 }
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:35
std::vector< void * > args_
Definition: MethodInvoker.h:36

Member Data Documentation

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

Definition at line 35 of file MethodInvoker.h.

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

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

Definition at line 38 of file MethodInvoker.h.

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

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

Definition at line 34 of file MethodInvoker.h.

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

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

Definition at line 33 of file MethodInvoker.h.

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

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

Definition at line 39 of file MethodInvoker.h.

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