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 
10 
11 #include <boost/shared_ptr.hpp>
12 #include <boost/utility.hpp>
13 
14 #include <map>
15 #include <vector>
16 
17 namespace reco {
18 namespace parser {
19 
21 private: // Private Data Members
24  std::vector<AnyMethodArgument> ints_; // already fixed to the correct type
25  std::vector<void*> args_;
26 
29 private: // Private Function Members
30  void setArgs();
31 public: // Public Function Members
33  const std::vector<AnyMethodArgument>& ints =
34  std::vector<AnyMethodArgument>());
35  explicit MethodInvoker(const edm::MemberWithDict&);
38 
39  edm::FunctionWithDict const method() const { return method_; }
40  edm::MemberWithDict const member() const { return member_; }
41  bool isFunction() const { return isFunction_; }
42  std::string methodName() const;
44 
51  edm::ObjectWithDict& retstore) const;
52 };
53 
58 struct SingleInvoker : boost::noncopyable {
59 private: // Private Data Members
61  std::vector<MethodInvoker> invokers_;
65  bool isRefGet_;
66 public:
68  const std::vector<AnyMethodArgument>& args);
70 
78  std::pair<edm::ObjectWithDict, bool>
80  std::vector<edm::ObjectWithDict>& v) const;
81 
83  double retToDouble(const edm::ObjectWithDict&) const;
84 
85  void throwFailedConversion(const edm::ObjectWithDict&) const;
86 };
87 
88 
90 struct LazyInvoker {
91 private: // Private Data Members
93  std::vector<AnyMethodArgument> argsBeforeFixups_;
94  // the shared ptr is only to make the code exception safe
95  // otherwise I think it could leak if the constructor of
96  // SingleInvoker throws an exception (which can happen)
97  typedef boost::shared_ptr<SingleInvoker> SingleInvokerPtr;
98  mutable std::map<edm::TypeID, SingleInvokerPtr> invokers_;
99 private: // Private Function Members
100  const SingleInvoker& invoker(const edm::TypeWithDict&) const;
101 public: // Public Function Members
102  explicit LazyInvoker(const std::string& name,
103  const std::vector<AnyMethodArgument>& args);
104  ~LazyInvoker();
105 
113  std::vector<edm::ObjectWithDict>& v) const;
114 
116  double invokeLast(const edm::ObjectWithDict& o,
117  std::vector<edm::ObjectWithDict>& v) const;
118 };
119 
120 } // namesapce parser
121 } // namespace reco
122 
123 #endif // CommonTools_Utils_MethodInvoker_h
edm::ObjectWithDict invoke(const edm::ObjectWithDict &obj, edm::ObjectWithDict &retstore) const
method::TypeCode retType_
Definition: MethodInvoker.h:60
bool isRefGet_
true if this invoker just pops out a ref and returns (ref.get(), false)
Definition: MethodInvoker.h:65
SingleInvoker(const edm::TypeWithDict &, const std::string &name, const std::vector< AnyMethodArgument > &args)
std::pair< edm::ObjectWithDict, bool > invoke(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
MethodInvoker(const edm::FunctionWithDict &method, const std::vector< AnyMethodArgument > &ints=std::vector< AnyMethodArgument >())
std::string returnTypeName() const
double invokeLast(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
invoke and coerce result to double
edm::MemberWithDict member_
Definition: MethodInvoker.h:23
boost::shared_ptr< SingleInvoker > SingleInvokerPtr
Definition: MethodInvoker.h:97
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:24
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
Definition: MethodInvoker.h:90
edm::MemberWithDict const member() const
Definition: MethodInvoker.h:40
edm::FunctionWithDict method_
Definition: MethodInvoker.h:22
edm::ObjectWithDict storage_
Definition: MethodInvoker.h:62
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:28
edm::ObjectWithDict invoke(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
MethodInvoker & operator=(const MethodInvoker &)
void throwFailedConversion(const edm::ObjectWithDict &) const
edm::FunctionWithDict const method() const
Definition: MethodInvoker.h:39
const SingleInvoker & invoker(const edm::TypeWithDict &) const
std::string methodName() const
std::vector< void * > args_
Definition: MethodInvoker.h:25
std::vector< AnyMethodArgument > argsBeforeFixups_
Definition: MethodInvoker.h:93
double retToDouble(const edm::ObjectWithDict &) const
convert the output of invoke to a double, if possible
std::vector< MethodInvoker > invokers_
Definition: MethodInvoker.h:61
std::map< edm::TypeID, SingleInvokerPtr > invokers_
Definition: MethodInvoker.h:98
LazyInvoker(const std::string &name, const std::vector< AnyMethodArgument > &args)