optimize
This commit is contained in:
parent
61a700479d
commit
244477f0a0
20 changed files with 140 additions and 231 deletions
|
@ -1,49 +1,43 @@
|
|||
#include "render_section.hpp"
|
||||
#include "is_node_empty.hpp"
|
||||
|
||||
using namespace mstch;
|
||||
|
||||
visitor::render_section::render_section(
|
||||
render_context& context,
|
||||
const std::string& section,
|
||||
std::set<flag> flags):
|
||||
context(context),
|
||||
section(section),
|
||||
flags(flags)
|
||||
render_context& ctx, const std::string& section, std::set<flag> flags):
|
||||
ctx(ctx), section(section), flags(flags)
|
||||
{
|
||||
}
|
||||
|
||||
std::string visitor::render_section::operator()(
|
||||
const boost::blank& blank) const
|
||||
{
|
||||
return render_context(mstch::object{{".", mstch::node{}}}, context)
|
||||
.render(section);
|
||||
return render_context::push(ctx, {{".", {}}}).render(section);
|
||||
}
|
||||
|
||||
std::string visitor::render_section::operator()(const int& i) const {
|
||||
return render_context(mstch::object{{".", i}}, context).render(section);
|
||||
return render_context::push(ctx, {{".", i}}).render(section);
|
||||
}
|
||||
|
||||
std::string visitor::render_section::operator()(const bool& b) const {
|
||||
return render_context(mstch::object{{".", b}}, context).render(section);
|
||||
return render_context::push(ctx, {{".", b}}).render(section);
|
||||
}
|
||||
|
||||
std::string visitor::render_section::operator()(const std::string& str) const {
|
||||
return render_context(mstch::object{{".", str}}, context).render(section);
|
||||
return render_context::push(ctx, {{".", str}}).render(section);
|
||||
}
|
||||
|
||||
std::string visitor::render_section::operator()(const object& obj) const {
|
||||
return render_context(obj, context).render(section);
|
||||
return render_context::push(ctx, obj).render(section);
|
||||
}
|
||||
|
||||
std::string visitor::render_section::operator()(const array& a) const {
|
||||
std::ostringstream out;
|
||||
if(flags.find(flag::keep_array) != flags.end())
|
||||
out << render_context(mstch::object{{".", a}}, context).render(section);
|
||||
out << render_context::push(ctx, {{".", a}}).render(section);
|
||||
else
|
||||
for (auto& item: a)
|
||||
out << boost::apply_visitor(
|
||||
render_section(context, section, {flag::keep_array}), item);
|
||||
render_section(ctx, section, {flag::keep_array}), item);
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
@ -57,6 +51,6 @@ std::string visitor::render_section::operator()(
|
|||
const renderer_lambda& lambda) const
|
||||
{
|
||||
return (lambda())(section, [&](const std::string& text) {
|
||||
return render_context(mstch::object{}, context).render(text);
|
||||
return render_context::push(ctx).render(text);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue