CMS 3D CMS Logo

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 #include "tbb/concurrent_unordered_map.h"
18 
19 namespace edm {
20  struct TypeIDHasher {
21  size_t operator()(TypeID const& tid) const {
22  tbb::tbb_hash<std::string> hasher;
23  return hasher(std::string(tid.name()));
24  }
25  };
26 }
27 
28 namespace reco {
29 namespace parser {
30 
32 private: // Private Data Members
35  std::vector<AnyMethodArgument> ints_; // already fixed to the correct type
36  std::vector<void*> args_;
37 
40 private: // Private Function Members
41  void setArgs();
42 public: // Public Function Members
44  const std::vector<AnyMethodArgument>& ints =
45  std::vector<AnyMethodArgument>());
46  explicit MethodInvoker(const edm::MemberWithDict&);
48  MethodInvoker& operator=(const MethodInvoker&);
49 
50  edm::FunctionWithDict const method() const { return method_; }
51  edm::MemberWithDict const member() const { return member_; }
52  bool isFunction() const { return isFunction_; }
53  std::string methodName() const;
54  std::string returnTypeName() const;
55 
62  edm::ObjectWithDict& retstore) const;
63 };
64 
69 struct SingleInvoker : boost::noncopyable {
70 private: // Private Data Members
72  std::vector<MethodInvoker> invokers_;
76  bool isRefGet_;
77 public:
79  const std::vector<AnyMethodArgument>& args);
80  ~SingleInvoker();
81 
89  std::pair<edm::ObjectWithDict, bool>
90  invoke(const edm::ObjectWithDict& o,
91  std::vector<edm::ObjectWithDict>& v) const;
92 
94  double retToDouble(const edm::ObjectWithDict&) const;
95 
96  void throwFailedConversion(const edm::ObjectWithDict&) const;
97 };
98 
99 
101 struct LazyInvoker {
102  typedef std::shared_ptr<SingleInvoker> SingleInvokerPtr;
103  typedef tbb::concurrent_unordered_map<edm::TypeID, SingleInvokerPtr,edm::TypeIDHasher> InvokerMap;
104 private: // Private Data Members
106  std::vector<AnyMethodArgument> argsBeforeFixups_;
107  // the shared ptr is only to make the code exception safe
108  // otherwise I think it could leak if the constructor of
109  // SingleInvoker throws an exception (which can happen)
110  mutable InvokerMap invokers_;
111 private: // Private Function Members
112  const SingleInvoker& invoker(const edm::TypeWithDict&) const;
113 public: // Public Function Members
114  explicit LazyInvoker(const std::string& name,
115  const std::vector<AnyMethodArgument>& args);
116  ~LazyInvoker();
117 
125  std::vector<edm::ObjectWithDict>& v) const;
126 
128  double invokeLast(const edm::ObjectWithDict& o,
129  std::vector<edm::ObjectWithDict>& v) const;
130 };
131 
132 } // namesapce parser
133 } // namespace reco
134 
135 #endif // CommonTools_Utils_MethodInvoker_h
method::TypeCode retType_
Definition: MethodInvoker.h:71
bool isRefGet_
true if this invoker just pops out a ref and returns (ref.get(), false)
Definition: MethodInvoker.h:76
edm::MemberWithDict member_
Definition: MethodInvoker.h:34
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:35
size_t operator()(TypeID const &tid) const
Definition: MethodInvoker.h:21
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke() ...
std::shared_ptr< SingleInvoker > SingleInvokerPtr
edm::MemberWithDict const member() const
Definition: MethodInvoker.h:51
tbb::concurrent_unordered_map< edm::TypeID, SingleInvokerPtr, edm::TypeIDHasher > InvokerMap
edm::FunctionWithDict method_
Definition: MethodInvoker.h:33
edm::ObjectWithDict storage_
Definition: MethodInvoker.h:73
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:39
edm::FunctionWithDict const method() const
Definition: MethodInvoker.h:50
fixed size matrix
std::vector< void * > args_
Definition: MethodInvoker.h:36
HLT enums.
std::vector< AnyMethodArgument > argsBeforeFixups_
std::vector< MethodInvoker > invokers_
Definition: MethodInvoker.h:72
const char * name() const
Definition: TypeIDBase.h:52