Electroneum
render_section.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/variant/static_visitor.hpp>
4 
5 #include "render_context.hpp"
6 #include "mstch/mstch.hpp"
7 #include "utils.hpp"
8 #include "render_node.hpp"
9 
10 namespace mstch {
11 
12 class render_section: public boost::static_visitor<std::string> {
13  public:
14  enum class flag { none, keep_array };
16  render_context& ctx,
17  const template_type& section,
18  const delim_type& delims,
19  flag p_flag = flag::none):
20  m_ctx(ctx), m_section(section), m_delims(delims), m_flag(p_flag)
21  {
22  }
23 
24  template<class T>
25  std::string operator()(const T& t) const {
27  }
28 
29  std::string operator()(const lambda& fun) const {
30  std::string section_str;
31  for (auto& token: m_section)
32  section_str += token.raw();
33  template_type interpreted{fun([this](const mstch::node& n) {
34  return visit(render_node(m_ctx), n);
35  }, section_str), m_delims};
36  return render_context::push(m_ctx).render(interpreted);
37  }
38 
39  std::string operator()(const array& array) const {
40  std::string out;
41  if (m_flag == flag::keep_array)
43  else
44  for (auto& item: array)
45  out += visit(render_section(
47  return out;
48  }
49 
50  private:
55 };
56 
57 }
Definition: render_node.hpp:12
const template_type & m_section
Definition: render_section.hpp:52
Definition: render_context.hpp:17
const uint32_t T[512]
Definition: groestl_tables.h:34
render_section(render_context &ctx, const template_type &section, const delim_type &delims, flag p_flag=flag::none)
Definition: render_section.hpp:15
Definition: render_section.hpp:12
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 T &t) const
Definition: render_section.hpp:25
flag
Definition: render_section.hpp:14
std::vector< node > array
Definition: mstch.hpp:120
Definition: mstch.hpp:11
render_context & m_ctx
Definition: render_section.hpp:51
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
const delim_type & m_delims
Definition: render_section.hpp:53
Definition: template_type.hpp:11
Definition: render_context.hpp:15
Definition: mstch.hpp:66
std::pair< std::string, std::string > delim_type
Definition: token.hpp:7
const std::string & raw() const
Definition: token.hpp:17
std::string operator()(const array &array) const
Definition: render_section.hpp:39
flag m_flag
Definition: render_section.hpp:54
Definition: token.hpp:9
std::string operator()(const lambda &fun) const
Definition: render_section.hpp:29