X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Fmstch%2Frender_context.hpp;fp=lib%2Fmstch%2Frender_context.hpp;h=b97d41baa83e9dd7000bf8311240393b3feddb13;hb=2e142df11d6f312a2a2b5097b8da73571ed523e8;hp=0000000000000000000000000000000000000000;hpb=61b3659afe961ed248f30e26f9ca8f28fcfafddc;p=cpPlugins.git diff --git a/lib/mstch/render_context.hpp b/lib/mstch/render_context.hpp new file mode 100644 index 0000000..b97d41b --- /dev/null +++ b/lib/mstch/render_context.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "mstch/mstch.hpp" +#include "state/render_state.hpp" +#include "template_type.hpp" + +namespace mstch { + +class render_context { + public: + class push { + public: + push(render_context& context, const mstch::node& node = {}); + ~push(); + std::string render(const template_type& templt); + private: + render_context& m_context; + }; + + render_context( + const mstch::node& node, + const std::map& partials); + const mstch::node& get_node(const std::string& token); + std::string render( + const template_type& templt, const std::string& prefix = ""); + std::string render_partial( + const std::string& partial_name, const std::string& prefix); + template + void set_state(Args&& ... args) { + m_state.top() = std::unique_ptr( + new T(std::forward(args)...)); + } + + private: + static const mstch::node null_node; + const mstch::node& find_node( + const std::string& token, + std::list current_nodes); + std::map m_partials; + std::deque m_nodes; + std::list m_node_ptrs; + std::stack> m_state; +}; + +}