File: dot_notation.hpp

package info (click to toggle)
mstch 1.0.2-4
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 940 kB
  • sloc: cpp: 1,429; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class dot_notation_price: public mstch::object {
private:
  int m_value;
  mstch::map m_currency;
public:
  dot_notation_price():
    m_value(200), m_currency(mstch::map{{"symbol", std::string{"$"}}, {"name", std::string{"USD"}}})
  {
    register_methods(this, std::map<std::string,mstch::node(dot_notation_price::*)()>{
      {"value", &dot_notation_price::value},
      {"vat", &dot_notation_price::vat},
      {"currency", &dot_notation_price::currency}});
  }

  mstch::node value() {
    return m_value;
  }

  mstch::node vat() {
    return m_value * 0.2;
  }

  mstch::node currency() {
    return m_currency;
  }
};

const auto dot_notation_data = mstch::map{
  {"name", std::string{"A Book"}},
  {"authors", mstch::array{std::string{"John Power"}, std::string{"Jamie Walsh"}}},
  {"price", std::make_shared<dot_notation_price>()},
  {"availability", mstch::map{{"status", true}, {"text", std::string{"In Stock"}}}},
  {"truthy", mstch::map{{"zero", 0}, {"notTrue", false}}}
};