Doxygen
template.h
浏览该文件的文档.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2015 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #ifndef TEMPLATE_H
17 #define TEMPLATE_H
18 
19 #include <vector>
20 #include <memory>
21 #include <functional>
22 
23 #include "qcstring.h"
24 #include "containers.h"
25 #include "variant.h"
26 
27 class TemplateListIntf;
28 class TemplateStructIntf;
29 class TemplateEngine;
30 class TextStream;
31 
32 using TemplateListIntfPtr = std::shared_ptr<TemplateListIntf>;
33 using TemplateStructIntfPtr = std::shared_ptr<TemplateStructIntf>;
34 using TemplateStructIntfWeakPtr = std::weak_ptr<TemplateStructIntf>;
35 
36 /** @defgroup template_api Template API
37  *
38  * This is the API for a
39  * <a href="https://www.djangoproject.com/">Django</a>
40  * compatible template system written in C++.
41  * It is somewhat inspired by Stephen Kelly's
42  * <a href="http://www.gitorious.org/grantlee/pages/Home">Grantlee</a>.
43  *
44  * A template is simply a text file.
45  * A template contains \b variables, which get replaced with values when the
46  * template is evaluated, and \b tags, which control the logic of the template.
47  *
48  * Variables look like this: `{{ variable }}`
49  * When the template engine encounters a variable, it evaluates that variable and
50  * replaces it with the result. Variable names consist of any combination of
51  * alphanumeric characters and the underscore ("_").
52  * Use a dot (.) to access attributes of a structured variable.
53  *
54  * One can modify variables for display by using \b filters, for example:
55  * `{{ value|default:"nothing" }}`
56  *
57  * Tags look like this: `{% tag %}`. Tags are more complex than variables:
58  * Some create text in the output, some control flow by performing loops or logic,
59  * and some load external information into the template to be used by later variables.
60  *
61  * To comment-out part of a line in a template, use the comment syntax:
62  * `{# comment text #}`.
63  *
64  * Supported Django tags:
65  * - `for ... empty ... endfor`
66  * - `if ... else ... endif`
67  * - `block ... endblock`
68  * - `extend`
69  * - `include`
70  * - `with ... endwith`
71  * - `spaceless ... endspaceless`
72  * - `cycle`
73  *
74  * Extension tags:
75  * - `create` which instantiates a template and writes the result to a file.
76  * The syntax is `{% create 'filename' from 'template' %}`.
77  * - `recursetree`
78  * - `markers`
79  * - `msg` ... `endmsg`
80  * - `set`
81  *
82  * Supported Django filters:
83  * - `default`
84  * - `length`
85  * - `add`
86  * - `divisibleby`
87  *
88  * Extension filters:
89  * - `stripPath`
90  * - `nowrap`
91  * - `prepend`
92  * - `append`
93  *
94  * @{
95  */
96 
97 /** @brief Variant type which can hold one value of a fixed set of types. */
99 {
100  public:
101  /** Type representing a function call in a template */
102  using FunctionDelegate = std::function<TemplateVariant(const std::vector<TemplateVariant>&)>;
103 
104  /** Symbolic names for the possible types that this variant can hold. */
105  using VariantT = Variant<bool, // index==0: Type::Bool
106  int, // index==1: Type::Int
107  QCString, // index==2: Type::String
108  TemplateStructIntfPtr, // index==3: Type::Struct
109  TemplateListIntfPtr, // index==4: Type::List
110  FunctionDelegate, // index==5: Type::Function
111  TemplateStructIntfWeakPtr // index==6: Type::WeakStruct
112  >;
113 
114  enum class Type : uint8_t
115  {
116  Bool = 0,
117  Int = 1,
118  String = 2,
119  Struct = 3,
120  List = 4,
121  Function = 5,
122  WeakStruct = 6,
123  None = 255
124  };
125 
126  /** Constructs an invalid variant. */
128 
129  /** Constructs a new variant with a boolean value \a b. */
130  explicit TemplateVariant(bool b) { m_variant.set<static_cast<uint8_t>(Type::Bool)>(b); }
131 
132  /** Constructs a new variant with a integer value \a v. */
133  TemplateVariant(int v) { m_variant.set<static_cast<uint8_t>(Type::Int)>(v); }
134 
135  /** Constructs a new variant with a string value \a s. */
136  TemplateVariant(const char *s,bool raw=FALSE) : m_raw(raw) { m_variant.set<static_cast<uint8_t>(Type::String)>(s); }
137 
138  /** Constructs a new variant with a string value \a s. */
139  TemplateVariant(const QCString &s,bool raw=FALSE) : m_raw(raw) { m_variant.set<static_cast<uint8_t>(Type::String)>(s.str()); }
140 
141  /** Constructs a new variant with a string value \a s. */
142  TemplateVariant(const std::string &s,bool raw=FALSE) : m_raw(raw) { m_variant.set<static_cast<uint8_t>(Type::String)>(s); }
143 
144  /** Constructs a new variant with a struct value \a s.
145  * @note. The variant will hold a counting reference to the object.
146  */
148 
149  /** Constructs a new variant with a list value \a l.
150  * @note. The variant will hold a counting reference to the object.
151  */
152  TemplateVariant(TemplateListIntfPtr l) { m_variant.set<static_cast<uint8_t>(Type::List)>(l); }
153 
154  /** Constructs a new variant with a struct value \a s.
155  * @note. The variant will hold a non-counting reference to the object.
156  */
158 
159  /** Constructs a new variant which represents a method call
160  * @param[in] delegate FunctionDelegate object to invoke when
161  * calling call() on this variant.
162  * @note Use TemplateVariant::FunctionDelegate::fromMethod() and
163  * TemplateVariant::FunctionDelegate::fromFunction() to create
164  * FunctionDelegate objects.
165  */
166  TemplateVariant(FunctionDelegate delegate) { m_variant.set<static_cast<uint8_t>(Type::Function)>(delegate); }
167 
168  /** Destroys the Variant object */
169  ~TemplateVariant() = default;
170 
171  /** Constructs a copy of the variant, \a v,
172  * passed as the argument to this constructor.
173  */
174  TemplateVariant(const TemplateVariant &v) = default;
175 
176  /** Moves the contents of variant \a v into this variant.
177  * variant \a v will become invalid
178  */
180 
181  /** Assigns the value of the variant \a v to this variant. */
182  TemplateVariant &operator=(const TemplateVariant &v) = default;
183 
184  /** Move the value of the variant \a v into this variant.
185  * Variant \a v will become invalid */
187 
188  /** Compares this QVariant with v and returns true if they are equal;
189  * otherwise returns false.
190  */
191  bool operator==(TemplateVariant &other) const;
192 
193  /** Returns the variant as a string. */
194  QCString toString() const;
195 
196  /** Returns the variant as a boolean. */
197  bool toBool() const;
198 
199  /** Returns the variant as an integer. */
200  int toInt() const;
201 
202  /** Returns TRUE if the variant holds a valid value, or FALSE otherwise */
203  constexpr bool isValid() const { return m_variant.valid(); }
204  /** Returns TRUE if the variant holds a boolean value */
205  constexpr bool isBool() const { return m_variant.is<static_cast<uint8_t>(Type::Bool)>(); }
206  /** Returns TRUE if the variant holds an integer value */
207  constexpr bool isInt() const { return m_variant.is<static_cast<uint8_t>(Type::Int)>(); }
208  /** Returns TRUE if the variant holds a string value */
209  constexpr bool isString() const { return m_variant.is<static_cast<uint8_t>(Type::String)>(); }
210  /** Returns TRUE if the variant holds a struct value */
211  constexpr bool isStruct() const { return m_variant.is<static_cast<uint8_t>(Type::Struct)>(); }
212  /** Returns TRUE if the variant holds a list value */
213  constexpr bool isList() const { return m_variant.is<static_cast<uint8_t>(Type::List)>(); }
214  /** Returns TRUE if the variant holds a function value */
215  constexpr bool isFunction() const { return m_variant.is<static_cast<uint8_t>(Type::Function)>(); }
216  /** Returns TRUE if the variant holds a struct value */
217  constexpr bool isWeakStruct() const { return m_variant.is<static_cast<uint8_t>(Type::WeakStruct)>(); }
218 
219  /** Returns the pointer to list referenced by this variant
220  * or 0 if this variant does not have list type.
221  */
223  const TemplateListIntfPtr toList() const;
224 
225  /** Returns the pointer to struct referenced by this variant
226  * or 0 if this variant does not have struct type.
227  */
229  const TemplateStructIntfPtr toStruct() const;
230 
231  /** Return the result of apply this function with \a args.
232  * Returns an empty string if the variant type is not a function.
233  */
234  TemplateVariant call(const std::vector<TemplateVariant> &args = std::vector<TemplateVariant>());
235 
236  /** Sets whether or not the value of the Variant should be
237  * escaped or written as-is (raw).
238  * @param[in] b TRUE means write as-is, FALSE means apply escaping.
239  */
240  void setRaw(bool b) { m_raw = b; }
241 
242  /** Returns whether or not the value of the Value is raw.
243  * @see setRaw()
244  */
245  constexpr bool raw() const { return m_raw; }
246 
247  /** Returns the type held by this variant */
248  constexpr Type type() const { return static_cast<Type>(m_variant.index()); }
249 
250  /** Returns a string representation of this variant's type */
251  const char *typeAsString() const;
252 
253  private:
254  QCString listToString() const;
255  QCString structToString() const;
256 
258  bool m_raw = false;
259 };
260 
261 using TemplateVariantList = std::vector<TemplateVariant>;
262 
263 //------------------------------------------------------------------------
264 
265 /** @brief Abstract read-only interface for a context value of type list.
266  * @note The values of the list are TemplateVariants.
267  */
269 {
270  public:
271  /** @brief Abstract interface for a iterator of a list. */
273  {
274  public:
275  /** Destructor for the iterator */
276  virtual ~ConstIterator() {}
277  /** Moves iterator to the first element in the list */
278  virtual void toFirst() = 0;
279  /** Moves iterator to the last element in the list */
280  virtual void toLast() = 0;
281  /** Moves iterator to the next element in the list */
282  virtual void toNext() = 0;
283  /** Moves iterator to the previous element in the list */
284  virtual void toPrev() = 0;
285  /* Returns TRUE if the iterator points to a valid element
286  * in the list, or FALSE otherwise.
287  * If TRUE is returned, the value pointed to be the
288  * iterator is assigned to \a v.
289  */
290  virtual bool current(TemplateVariant &v) const = 0;
291  };
292  using ConstIteratorPtr = std::unique_ptr<ConstIterator>;
293 
294  /** Destroys the list */
295  virtual ~TemplateListIntf() {}
296 
297  /** Returns the number of elements in the list */
298  virtual uint count() const = 0;
299 
300  /** Returns the element at index position \a index. */
301  virtual TemplateVariant at(uint index) const = 0;
302 
303  /** Creates a new iterator for this list.
304  * @note the user should call delete on the returned pointer.
305  */
307 
308 };
309 
310 /** @brief Default implementation of a immutable context value of type list. */
312 {
313  public:
314  // TemplateListIntf methods
315  virtual uint count() const;
316  virtual TemplateVariant at(uint index) const;
318 
319  /** Creates an instance and returns a shared pointer to it */
320  static TemplateListIntfPtr alloc(std::initializer_list<TemplateVariant> elements);
321  static TemplateListIntfPtr alloc(const std::vector<TemplateVariant> &elements);
322 
323  /** Creates a list */
324  TemplateImmutableList(std::initializer_list<TemplateVariant> elements);
325  TemplateImmutableList(const std::vector<TemplateVariant> &elements);
326  /** Destroys the list */
327  virtual ~TemplateImmutableList();
328 
329  private:
330  class Private;
331  std::unique_ptr<Private> p;
332 };
333 
334 //------------------------------------------------------------------------
335 
336 /** @brief Abstract interface for a context value of type struct. */
338 {
339  public:
340  /** Destroys the struct */
341  virtual ~TemplateStructIntf() {}
342 
343  /** Gets the value for a field name.
344  * @param[in] name The name of the field.
345  */
346  virtual TemplateVariant get(const QCString &name) const = 0;
347 
348  /** Return the list of fields. */
349  virtual StringVector fields() const = 0;
350 };
351 
352 //------------------------------------------------------------------------
353 
354 /** @brief Default implementation of an immutable context value of type struct. */
356 {
357  public:
358  // TemplateStructIntf methods
359  virtual TemplateVariant get(const QCString &name) const;
360  virtual StringVector fields() const;
361 
362  using StructField = std::pair<const std::string,TemplateVariant>;
363 
364  /** Creates an instance and returns a shared pointer to it
365  * @param fields the fields of the struct as key/value pairs.
366  */
367  static TemplateStructIntfPtr alloc(std::initializer_list<StructField> fields);
368 
369  /** Creates a struct */
370  TemplateImmutableStruct(std::initializer_list<StructField> fields);
371  /** Destroys the struct */
372  virtual ~TemplateImmutableStruct();
373 
374  private:
375 
376  class Private;
377  std::unique_ptr<Private> p;
378 };
379 
380 
381 //------------------------------------------------------------------------
382 
383 /** @brief Interface used to escape characters in a string */
385 {
386  public:
387  virtual ~TemplateEscapeIntf() {}
388  /** Create a copy of the escape filter */
389  virtual std::unique_ptr<TemplateEscapeIntf> clone() = 0;
390  /** Returns the \a input after escaping certain characters */
391  virtual QCString escape(const QCString &input) = 0;
392  /** Setting tabbing mode on or off (for LaTeX) */
393  virtual void enableTabbing(bool b) = 0;
394 };
395 
396 //------------------------------------------------------------------------
397 
398 /** @brief Interface used to remove redundant spaces inside a spaceless block */
400 {
401  public:
403  /** Create a copy of the spaceless filter */
404  virtual std::unique_ptr<TemplateSpacelessIntf> clone() = 0;
405  /** Returns the \a input after removing redundant whitespace */
406  virtual QCString remove(const QCString &input) = 0;
407  /** Reset filter state */
408  virtual void reset() = 0;
409 };
410 
411 //------------------------------------------------------------------------
412 
413 /** @brief Abstract interface for a template context.
414  *
415  * A Context consists of a stack of dictionaries.
416  * A dictionary consists of a mapping of string keys onto TemplateVariant values.
417  * A key is searched starting with the dictionary at the top of the stack
418  * and searching downwards until it is found. The stack is used to create
419  * local scopes.
420  * @note This object must be created by TemplateEngine::createContext()
421  */
423 {
424  public:
425  virtual ~TemplateContext() {}
426 
427  /** Push a new scope on the stack. */
428  virtual void push() = 0;
429 
430  /** Pop the current scope from the stack. */
431  virtual void pop() = 0;
432 
433  /** Sets a value in the current scope.
434  * @param[in] name The name of the value; the key in the dictionary.
435  * @param[in] v The value associated with the key.
436  * @note When a given key is already present,
437  * its value will be replaced by \a v
438  */
439  virtual void set(const QCString &name,const TemplateVariant &v) = 0;
440 
441  /** Gets the value for a given key
442  * @param[in] name The name of key.
443  * @returns The value, which can be an invalid variant in case the
444  * key was not found.
445  */
446  virtual TemplateVariant get(const QCString &name) const = 0;
447 
448  /** Returns a pointer to the value corresponding to a given key.
449  * @param[in] name The name of key.
450  * @returns A pointer to the value, or 0 in case the key was not found.
451  */
452  virtual const TemplateVariant *getRef(const QCString &name) const = 0;
453 
454  /** When files are created (i.e. by {% create ... %}) they written
455  * to the directory \a dir.
456  */
457  virtual void setOutputDirectory(const QCString &dir) = 0;
458 
459  /** Sets the interface that will be used for escaping the result
460  * of variable expansion before writing it to the output.
461  */
462  virtual void setEscapeIntf(const QCString &extension, std::unique_ptr<TemplateEscapeIntf> intf) = 0;
463 
464  /** Sets the interface that will be used inside a spaceless block
465  * to remove any redundant whitespace.
466  */
467  virtual void setSpacelessIntf(std::unique_ptr<TemplateSpacelessIntf> intf) = 0;
468 };
469 
470 //------------------------------------------------------------------------
471 
472 /** @brief Abstract interface for a template.
473  * @note Must be created and is deleted by the TemplateEngine
474  */
475 class Template
476 {
477  public:
478  /** Destructor */
479  virtual ~Template() {}
480 
481  /** Renders a template instance to a stream.
482  * @param[in] ts The text stream to write the results to.
483  * @param[in] c The context containing data that can be used
484  * when instantiating the template.
485  */
486  virtual void render(TextStream &ts,TemplateContext *c) = 0;
487 };
488 
489 //------------------------------------------------------------------------
490 
491 /** @brief Engine to create templates and template contexts. */
493 {
494  public:
495  /** Create a template engine. */
496  TemplateEngine();
497 
498  /** Destroys the template engine. */
499  ~TemplateEngine();
500 
501  /** Creates a new context that can be using to render a template.
502  * @see Template::render()
503  */
504  std::unique_ptr<TemplateContext> createContext() const;
505 
506  /** Creates a new template whose contents are in a file.
507  * @param[in] fileName The name of the file containing the template data
508  * @param[in] fromLine The line number of the statement that triggered the load
509  * @return the new template, the engine will keep ownership of the object.
510  */
511  Template *loadByName(const QCString &fileName,int fromLine);
512 
513  /** Indicates that template \a t is no longer needed. The engine
514  * may decide to delete it.
515  */
516  void unload(Template *t);
517 
518  /** Prints the current template file include stack */
519  void printIncludeContext(const QCString &fileName,int line) const;
520 
521  /** Sets the search directory where to look for template files */
522  void setTemplateDir(const QCString &dirName);
523 
524  private:
525  friend class TemplateNodeBlock;
526  friend class TemplateNodeCreate;
527 
528  void enterBlock(const QCString &fileName,const QCString &blockName,int line);
529  void leaveBlock();
530 
531  /** Sets the extension of the output file. This is used to control the
532  * format of 'special' tags in the template
533  */
534  void setOutputExtension(const QCString &extension);
535 
536  /** Returns the output extension, set via setOutputExtension() */
537  QCString outputExtension() const;
538 
539  class Private;
540  std::unique_ptr<Private> p;
541 };
542 
543 /** @} */
544 
545 #endif
TemplateSpacelessIntf::~TemplateSpacelessIntf
virtual ~TemplateSpacelessIntf()
Definition: template.h:402
TemplateVariant::toStruct
TemplateStructIntfPtr toStruct()
Returns the pointer to struct referenced by this variant or 0 if this variant does not have struct ty...
Definition: template.cpp:441
StringVector
std::vector< std::string > StringVector
Definition: containers.h:32
TemplateListIntf::createIterator
virtual TemplateListIntf::ConstIteratorPtr createIterator() const =0
Creates a new iterator for this list.
TemplateImmutableStruct::alloc
static TemplateStructIntfPtr alloc(std::initializer_list< StructField > fields)
Creates an instance and returns a shared pointer to it
Definition: template.cpp:497
TemplateVariant::Type::String
@ String
TemplateVariantList
std::vector< TemplateVariant > TemplateVariantList
Definition: template.h:261
TemplateImmutableList::createIterator
virtual TemplateListIntf::ConstIteratorPtr createIterator() const
Creates a new iterator for this list.
Definition: template.cpp:533
TemplateStructIntf::get
virtual TemplateVariant get(const QCString &name) const =0
Gets the value for a field name.
TemplateListIntf::ConstIterator::toPrev
virtual void toPrev()=0
Moves iterator to the previous element in the list
TemplateVariant::isList
constexpr bool isList() const
Returns TRUE if the variant holds a list value
Definition: template.h:213
TemplateImmutableList::p
std::unique_ptr< Private > p
Definition: template.h:330
TemplateVariant::TemplateVariant
TemplateVariant(FunctionDelegate delegate)
Constructs a new variant which represents a method call
Definition: template.h:166
Variant< bool, int, QCString, TemplateStructIntfPtr, TemplateListIntfPtr, FunctionDelegate, TemplateStructIntfWeakPtr >
TemplateImmutableStruct::p
std::unique_ptr< Private > p
Definition: template.h:376
TemplateContext::~TemplateContext
virtual ~TemplateContext()
Definition: template.h:425
TemplateListIntf::count
virtual uint count() const =0
Returns the number of elements in the list
TemplateEngine::TemplateEngine
TemplateEngine()
Create a template engine.
Definition: template.cpp:5368
TemplateVariant::Type::List
@ List
TemplateListIntf::~TemplateListIntf
virtual ~TemplateListIntf()
Destroys the list
Definition: template.h:295
TemplateEscapeIntf::enableTabbing
virtual void enableTabbing(bool b)=0
Setting tabbing mode on or off (for LaTeX)
TemplateStructIntf::fields
virtual StringVector fields() const =0
Return the list of fields.
TemplateNodeCreate
Class representing an 'create' tag in a template
Definition: template.cpp:3823
TemplateVariant::isFunction
constexpr bool isFunction() const
Returns TRUE if the variant holds a function value
Definition: template.h:215
TemplateImmutableList::Private
Private data of a template immutable list object
Definition: template.cpp:505
TemplateImmutableList::TemplateImmutableList
TemplateImmutableList(std::initializer_list< TemplateVariant > elements)
Creates a list
Definition: template.cpp:514
TemplateEngine::outputExtension
QCString outputExtension() const
Returns the output extension, set via setOutputExtension()
Definition: template.cpp:5411
TemplateVariant::structToString
QCString structToString() const
Definition: template.cpp:5443
TemplateVariant::FunctionDelegate
std::function< TemplateVariant(const std::vector< TemplateVariant > &)> FunctionDelegate
Type representing a function call in a template
Definition: template.h:102
TemplateVariant::call
TemplateVariant call(const std::vector< TemplateVariant > &args=std::vector< TemplateVariant >())
Return the result of apply this function with args.
Definition: template.cpp:454
TemplateNodeBlock
Class representing a 'block' tag in a template
Definition: template.cpp:3600
TemplateVariant::isBool
constexpr bool isBool() const
Returns TRUE if the variant holds a boolean value
Definition: template.h:205
Template::render
virtual void render(TextStream &ts, TemplateContext *c)=0
Renders a template instance to a stream.
TemplateImmutableList::count
virtual uint count() const
Returns the number of elements in the list
Definition: template.cpp:528
TemplateEngine::loadByName
Template * loadByName(const QCString &fileName, int fromLine)
Creates a new template whose contents are in a file.
Definition: template.cpp:5381
TemplateListIntf::at
virtual TemplateVariant at(uint index) const =0
Returns the element at index position index.
TemplateVariant::listToString
QCString listToString() const
Definition: template.cpp:5423
TemplateEscapeIntf::escape
virtual QCString escape(const QCString &input)=0
Returns the input after escaping certain characters
QCString::str
std::string str() const
Definition: qcstring.h:442
TemplateEngine::p
std::unique_ptr< Private > p
Definition: template.h:539
Template
Abstract interface for a template.
Definition: template.h:475
TemplateListIntf::ConstIterator::~ConstIterator
virtual ~ConstIterator()
Destructor for the iterator
Definition: template.h:276
TemplateVariant::m_raw
bool m_raw
Definition: template.h:258
TemplateVariant::isWeakStruct
constexpr bool isWeakStruct() const
Returns TRUE if the variant holds a struct value
Definition: template.h:217
TemplateEngine::setOutputExtension
void setOutputExtension(const QCString &extension)
Sets the extension of the output file.
Definition: template.cpp:5406
TemplateVariant::Type::Struct
@ Struct
TextStream
Text streaming class that buffers data.
Definition: textstream.h:33
TemplateVariant::~TemplateVariant
~TemplateVariant()=default
Destroys the Variant object
qcstring.h
TemplateEngine::printIncludeContext
void printIncludeContext(const QCString &fileName, int line) const
Prints the current template file include stack
Definition: template.cpp:5401
TemplateEscapeIntf::~TemplateEscapeIntf
virtual ~TemplateEscapeIntf()
Definition: template.h:387
TemplateSpacelessIntf::remove
virtual QCString remove(const QCString &input)=0
Returns the input after removing redundant whitespace
TemplateImmutableStruct::TemplateImmutableStruct
TemplateImmutableStruct(std::initializer_list< StructField > fields)
Creates a struct
Definition: template.cpp:470
TemplateStructIntfPtr
std::shared_ptr< TemplateStructIntf > TemplateStructIntfPtr
Definition: template.h:33
TemplateListIntf::ConstIterator
Abstract interface for a iterator of a list.
Definition: template.h:272
TemplateListIntf::ConstIteratorPtr
std::unique_ptr< ConstIterator > ConstIteratorPtr
Definition: template.h:292
TemplateListIntf
Abstract read-only interface for a context value of type list.
Definition: template.h:268
Variant::index
constexpr uint8_t index() const
Returns the index of the type held by this variant, or invalid_id() if the variant does not hold any ...
Definition: variant.h:266
TemplateVariant::Type::Int
@ Int
TemplateSpacelessIntf
Interface used to remove redundant spaces inside a spaceless block
Definition: template.h:399
uint
unsigned uint
Definition: qcstring.h:40
TemplateVariant::TemplateVariant
TemplateVariant(const char *s, bool raw=FALSE)
Constructs a new variant with a string value s.
Definition: template.h:136
Variant::valid
constexpr bool valid() const
Returns true iff the Variant holds a valid type.
Definition: variant.h:255
TemplateEngine::createContext
std::unique_ptr< TemplateContext > createContext() const
Creates a new context that can be using to render a template.
Definition: template.cpp:5376
TemplateVariant
Variant type which can hold one value of a fixed set of types.
Definition: template.h:98
TemplateEngine::Private
Private data of the template engine
Definition: template.cpp:5226
TemplateVariant::isInt
constexpr bool isInt() const
Returns TRUE if the variant holds an integer value
Definition: template.h:207
TemplateImmutableStruct::Private
Private data of a template struct object
Definition: template.cpp:463
Variant::set
void set(Args &&... args)
Replaces the contents of the variant container by constructing a type T calling the constructor with ...
Definition: variant.h:274
TemplateStructIntf::~TemplateStructIntf
virtual ~TemplateStructIntf()
Destroys the struct
Definition: template.h:341
TemplateEscapeIntf::clone
virtual std::unique_ptr< TemplateEscapeIntf > clone()=0
Create a copy of the escape filter
TemplateImmutableList::at
virtual TemplateVariant at(uint index) const
Returns the element at index position index.
Definition: template.cpp:538
TemplateStructIntfWeakPtr
std::weak_ptr< TemplateStructIntf > TemplateStructIntfWeakPtr
Definition: template.h:34
TemplateVariant::TemplateVariant
TemplateVariant(TemplateListIntfPtr l)
Constructs a new variant with a list value l.
Definition: template.h:152
TemplateContext::setEscapeIntf
virtual void setEscapeIntf(const QCString &extension, std::unique_ptr< TemplateEscapeIntf > intf)=0
Sets the interface that will be used for escaping the result of variable expansion before writing it ...
TemplateVariant::TemplateVariant
TemplateVariant()
Constructs an invalid variant.
Definition: template.h:127
TemplateListIntf::ConstIterator::current
virtual bool current(TemplateVariant &v) const =0
TemplateVariant::TemplateVariant
TemplateVariant(TemplateStructIntfPtr s)
Constructs a new variant with a struct value s.
Definition: template.h:147
Template::~Template
virtual ~Template()
Destructor
Definition: template.h:479
TemplateContext::set
virtual void set(const QCString &name, const TemplateVariant &v)=0
Sets a value in the current scope.
TemplateVariant::isStruct
constexpr bool isStruct() const
Returns TRUE if the variant holds a struct value
Definition: template.h:211
Variant::is
constexpr bool is() const
Returns true iff the variant container holds a specific type.
Definition: variant.h:252
TemplateContext
Abstract interface for a template context.
Definition: template.h:422
TemplateVariant::Type::WeakStruct
@ WeakStruct
TemplateEngine::~TemplateEngine
~TemplateEngine()
Destroys the template engine.
Definition: template.cpp:5372
TemplateContext::setOutputDirectory
virtual void setOutputDirectory(const QCString &dir)=0
When files are created (i.e.
TemplateVariant::TemplateVariant
TemplateVariant(int v)
Constructs a new variant with a integer value v.
Definition: template.h:133
TemplateImmutableStruct
Default implementation of an immutable context value of type struct.
Definition: template.h:355
variant.h
TemplateVariant::raw
constexpr bool raw() const
Returns whether or not the value of the Value is raw.
Definition: template.h:245
TemplateVariant::operator==
bool operator==(TemplateVariant &other) const
Compares this QVariant with v and returns true if they are equal; otherwise returns false.
Definition: template.cpp:342
TemplateSpacelessIntf::clone
virtual std::unique_ptr< TemplateSpacelessIntf > clone()=0
Create a copy of the spaceless filter
TemplateImmutableStruct::get
virtual TemplateVariant get(const QCString &name) const
Gets the value for a field name.
Definition: template.cpp:480
containers.h
TemplateContext::get
virtual TemplateVariant get(const QCString &name) const =0
Gets the value for a given key
TemplateImmutableStruct::~TemplateImmutableStruct
virtual ~TemplateImmutableStruct()
Destroys the struct
Definition: template.cpp:476
TemplateListIntfPtr
std::shared_ptr< TemplateListIntf > TemplateListIntfPtr
Definition: template.h:32
TemplateStructIntf
Abstract interface for a context value of type struct.
Definition: template.h:337
TemplateListIntf::ConstIterator::toLast
virtual void toLast()=0
Moves iterator to the last element in the list
TemplateImmutableList::alloc
static TemplateListIntfPtr alloc(std::initializer_list< TemplateVariant > elements)
Creates an instance and returns a shared pointer to it
Definition: template.cpp:543
TemplateVariant::toString
QCString toString() const
Returns the variant as a string.
Definition: template.cpp:399
TemplateVariant::Type::Bool
@ Bool
TemplateVariant::Type::Function
@ Function
TemplateContext::setSpacelessIntf
virtual void setSpacelessIntf(std::unique_ptr< TemplateSpacelessIntf > intf)=0
Sets the interface that will be used inside a spaceless block to remove any redundant whitespace.
TemplateVariant::isValid
constexpr bool isValid() const
Returns TRUE if the variant holds a valid value, or FALSE otherwise
Definition: template.h:203
TemplateImmutableList::~TemplateImmutableList
virtual ~TemplateImmutableList()
Destroys the list
Definition: template.cpp:524
TemplateVariant::TemplateVariant
TemplateVariant(bool b)
Constructs a new variant with a boolean value b.
Definition: template.h:130
TemplateVariant::typeAsString
const char * typeAsString() const
Returns a string representation of this variant's type
Definition: template.cpp:416
TemplateVariant::setRaw
void setRaw(bool b)
Sets whether or not the value of the Variant should be escaped or written as-is (raw).
Definition: template.h:240
TemplateVariant::toBool
bool toBool() const
Returns the variant as a boolean.
Definition: template.cpp:367
TemplateVariant::TemplateVariant
TemplateVariant(const std::string &s, bool raw=FALSE)
Constructs a new variant with a string value s.
Definition: template.h:142
TemplateEscapeIntf
Interface used to escape characters in a string
Definition: template.h:384
TemplateEngine
Engine to create templates and template contexts.
Definition: template.h:492
TemplateEngine::enterBlock
void enterBlock(const QCString &fileName, const QCString &blockName, int line)
Definition: template.cpp:5391
TemplateVariant::TemplateVariant
TemplateVariant(const QCString &s, bool raw=FALSE)
Constructs a new variant with a string value s.
Definition: template.h:139
TemplateVariant::toInt
int toInt() const
Returns the variant as an integer.
Definition: template.cpp:383
TemplateContext::push
virtual void push()=0
Push a new scope on the stack.
TemplateVariant::operator=
TemplateVariant & operator=(const TemplateVariant &v)=default
Assigns the value of the variant v to this variant.
TemplateEngine::setTemplateDir
void setTemplateDir(const QCString &dirName)
Sets the search directory where to look for template files
Definition: template.cpp:5416
TemplateEngine::unload
void unload(Template *t)
Indicates that template t is no longer needed.
Definition: template.cpp:5386
TemplateImmutableList
Default implementation of a immutable context value of type list.
Definition: template.h:311
TemplateContext::getRef
virtual const TemplateVariant * getRef(const QCString &name) const =0
Returns a pointer to the value corresponding to a given key.
TemplateSpacelessIntf::reset
virtual void reset()=0
Reset filter state
TemplateListIntf::ConstIterator::toNext
virtual void toNext()=0
Moves iterator to the next element in the list
TemplateListIntf::ConstIterator::toFirst
virtual void toFirst()=0
Moves iterator to the first element in the list
TemplateVariant::Type
Type
Definition: template.h:114
TemplateImmutableStruct::StructField
std::pair< const std::string, TemplateVariant > StructField
Definition: template.h:362
TemplateVariant::Type::None
@ None
TemplateVariant::toList
TemplateListIntfPtr toList()
Returns the pointer to list referenced by this variant or 0 if this variant does not have list type.
Definition: template.cpp:432
TemplateContext::pop
virtual void pop()=0
Pop the current scope from the stack.
TemplateEngine::leaveBlock
void leaveBlock()
Definition: template.cpp:5396
TemplateImmutableStruct::fields
virtual StringVector fields() const
Return the list of fields.
Definition: template.cpp:486
TemplateVariant::isString
constexpr bool isString() const
Returns TRUE if the variant holds a string value
Definition: template.h:209
TemplateVariant::TemplateVariant
TemplateVariant(TemplateStructIntfWeakPtr s)
Constructs a new variant with a struct value s.
Definition: template.h:157
TemplateVariant::m_variant
VariantT m_variant
Definition: template.h:257
TemplateVariant::type
constexpr Type type() const
Returns the type held by this variant
Definition: template.h:248
FALSE
#define FALSE
Definition: qcstring.h:33
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108