From d308b31d745c37c2339b73d6f6c0c9ec88496cc9 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sun, 17 Jun 2018 10:07:50 +0800 Subject: [PATCH] json_detailedtransaction started --- src/page.h | 88 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 7 deletions(-) diff --git a/src/page.h b/src/page.h index 7e846ee..bc60bab 100644 --- a/src/page.h +++ b/src/page.h @@ -273,6 +273,85 @@ struct tx_details }; +class my_render_node: public boost::static_visitor { +public: + + std::string operator()(const int& value) const { + return std::to_string(value); + } + + std::string operator()(const double& value) const { + std::stringstream ss; + ss << value; + return ss.str(); + } + + std::string operator()(const uint64_t& value) const { + std::stringstream ss; + ss << value; + return ss.str(); + } + + std::string operator()(const int64_t& value) const { + std::stringstream ss; + ss << value; + return ss.str(); + } + + std::string operator()(const uint32_t& value) const { + std::stringstream ss; + ss << value; + return ss.str(); + } + + std::string operator()(const bool& value) const { + return value ? "true" : "false"; + } + + std::string operator()(const string& value) const { + return value; + } + + std::string operator()(const mstch::map& n_map) const + { + std::stringstream ss; + + for (auto const& kv: n_map) + { + ss << "k:" << kv.first + << ", v: " << boost::apply_visitor(my_render_node(), kv.second) + << " "; + } + + return ss.str(); + } + + std::string operator()(const mstch::array& n_array) const + { + std::stringstream ss; + for (auto const& v: n_array) + { + string s = boost::apply_visitor(my_render_node(), v); + ss << " a: " << s << " "; + } + + return ss.str(); + + } + + std::string operator()(const mstch::lambda& value) const { + return "lambda"; + } + + template + std::string operator()(const T&) const { + return "unknown type"; + } + +}; + + + class page { @@ -4257,14 +4336,9 @@ public: { //j_data[kv.first] = boost::apply_visitor(render_node2(), kv.second); - mstch::map context{ - {"yay", kv.second}, - {"bold", mstch::lambda{[](const std::string& text) -> mstch::node { - return "" + text + ""; - }}} - }; + string a = boost::apply_visitor(my_render_node(), kv.second); - cout << mstch::render(view, context) << endl; + cout << kv.first << " = " << a << endl; } j_response["status"] = "success";