Scorum
market.cpp
Go to the documentation of this file.
2 #include <scorum/utils/static_variant_serialization.hpp>
3 
4 namespace scorum {
5 namespace protocol {
6 
8 {
9  template <market_kind kind, typename tag>
10  std::pair<wincase_type, wincase_type> operator()(const over_under_market<kind, tag>& m) const
11  {
14  }
15 
16  template <market_kind kind, typename tag>
17  std::pair<wincase_type, wincase_type> operator()(const score_yes_no_market<kind, tag>& m) const
18  {
21  }
22 
23  template <market_kind kind, typename tag>
24  std::pair<wincase_type, wincase_type> operator()(const yes_no_market<kind, tag>& m) const
25  {
27  }
28 };
29 
31 {
32  template <bool site, market_kind kind, typename tag>
34  {
36  }
37 
38  template <bool site, market_kind kind, typename tag>
40  {
42  }
43 
44  template <bool site, market_kind kind, typename tag>
46  {
47  return yes_no_market<kind, tag>{};
48  }
49 };
50 
51 std::pair<wincase_type, wincase_type> create_wincases(const market_type& market)
52 {
53  return market.visit(wincases_builder{});
54 }
55 
57 {
58  return wincase.visit(market_builder{});
59 }
60 
62 {
63  return wincase.visit([](const auto& w) { return wincase_type(w.create_opposite()); });
64 }
65 
66 bool has_trd_state(const market_type& market)
67 {
68  return market.visit([](const auto& m) { return m.has_trd_state(); });
69 }
70 
71 bool match_wincases(const wincase_type& lhs, const wincase_type& rhs)
72 {
73  auto lhs_opposite = create_opposite(lhs);
74 
75  return !(lhs_opposite < rhs) && !(rhs < lhs_opposite);
76 }
77 
79 {
80  return wincase.visit([](const auto& w) { return std::decay_t<decltype(w)>::kind_v; });
81 }
82 
83 } // namespace protocol
84 
85 namespace utils {
93 template <>
94 template <typename TVariantItem>
95 std::string static_variant_convertor<protocol::wincase_type>::get_type_name(const TVariantItem& obj) const
96 {
97  std::string type_name = fc::get_typename<TVariantItem>::name();
98  auto nested_type_threshold = type_name.find_last_of(':') - 2;
99  auto type_threshold = type_name.find_last_of(':', nested_type_threshold) + 1;
100  return type_name.substr(type_threshold, type_name.size() - type_threshold);
101 }
102 }
103 }
104 
105 namespace fc {
106 
107 template <> void to_variant(const wincase_type& wincase, fc::variant& var)
108 {
109  scorum::utils::to_variant(wincase, var);
110 }
111 template <> void from_variant(const fc::variant& var, wincase_type& wincase)
112 {
113  scorum::utils::from_variant(var, wincase);
114 }
115 
116 template <> void to_variant(const market_type& market, fc::variant& var)
117 {
118  scorum::utils::to_variant(market, var);
119 }
120 template <> void from_variant(const fc::variant& var, market_type& market)
121 {
122  scorum::utils::from_variant(var, market);
123 }
124 }
Definition: game.cpp:4
void to_variant(const game_type &game, fc::variant &var)
Definition: game.cpp:8
void from_variant(const fc::variant &var, market_type &market)
Definition: market.cpp:120
void to_variant(const market_type &market, fc::variant &var)
Definition: market.cpp:116
void from_variant(const fc::variant &var, game_type &game)
Definition: game.cpp:12
market_type create_market(const wincase_type &wincase)
Definition: market.cpp:56
market_kind get_market_kind(const wincase_type &wincase)
Definition: market.cpp:78
wincase_type create_opposite(const wincase_type &wincase)
Definition: market.cpp:61
fc::static_variant< result_home::yes, result_home::no, result_draw::yes, result_draw::no, result_away::yes, result_away::no, round_home::yes, round_home::no, handicap::over, handicap::under, correct_score_home::yes, correct_score_home::no, correct_score_draw::yes, correct_score_draw::no, correct_score_away::yes, correct_score_away::no, correct_score::yes, correct_score::no, goal_home::yes, goal_home::no, goal_both::yes, goal_both::no, goal_away::yes, goal_away::no, total::over, total::under, total_goals_home::over, total_goals_home::under, total_goals_away::over, total_goals_away::under > wincase_type
Definition: market.hpp:128
bool has_trd_state(const market_type &market)
Definition: market.cpp:66
bool match_wincases(const wincase_type &lhs, const wincase_type &rhs)
Definition: market.cpp:71
std::pair< wincase_type, wincase_type > create_wincases(const market_type &market)
Definition: market.cpp:51
fc::static_variant< result_home, result_draw, result_away, round_home, handicap, correct_score_home, correct_score_draw, correct_score_away, correct_score, goal_home, goal_both, goal_away, total, total_goals_home, total_goals_away > market_type
Definition: market.hpp:97
Definition: asset.cpp:15
market_type operator()(const over_under_wincase< site, kind, tag > &w) const
Definition: market.cpp:33
market_type operator()(const yes_no_wincase< site, kind, tag > &w) const
Definition: market.cpp:45
market_type operator()(const score_yes_no_wincase< site, kind, tag > &w) const
Definition: market.cpp:39
int16_t threshold
Market threshold x 1000 (i.e. -500 in 'handicap' market means -0.5)
Definition: wincase.hpp:11
std::pair< wincase_type, wincase_type > operator()(const score_yes_no_market< kind, tag > &m) const
Definition: market.cpp:17
std::pair< wincase_type, wincase_type > operator()(const over_under_market< kind, tag > &m) const
Definition: market.cpp:10
std::pair< wincase_type, wincase_type > operator()(const yes_no_market< kind, tag > &m) const
Definition: market.cpp:24