mstch/test/data/complex.hpp

69 lines
1.5 KiB
C++
Raw Normal View History

2015-04-17 08:07:14 +08:00
class complex_item: public mstch::object {
private:
2015-04-21 21:04:11 +08:00
std::string m_name;
bool m_current;
std::string m_url;
2015-04-17 08:07:14 +08:00
public:
complex_item(const std::string& name, bool current, const std::string& url):
2015-10-01 18:16:35 +08:00
m_name(name), m_current(current), m_url(url)
2015-04-17 08:07:14 +08:00
{
2015-10-01 18:16:35 +08:00
register_methods(this, std::map<std::string,mstch::node(complex_item::*)()>{
2015-04-21 21:04:11 +08:00
{"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;
2015-04-17 08:07:14 +08:00
}
mstch::node link() {
2015-04-21 21:04:11 +08:00
return !m_current;
2015-04-17 08:07:14 +08:00
}
};
class complex: public mstch::object {
private:
2015-04-21 21:04:11 +08:00
std::string m_header;
mstch::array m_item;
2015-04-17 08:07:14 +08:00
public:
complex():
2015-10-01 18:16:35 +08:00
m_header("Colors"),
m_item(mstch::array{
2015-04-17 08:07:14 +08:00
std::make_shared<complex_item>("red", true, "#Red"),
std::make_shared<complex_item>("green", false, "#Green"),
std::make_shared<complex_item>("blue", false, "#Blue")
2015-10-01 18:16:35 +08:00
})
2015-04-17 08:07:14 +08:00
{
2015-10-01 18:16:35 +08:00
register_methods(this, std::map<std::string,mstch::node(complex::*)()>{
2015-04-21 21:04:11 +08:00
{"header", &complex::header}, {"item", &complex::item},
2015-04-23 21:55:18 +08:00
{"list", &complex::list}, {"empty", &complex::empty}
});
2015-04-21 21:04:11 +08:00
}
mstch::node header() {
return m_header;
}
mstch::node item() {
return m_item;
2015-04-17 08:07:14 +08:00
}
mstch::node list() {
2015-04-21 21:04:11 +08:00
return m_item.size() != 0;
2015-04-17 08:07:14 +08:00
}
mstch::node empty() {
2015-04-21 21:04:11 +08:00
return m_item.size() == 0;
2015-04-17 08:07:14 +08:00
}
};
const auto complex_data = std::make_shared<complex>();