CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MethodInvoker.h
Go to the documentation of this file.
1 #ifndef CommonTools_Utils_MethodInvoker_h
2 #define CommonTools_Utils_MethodInvoker_h
9 #include <boost/utility.hpp>
10 #include <boost/shared_ptr.hpp>
11 #include <vector>
12 #include <map>
13 
14 namespace reco {
15  namespace parser {
16 
17  struct MethodInvoker {
19  const std::vector<AnyMethodArgument> & ints = std::vector<AnyMethodArgument>() );
20  explicit MethodInvoker(const edm::MemberWithDict & member);
21  MethodInvoker(const MethodInvoker &);
22 
27  invoke(const edm::ObjectWithDict & o, edm::ObjectWithDict &retstore) const;
28  edm::FunctionWithDict const method() const {return method_;}
29  edm::MemberWithDict const member() const {return member_;}
31  bool isFunction() const {return isFunction_;}
32  std::string methodName() const;
34  private:
37  std::vector<AnyMethodArgument> ints_; // already fixed to the correct type
38  std::vector<void*> args_;
40  void setArgs();
41  };
42 
47  struct SingleInvoker : boost::noncopyable {
49  const std::string &name,
50  const std::vector<AnyMethodArgument> &args) ;
52 
57  std::pair<edm::ObjectWithDict,bool> invoke(const edm::ObjectWithDict & o, std::vector<edm::ObjectWithDict> &v) const;
58 
59  // convert the output of invoke to a double, if possible
60  double retToDouble(const edm::ObjectWithDict & o) const;
61  void throwFailedConversion(const edm::ObjectWithDict & o) const;
62  private:
64  std::vector<MethodInvoker> invokers_;
68  bool isRefGet_;
69  };
70 
71 
73  struct LazyInvoker {
74  explicit LazyInvoker(const std::string &name,
75  const std::vector<AnyMethodArgument> &args);
76  ~LazyInvoker();
81  edm::ObjectWithDict invoke(const edm::ObjectWithDict & o, std::vector<edm::ObjectWithDict> &v) const;
83  double invokeLast(const edm::ObjectWithDict & o, std::vector<edm::ObjectWithDict> &v) const;
84  private:
86  std::vector<AnyMethodArgument> argsBeforeFixups_;
87  typedef boost::shared_ptr<SingleInvoker> SingleInvokerPtr; // the shared ptr is only to make the code exception safe
88  mutable std::map<edm::TypeID, SingleInvokerPtr> invokers_; // otherwise I think it could leak if the constructor of
89  const SingleInvoker & invoker(const edm::TypeWithDict &t) const ; // SingleInvoker throws an exception (which can happen)
90  };
91 
92  }
93 }
94 
95 #endif
SingleInvoker(const edm::TypeWithDict &t, const std::string &name, const std::vector< AnyMethodArgument > &args)
method::TypeCode retType_
Definition: MethodInvoker.h:63
std::vector< void * > args_
Definition: MethodInvoker.h:38
MethodInvoker & operator=(const MethodInvoker &)
MethodInvoker(const edm::FunctionWithDict &method, const std::vector< AnyMethodArgument > &ints=std::vector< AnyMethodArgument >())
edm::FunctionWithDict method_
Definition: MethodInvoker.h:35
bool isRefGet_
true if this invoker just pops out a ref and returns (ref.get(), false)
Definition: MethodInvoker.h:68
std::pair< edm::ObjectWithDict, bool > invoke(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
edm::FunctionWithDict const method() const
Definition: MethodInvoker.h:28
double invokeLast(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
invoke and coerce result to double
boost::shared_ptr< SingleInvoker > SingleInvokerPtr
Definition: MethodInvoker.h:87
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
Definition: MethodInvoker.h:73
edm::ObjectWithDict storage_
Definition: MethodInvoker.h:65
edm::ObjectWithDict invoke(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
std::string returnTypeName() const
double retToDouble(const edm::ObjectWithDict &o) const
edm::ObjectWithDict invoke(const edm::ObjectWithDict &o, edm::ObjectWithDict &retstore) const
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:37
const SingleInvoker & invoker(const edm::TypeWithDict &t) const
void throwFailedConversion(const edm::ObjectWithDict &o) const
std::vector< AnyMethodArgument > argsBeforeFixups_
Definition: MethodInvoker.h:86
std::string methodName() const
std::vector< MethodInvoker > invokers_
Definition: MethodInvoker.h:64
std::map< edm::TypeID, SingleInvokerPtr > invokers_
Definition: MethodInvoker.h:88
LazyInvoker(const std::string &name, const std::vector< AnyMethodArgument > &args)
edm::MemberWithDict member_
Definition: MethodInvoker.h:36
edm::MemberWithDict const member() const
Definition: MethodInvoker.h:29