1 
2 #ifndef MUSTACHE_RENDERER_HPP
3 #define MUSTACHE_RENDERER_HPP
4 
5 #include <iostream>
6 #include <map>
7 #include <string>
8 
9 #include "data.hpp"
10 #include "exception.hpp"
11 #include "node.hpp"
12 #include "tokenizer.hpp"
13 #include "utils.hpp"
14 
15 namespace mustache {
16 
17 
18 /*! \class Renderer
19     \brief Renders a token tree
20 
21     This class renders a token tree.
22 */
23 class Renderer {
24   private:
25     //! The root token node
26     Node * _node;
27 
28     //! The root data node
29     Data * _data;
30 
31     //! The data stack
32     Stack<Data *> * _stack;
33 
34     //! Partials
35     Node::Partials * _partials;
36 
37     //! Current output buffer
38     std::string * _output;
39 
40     //! Renders a single node
41     void _renderNode(Node * node);
42 
43     Data * _lookup(Node * node);
44 
45     bool _strictPaths;
46 
47   public:
48     //! The default output buffer length
49     static const int outputBufferLength = 1000;
50 
51     //! Constructor
Renderer()52     Renderer() :
53         _node(NULL),
54         _data(NULL),
55         _stack(NULL),
56         _partials(NULL),
57         _output(NULL),
58         _strictPaths(false) {};
59 
60     //! Destructor
61     ~Renderer();
62 
63     //! Clears any assigned values
64     void clear();
65 
66     //! Initializes the renderer
67     void init(Node * node, Data * data, Node::Partials * partials, std::string * output);
68 
69     //! Sets the current root token node
70     void setNode(Node * node);
71 
72     //! Sets the current root data node
73     void setData(Data * data);
74 
75     //! Sets the current partials
76     void setPartials(Node::Partials * partials);
77 
78     //! Sets the current output buffer
79     void setOutput(std::string * output);
80 
81     //! Renders using the stored variables
82     void render();
83 
84     //! Renders the given node to the given output using the stored variables
85     void renderForLambda(Node * node, std::string * output);
86 };
87 
88 
89 } // namespace Mustache
90 
91 #endif
92