Electroneum
render_node.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 #include <boost/variant/static_visitor.hpp>
5 
6 #include "render_context.hpp"
7 #include "mstch/mstch.hpp"
8 #include "utils.hpp"
9 
10 namespace mstch {
11 
12 class render_node: public boost::static_visitor<std::string> {
13  public:
14  enum class flag { none, escape_html };
16  m_ctx(ctx), m_flag(p_flag)
17  {
18  }
19 
20  template<class T>
21  std::string operator()(const T&) const {
22  return "";
23  }
24 
25  std::string operator()(const int& value) const {
26  return std::to_string(value);
27  }
28 
29  std::string operator()(const double& value) const {
30  std::stringstream ss;
31  ss << value;
32  return ss.str();
33  }
34 
35  std::string operator()(const uint64_t& value) const {
36  std::stringstream ss;
37  ss << value;
38  return ss.str();
39  }
40 
41  std::string operator()(const int64_t& value) const {
42  std::stringstream ss;
43  ss << value;
44  return ss.str();
45  }
46 
47  std::string operator()(const uint32_t& value) const {
48  std::stringstream ss;
49  ss << value;
50  return ss.str();
51  }
52 
53  std::string operator()(const bool& value) const {
54  return value ? "true" : "false";
55  }
56 
57  std::string operator()(const lambda& value) const {
58  template_type interpreted{value([this](const mstch::node& n) {
59  return visit(render_node(m_ctx), n);
60  })};
61  auto rendered = render_context::push(m_ctx).render(interpreted);
62  return (m_flag == flag::escape_html) ? html_escape(rendered) : rendered;
63  }
64 
65  std::string operator()(const std::string& value) const {
66  return (m_flag == flag::escape_html) ? html_escape(value) : value;
67  }
68 
69  private:
72 };
73 
74 }
Definition: render_node.hpp:12
Definition: render_context.hpp:17
const uint32_t T[512]
Definition: groestl_tables.h:34
render_context & m_ctx
Definition: render_node.hpp:70
std::string operator()(const T &) const
Definition: render_node.hpp:21
flag
Definition: render_node.hpp:14
boost::make_recursive_variant< std::nullptr_t, std::string, int, double, bool, uint64_t, int64_t, uint32_t, internal::lambda_t< boost::recursive_variant_ >, std::shared_ptr< internal::object_t< boost::recursive_variant_ > >, internal::map< const std::string, boost::recursive_variant_ >, std::vector< boost::recursive_variant_ > >::type node
Definition: mstch.hpp:116
std::string operator()(const double &value) const
Definition: render_node.hpp:29
std::string html_escape(const std::string &str)
Definition: utils.cpp:20
std::string operator()(const uint64_t &value) const
Definition: render_node.hpp:35
Definition: mstch.hpp:11
std::string operator()(const uint32_t &value) const
Definition: render_node.hpp:47
std::string operator()(const int &value) const
Definition: render_node.hpp:25
std::string operator()(const lambda &value) const
Definition: render_node.hpp:57
std::string operator()(const bool &value) const
Definition: render_node.hpp:53
std::string operator()(const std::string &value) const
Definition: render_node.hpp:65
std::string render(const template_type &templt)
Definition: render_context.cpp:23
auto visit(Args &&... args) -> decltype(boost::apply_visitor(std::forward< Args >(args)...))
Definition: utils.hpp:17
Definition: template_type.hpp:11
render_node(render_context &ctx, flag p_flag=flag::none)
Definition: render_node.hpp:15
std::string operator()(const int64_t &value) const
Definition: render_node.hpp:41
Definition: render_context.hpp:15
Definition: mstch.hpp:66
flag m_flag
Definition: render_node.hpp:71
std::string to_string(t_connection_type type)
Definition: connection_basic.cpp:96