Cutelee  6.1.0
template.h
1 /*
2  This file is part of the Cutelee template system.
3 
4  Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either version
9  2.1 of the Licence, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #ifndef CUTELEE_TEMPLATE_H
22 #define CUTELEE_TEMPLATE_H
23 
24 #include "exception.h"
25 #include "cutelee_templates_export.h"
26 #include "node.h"
27 
28 #include <QtCore/QStringList>
29 
30 namespace Cutelee
31 {
32 class Context;
33 class Engine;
34 class TemplateImpl;
35 class OutputStream;
36 
37 #ifdef Q_QDOC
38 #define TemplateImpl Template
39 #else
40 typedef std::shared_ptr<TemplateImpl> Template;
41 #endif
42 
43 class TemplatePrivate;
44 
46 
94 class CUTELEE_TEMPLATES_EXPORT TemplateImpl : public QObject
95 {
96  Q_OBJECT
97 public:
98  ~TemplateImpl() override;
99 
103  QString render(Context *c) const;
104 
108  OutputStream *render(OutputStream *stream, Context *c) const;
109 
110 #ifndef Q_QDOC
114  NodeList nodeList() const;
115 
119  void setNodeList(const NodeList &list);
120 #endif
121 
125  Error error() const;
126 
130  QString errorString() const;
131 
135  Engine const *engine() const;
136 
137 #ifndef Q_QDOC
138 protected:
139  TemplateImpl(Engine const *engine, QObject *parent = {});
140  TemplateImpl(Engine const *engine, bool smartTrim, QObject *parent = {});
141 
142  void setContent(const QString &templateString);
143 #endif
144 
145 private:
146  // Don't allow setting the parent on a Template, which is memory managed as
147  // a std::shared_ptr.
148  using QObject::setParent;
149 
150 private:
151  Q_DECLARE_PRIVATE(Template)
152  TemplatePrivate *const d_ptr;
153 #ifndef Q_QDOC
154  friend class Engine;
155  friend class Parser;
156 #endif
157 };
158 }
159 
160 Q_DECLARE_METATYPE(Cutelee::Template)
161 
162 #endif
The Context class holds the context to render a Template with.
Definition: context.h:119
Cutelee::Engine is the main entry point for creating Cutelee Templates.
Definition: engine.h:121
A list of Nodes with some convenience API for rendering them.
Definition: node.h:148
The OutputStream class is used to render templates to a QTextStream.
Definition: outputstream.h:81
The Parser class processes a string template into a tree of nodes.
Definition: parser.h:49
The Template class is a tree of nodes which may be rendered.
Definition: template.h:95
The Cutelee namespace holds all public Cutelee API.
Definition: Mainpage.dox:8