Scorum
evaluator.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 namespace scorum {
6 namespace chain {
7 
8 struct data_service_factory_i;
9 class database;
10 
11 template <typename OperationType = scorum::protocol::operation> class evaluator
12 {
13 public:
14  virtual ~evaluator() = default;
15  virtual void apply(const OperationType& op) = 0;
16 };
17 
18 template <typename DataServices, typename EvaluatorType, typename OperationType = scorum::protocol::operation>
19 class evaluator_impl : public evaluator<OperationType>
20 {
21 public:
22  evaluator_impl(DataServices& d)
23  : _services(d)
24  {
25  }
26 
27  virtual void apply(const OperationType& o) final override
28  {
29  auto* eval = static_cast<EvaluatorType*>(this);
30  const auto& op = o.template get<typename EvaluatorType::operation_type>();
31  eval->do_apply(op);
32  }
33 
34  DataServices& db() const
35  {
36  return _services;
37  }
38 
39 private:
40  DataServices& _services;
41 };
42 
43 } // namespace scorum
44 } // namespace chain
45 
46 #define DEFINE_EVALUATOR(X) \
47  class X##_evaluator : public scorum::chain::evaluator_impl<data_service_factory_i, X##_evaluator> \
48  { \
49  public: \
50  typedef X##_operation operation_type; \
51  \
52  X##_evaluator(data_service_factory_i& db) \
53  : scorum::chain::evaluator_impl<data_service_factory_i, X##_evaluator>(db) \
54  { \
55  } \
56  \
57  void do_apply(const X##_operation& o); \
58  };
DataServices & db() const
Definition: evaluator.hpp:34
virtual void apply(const OperationType &o) final override
Definition: evaluator.hpp:27
evaluator_impl(DataServices &d)
Definition: evaluator.hpp:22
virtual void apply(const OperationType &op)=0
virtual ~evaluator()=default
Definition: asset.cpp:15