dot_notation.hpp 986 B

12345678910111213141516171819202122232425262728293031323334
  1. class dot_notation_price: public mstch::object {
  2. private:
  3. int m_value;
  4. mstch::map m_currency;
  5. public:
  6. dot_notation_price():
  7. m_value(200), m_currency(mstch::map{{"symbol", std::string{"$"}}, {"name", std::string{"USD"}}})
  8. {
  9. register_methods(this, std::map<std::string,mstch::node(dot_notation_price::*)()>{
  10. {"value", &dot_notation_price::value},
  11. {"vat", &dot_notation_price::vat},
  12. {"currency", &dot_notation_price::currency}});
  13. }
  14. mstch::node value() {
  15. return m_value;
  16. }
  17. mstch::node vat() {
  18. return m_value * 0.2;
  19. }
  20. mstch::node currency() {
  21. return m_currency;
  22. }
  23. };
  24. const auto dot_notation_data = mstch::map{
  25. {"name", std::string{"A Book"}},
  26. {"authors", mstch::array{std::string{"John Power"}, std::string{"Jamie Walsh"}}},
  27. {"price", std::make_shared<dot_notation_price>()},
  28. {"availability", mstch::map{{"status", true}, {"text", std::string{"In Stock"}}}},
  29. {"truthy", mstch::map{{"zero", 0}, {"notTrue", false}}}
  30. };