aboutsummaryrefslogtreecommitdiff
path: root/lib/mstch/test/data/complex.hpp
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-01-16 15:43:04 +0800
committerMistivia <i@mistivia.com>2025-01-16 15:53:58 +0800
commit8689a7c78c50676ea739f52fbcee9f091709f5c0 (patch)
treebbb72c68e5e1753f751133941a402caa43e29a16 /lib/mstch/test/data/complex.hpp
parent00afb767ae37488d99f78363d031b898b1932354 (diff)
add mstch
Diffstat (limited to 'lib/mstch/test/data/complex.hpp')
-rw-r--r--lib/mstch/test/data/complex.hpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/mstch/test/data/complex.hpp b/lib/mstch/test/data/complex.hpp
new file mode 100644
index 0000000..a438098
--- /dev/null
+++ b/lib/mstch/test/data/complex.hpp
@@ -0,0 +1,69 @@
+class complex_item: public mstch::object {
+private:
+ std::string m_name;
+ bool m_current;
+ std::string m_url;
+public:
+ complex_item(const std::string& name, bool current, const std::string& url):
+ m_name(name), m_current(current), m_url(url)
+ {
+ register_methods(this, std::map<std::string,mstch::node(complex_item::*)()>{
+ {"name", &complex_item::name}, {"current", &complex_item::current},
+ {"url", &complex_item::url}, {"link", &complex_item::link}
+ });
+ }
+
+ mstch::node current() {
+ return m_current;
+ }
+
+ mstch::node url() {
+ return m_url;
+ }
+
+ mstch::node name() {
+ return m_name;
+ }
+
+ mstch::node link() {
+ return !m_current;
+ }
+};
+
+class complex: public mstch::object {
+private:
+ std::string m_header;
+ mstch::array m_item;
+public:
+ complex():
+ m_header("Colors"),
+ m_item(mstch::array{
+ std::make_shared<complex_item>("red", true, "#Red"),
+ std::make_shared<complex_item>("green", false, "#Green"),
+ std::make_shared<complex_item>("blue", false, "#Blue")
+ })
+ {
+ register_methods(this, std::map<std::string,mstch::node(complex::*)()>{
+ {"header", &complex::header}, {"item", &complex::item},
+ {"list", &complex::list}, {"empty", &complex::empty}
+ });
+ }
+
+ mstch::node header() {
+ return m_header;
+ }
+
+ mstch::node item() {
+ return m_item;
+ }
+
+ mstch::node list() {
+ return m_item.size() != 0;
+ }
+
+ mstch::node empty() {
+ return m_item.size() == 0;
+ }
+};
+
+const auto complex_data = std::make_shared<complex>(); \ No newline at end of file