diff options
| author | Mistivia <i@mistivia.com> | 2025-01-16 15:43:04 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-01-16 15:53:58 +0800 |
| commit | 8689a7c78c50676ea739f52fbcee9f091709f5c0 (patch) | |
| tree | bbb72c68e5e1753f751133941a402caa43e29a16 /lib/mstch/test/data/dot_notation.hpp | |
| parent | 00afb767ae37488d99f78363d031b898b1932354 (diff) | |
add mstch
Diffstat (limited to 'lib/mstch/test/data/dot_notation.hpp')
| -rw-r--r-- | lib/mstch/test/data/dot_notation.hpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/mstch/test/data/dot_notation.hpp b/lib/mstch/test/data/dot_notation.hpp new file mode 100644 index 0000000..c287107 --- /dev/null +++ b/lib/mstch/test/data/dot_notation.hpp @@ -0,0 +1,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}}} +};
\ No newline at end of file |
