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
3 #include "Reflex/Object.h"
4 #include "Reflex/Member.h"
7 #include <boost/utility.hpp>
8 #include <boost/shared_ptr.hpp>
9 #include <vector>
10 #include <map>
11 
12 namespace reco {
13  namespace parser {
14 
15  struct MethodInvoker {
16  explicit MethodInvoker(const Reflex::Member & method,
17  const std::vector<AnyMethodArgument> & ints = std::vector<AnyMethodArgument>() );
18  MethodInvoker(const MethodInvoker &);
19 
23  Reflex::Object
24  invoke(const Reflex::Object & o, Reflex::Object &retstore) const;
25  const Reflex::Member & method() const { return method_; }
27  private:
28  Reflex::Member method_;
29  std::vector<AnyMethodArgument> ints_; // already fixed to the correct type
30  std::vector<void*> args_;
32  void setArgs();
33  };
34 
39  struct SingleInvoker : boost::noncopyable {
41  const std::string &name,
42  const std::vector<AnyMethodArgument> &args) ;
44 
49  std::pair<Reflex::Object,bool> invoke(const Reflex::Object & o, std::vector<Reflex::Object> &v) const;
50 
51  // convert the output of invoke to a double, if possible
52  double retToDouble(const Reflex::Object & o) const;
53  void throwFailedConversion(const Reflex::Object & o) const;
54  private:
56  std::vector<MethodInvoker> invokers_;
57  mutable Reflex::Object storage_;
60  bool isRefGet_;
61  };
62 
63 
65  struct LazyInvoker {
66  explicit LazyInvoker(const std::string &name,
67  const std::vector<AnyMethodArgument> &args);
68  ~LazyInvoker();
73  Reflex::Object invoke(const Reflex::Object & o, std::vector<Reflex::Object> &v) const;
75  double invokeLast(const Reflex::Object & o, std::vector<Reflex::Object> &v) const;
76  private:
77  std::string name_;
78  std::vector<AnyMethodArgument> argsBeforeFixups_;
79  typedef boost::shared_ptr<SingleInvoker> SingleInvokerPtr; // the shared ptr is only to make the code exception safe
80  mutable std::map<void *, SingleInvokerPtr> invokers_; // otherwise I think it could leak if the constructor of
81  const SingleInvoker & invoker(const Reflex::Type &t) const ; // SingleInvoker throws an exception (which can happen)
82  };
83 
84  }
85 }
86 
87 #endif
std::map< void *, SingleInvokerPtr > invokers_
Definition: MethodInvoker.h:80
method::TypeCode retType_
Definition: MethodInvoker.h:55
std::vector< void * > args_
Definition: MethodInvoker.h:30
MethodInvoker & operator=(const MethodInvoker &)
bool isRefGet_
true if this invoker just pops out a ref and returns (ref.get(), false)
Definition: MethodInvoker.h:60
MethodInvoker(const Reflex::Member &method, const std::vector< AnyMethodArgument > &ints=std::vector< AnyMethodArgument >())
double retToDouble(const Reflex::Object &o) const
Reflex::Object invoke(const Reflex::Object &o, Reflex::Object &retstore) const
boost::shared_ptr< SingleInvoker > SingleInvokerPtr
Definition: MethodInvoker.h:79
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
Definition: MethodInvoker.h:65
double invokeLast(const Reflex::Object &o, std::vector< Reflex::Object > &v) const
invoke and coerce result to double
Reflex::Object invoke(const Reflex::Object &o, std::vector< Reflex::Object > &v) const
std::pair< Reflex::Object, bool > invoke(const Reflex::Object &o, std::vector< Reflex::Object > &v) const
SingleInvoker(const Reflex::Type &t, const std::string &name, const std::vector< AnyMethodArgument > &args)
const SingleInvoker & invoker(const Reflex::Type &t) const
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:29
dictionary args
void throwFailedConversion(const Reflex::Object &o) const
std::vector< AnyMethodArgument > argsBeforeFixups_
Definition: MethodInvoker.h:78
std::vector< MethodInvoker > invokers_
Definition: MethodInvoker.h:56
const Reflex::Member & method() const
Definition: MethodInvoker.h:25
mathSSE::Vec4< T > v
LazyInvoker(const std::string &name, const std::vector< AnyMethodArgument > &args)