CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 20 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().

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:23
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:24
edm::FunctionWithDict method_
Definition: MethodInvoker.h:22
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:28
TypeWithDict finalReturnType() const
MethodInvoker::MethodInvoker ( const edm::MemberWithDict member)
explicit

Definition at line 40 of file MethodInvoker.cc.

References 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:23
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:24
edm::FunctionWithDict method_
Definition: MethodInvoker.h:22
MethodInvoker::MethodInvoker ( const MethodInvoker rhs)

Definition at line 62 of file MethodInvoker.cc.

References setArgs().

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

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, edm::hlt::Exception, edm::MemberWithDict::get(), edm::errors::InvalidReference, edm::FunctionWithDict::invoke(), isFunction_, edm::TypeWithDict::isPointer(), edm::TypeWithDict::isReference(), member_, method_, methodName(), edm::TypeWithDict::qualifiedName(), run_regression::ret, retTypeFinal_, edm::TypeWithDict::stripConstRef(), edm::TypeWithDict::toType(), edm::ObjectWithDict::typeOf(), and edm::MemberWithDict::typeOf().

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 == 0) {
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:23
TypeWithDict toType() const
edm::FunctionWithDict method_
Definition: MethodInvoker.h:22
ObjectWithDict get() const
TypeWithDict typeOf() const
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:28
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:25
bool isPointer() const
bool reco::parser::MethodInvoker::isFunction ( ) const
inline

Definition at line 41 of file MethodInvoker.h.

References isFunction_.

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

Definition at line 40 of file MethodInvoker.h.

References member_.

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

Definition at line 39 of file MethodInvoker.h.

References method_.

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

Definition at line 99 of file MethodInvoker.cc.

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

Referenced by invoke().

100 {
101  if (isFunction_) {
102  return method_.name();
103  }
104  return member_.name();
105 }
std::string name() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:23
edm::FunctionWithDict method_
Definition: MethodInvoker.h:22
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().

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:23
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:24
edm::FunctionWithDict method_
Definition: MethodInvoker.h:22
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:28
std::string MethodInvoker::returnTypeName ( ) const

Definition at line 109 of file MethodInvoker.cc.

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

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:23
std::string typeName() const
edm::FunctionWithDict method_
Definition: MethodInvoker.h:22
TypeWithDict typeOf() const
void MethodInvoker::setArgs ( )
private

Definition at line 90 of file MethodInvoker.cc.

References args_, i, and ints_.

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 }
int i
Definition: DBlmapReader.cc:9
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:24
std::vector< void * > args_
Definition: MethodInvoker.h:25

Member Data Documentation

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

Definition at line 24 of file MethodInvoker.h.

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

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

Definition at line 27 of file MethodInvoker.h.

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

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

Definition at line 23 of file MethodInvoker.h.

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

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

Definition at line 22 of file MethodInvoker.h.

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

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

Definition at line 28 of file MethodInvoker.h.

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