Scorum
data_service_factory_def.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/preprocessor/seq/for_each.hpp>
4 
5 namespace scorum {
6 namespace chain {
7 namespace dba {
8 struct db_accessor_factory;
9 }
10 }
11 }
12 
13 #define DECLARE_SERVICE_FUNCT_NAME(service) BOOST_PP_CAT(service, _service)
14 
15 #define DECLARE_SERVICE_INTERFACE_NAME(service) BOOST_PP_CAT(DECLARE_SERVICE_FUNCT_NAME(service), _i)
16 
17 #define DECLARE_DBS_IMPL_NAME(service) BOOST_PP_CAT(dbs_, service)
18 
19 #define DECLARE_SERVICE_INTERFACE(_1, _2, service) \
20  struct DECLARE_SERVICE_INTERFACE_NAME(service); \
21  struct account_service_i; \
22  struct witness_service_i;
23 
24 #define DECLARE_FACTORY_INTERFACE_METHOD(_1, _2, service) \
25  virtual DECLARE_SERVICE_INTERFACE_NAME(service) \
26  & BOOST_PP_CAT(DECLARE_SERVICE_FUNCT_NAME(service), BOOST_PP_EMPTY())() const \
27  = 0;
28 
29 #define DECLARE_FACTORY_METHOD(_1, _2, service) \
30  virtual DECLARE_SERVICE_INTERFACE_NAME(service) \
31  & BOOST_PP_CAT(DECLARE_SERVICE_FUNCT_NAME(service), BOOST_PP_EMPTY())() const;
32 
33 #define DATA_SERVICE_FACTORY_DECLARE(SERVICES) \
34  namespace scorum { \
35  namespace chain { \
36  \
37  class database; \
38  class dbservice_dbs_factory; \
39  \
40  BOOST_PP_SEQ_FOR_EACH(DECLARE_SERVICE_INTERFACE, _, SERVICES) \
41  \
42  struct data_service_factory_i \
43  { \
44  BOOST_PP_SEQ_FOR_EACH(DECLARE_FACTORY_INTERFACE_METHOD, _, SERVICES) \
45  virtual account_service_i& account_service() const = 0; \
46  virtual witness_service_i& witness_service() const = 0; \
47  }; \
48  class data_service_factory : public data_service_factory_i \
49  { \
50  public: \
51  explicit data_service_factory(scorum::chain::database& db); \
52  \
53  virtual ~data_service_factory(); \
54  \
55  BOOST_PP_SEQ_FOR_EACH(DECLARE_FACTORY_METHOD, _, SERVICES) \
56  virtual account_service_i& account_service() const override; \
57  virtual witness_service_i& witness_service() const override; \
58  \
59  private: \
60  scorum::chain::dbservice_dbs_factory& factory; \
61  scorum::chain::dba::db_accessor_factory& dba_factory; \
62  }; \
63  } \
64  }
65 
66 #define DECLARE_FACTORY_METHOD_IMPL(_1, _2, service) \
67  DECLARE_SERVICE_INTERFACE_NAME(service) \
68  &data_service_factory::BOOST_PP_CAT(DECLARE_SERVICE_FUNCT_NAME(service), BOOST_PP_EMPTY())() const \
69  { \
70  return factory.obtain_service<DECLARE_DBS_IMPL_NAME(service)>(); \
71  }
72 
73 #define DATA_SERVICE_FACTORY_IMPL(SERVICES) \
74  namespace scorum { \
75  namespace chain { \
76  data_service_factory::data_service_factory(scorum::chain::database& db) \
77  : factory(db) \
78  , dba_factory(db) \
79  { \
80  } \
81  \
82  data_service_factory::~data_service_factory() \
83  { \
84  } \
85  BOOST_PP_SEQ_FOR_EACH(DECLARE_FACTORY_METHOD_IMPL, _, SERVICES) \
86  account_service_i& data_service_factory::account_service() const \
87  { \
88  return factory.obtain_service_explicit<dbs_account>(dynamic_global_property_service(), witness_service()); \
89  } \
90  witness_service_i& data_service_factory::witness_service() const \
91  { \
92  return factory.obtain_service_explicit<dbs_witness>(witness_schedule_service(), \
93  dynamic_global_property_service(), \
94  dba_factory.get_dba<chain_property_object>()); \
95  } \
96  } \
97  }
Definition: asset.cpp:15