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 Struct Reference

#include <MethodInvoker.h>

Public Member Functions

edm::ObjectWithDict invoke (const edm::ObjectWithDict &o, 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 &member)
 
 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_
 

Detailed Description

Definition at line 17 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 12 of file MethodInvoker.cc.

References setArgs().

12  :
13  method_(method), member_(), ints_(ints), isFunction_(true)
14 {
15  setArgs();
16  /*std::cout << "Booking " << methodName()
17  << " from " << method_.declaringType().name()
18  << " with " << args_.size() << " arguments"
19  << " (were " << ints.size() << ")"
20  << std::endl;*/
21 }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:35
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:37
edm::MemberWithDict member_
Definition: MethodInvoker.h:36
MethodInvoker::MethodInvoker ( const edm::MemberWithDict member)
explicit

Definition at line 23 of file MethodInvoker.cc.

References setArgs().

23  :
24  method_(), member_(member), ints_(), isFunction_(false)
25 {
26  setArgs();
27  /*std::cout << "Booking " << methodName()
28  << " from " << member_.declaringType().name()
29  << " with " << args_.size() << " arguments"
30  << " (were " << ints.size() << ")"
31  << std::endl;*/
32 }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:35
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:37
edm::MemberWithDict member_
Definition: MethodInvoker.h:36
MethodInvoker::MethodInvoker ( const MethodInvoker other)

Definition at line 34 of file MethodInvoker.cc.

References setArgs().

34  :
35  method_(other.method_), member_(other.member_), ints_(other.ints_), isFunction_(other.isFunction_) {
36  setArgs();
37 }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:35
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:37
edm::MemberWithDict member_
Definition: MethodInvoker.h:36

Member Function Documentation

edm::ObjectWithDict MethodInvoker::invoke ( const edm::ObjectWithDict o,
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 71 of file MethodInvoker.cc.

References edm::ObjectWithDict::address(), args_, edm::errors::Configuration, edm::hlt::Exception, edm::FunctionWithDict::finalReturnType(), edm::MemberWithDict::get(), edm::errors::InvalidReference, edm::FunctionWithDict::invoke(), isFunction_, edm::TypeWithDict::isPointer(), edm::TypeWithDict::isReference(), dttmaxenums::L, member_, method_, methodName(), edm::TypeWithDict::qualifiedName(), run_regression::ret, edm::TypeWithDict::toType(), edm::ObjectWithDict::typeOf(), and edm::MemberWithDict::typeOf().

71  {
72  edm::ObjectWithDict ret = retstore;
73  edm::TypeWithDict retType;
74  if(isFunction_) {
75  /*std::cout << "Invoking " << methodName()
76  << " from " << method_.declaringType().qualifiedName()
77  << " on an instance of " << o.dynamicType().qualifiedName()
78  << " at " << o.address()
79  << " with " << args_.size() << " arguments"
80  << std::endl; */
81  method_.invoke(o, &ret, args_);
82  retType = method_.finalReturnType(); // this is correct, it takes pointers and refs into account
83  } else {
84  /*std::cout << "Invoking " << methodName()
85  << " from " << member_.declaringType().qualifiedName()
86  << " on an instance of " << o.dynamicType().qualifiedName()
87  << " at " << o.address()
88  << " with " << args_.size() << " arguments"
89  << std::endl; */
90  ret = member_.get(o);
91  retType = member_.typeOf();
92  }
93  void * addr = ret.address();
94  //std::cout << "Stored result of " << methodName() << " (type " << returnTypeName() << ") at " << addr << std::endl;
95  if(addr==0) {
97  << "method \"" << methodName() << "\" called with " << args_.size()
98  << " arguments returned a null pointer ";
99  }
100  //std::cout << "Return type is " << retType.qualifiedName() << std::endl;
101 
102  if(retType.isPointer() || retType.isReference()) { // both need (void **)->(void *) conversion
103  if (retType.isPointer()) {
104  retType = retType.toType(); // for Pointers, I get the real type this way
105  } else {
106  retType = edm::TypeWithDict(retType, 0L); // strip cv & ref flags
107  }
108  ret = edm::ObjectWithDict(retType, *static_cast<void **>(addr));
109  //std::cout << "Now type is " << retType.qualifiedName() << std::endl;
110  }
111  if(!ret) {
113  << "method \"" << methodName()
114  << "\" returned void invoked on object of type \""
115  << o.typeOf().qualifiedName() << "\"\n";
116  }
117  return ret;
118 }
std::vector< void * > args_
Definition: MethodInvoker.h:38
void invoke(ObjectWithDict const &obj, ObjectWithDict *ret, std::vector< void * > const &values=std::vector< void * >()) const
edm::FunctionWithDict method_
Definition: MethodInvoker.h:35
void * address() const
std::string qualifiedName() const
TypeWithDict toType() const
ObjectWithDict get() const
TypeWithDict typeOf() const
TypeWithDict const & typeOf() const
TypeWithDict finalReturnType() const
bool isReference() const
std::string methodName() const
bool isPointer() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:36
bool reco::parser::MethodInvoker::isFunction ( ) const
inline

Definition at line 31 of file MethodInvoker.h.

References isFunction_.

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

Definition at line 29 of file MethodInvoker.h.

References member_.

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

Definition at line 28 of file MethodInvoker.h.

References method_.

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

Definition at line 55 of file MethodInvoker.cc.

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

Referenced by invoke().

55  {
56  if(isFunction_) {
57  return method_.name();
58  }
59  return member_.name();
60 }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:35
std::string name() const
std::string name() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:36
MethodInvoker & MethodInvoker::operator= ( const MethodInvoker other)

Definition at line 39 of file MethodInvoker.cc.

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

39  {
40  method_ = other.method_;
41  member_ = other.member_;
42  ints_ = other.ints_;
43  isFunction_ = other.isFunction_;
44  setArgs();
45  return *this;
46 }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:35
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:37
edm::MemberWithDict member_
Definition: MethodInvoker.h:36
std::string MethodInvoker::returnTypeName ( ) const

Definition at line 63 of file MethodInvoker.cc.

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

63  {
64  if(isFunction_) {
65  return method_.typeOf().qualifiedName();
66  }
67  return member_.typeOf().qualifiedName();
68 }
edm::FunctionWithDict method_
Definition: MethodInvoker.h:35
std::string qualifiedName() const
TypeWithDict typeOf() const
TypeWithDict typeOf() const
edm::MemberWithDict member_
Definition: MethodInvoker.h:36
void MethodInvoker::setArgs ( )
private

Definition at line 48 of file MethodInvoker.cc.

References args_, i, and ints_.

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

48  {
49  for(size_t i = 0; i < ints_.size(); ++i) {
50  args_.push_back( boost::apply_visitor( AnyMethodArgument2VoidPtr(), ints_[i] ) );
51  }
52 }
int i
Definition: DBlmapReader.cc:9
std::vector< void * > args_
Definition: MethodInvoker.h:38
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:37

Member Data Documentation

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

Definition at line 38 of file MethodInvoker.h.

Referenced by invoke(), valtools.webpage::parseArgs(), and setArgs().

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

Definition at line 37 of file MethodInvoker.h.

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

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

Definition at line 39 of file MethodInvoker.h.

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

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

Definition at line 36 of file MethodInvoker.h.

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

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

Definition at line 35 of file MethodInvoker.h.

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