You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
set (GTEST_BOTH_LIBRARIES "optimized;${GTEST_ROOT}/lib/libgtest.a;debug;${GTEST_ROOT}/lib/libgtestd.a;optimized;${GTEST_ROOT}/lib/libgtest_main.a;debug;${GTEST_ROOT}/lib/libgtest_maind.a")
Every specified field will be reflected into Jinja2Cpp internal data structures and can be accessed from the template without additional efforts. Quite simple! As you can see, you can use 'dot' notation to access named members of some parameter as well, as index notation like this: `enum['enumName']`. With index notation you can access to the particular item of a list: `enum.items[3]` or `enum.items[itemIndex]` or `enum['items'][itemIndex]`.
253
+
Every specified field will be reflected into Jinja2Cpp internal data structures and can be accessed from the template without additional efforts. Quite simply! As you can see, you can use 'dot' notation to access named members of some parameter as well, as index notation like this: `enum['enumName']`. With index notation you can access to the particular item of a list: `enum.items[3]` or `enum.items[itemIndex]` or `enum['items'][itemIndex]`.
250
254
251
255
### 'set' statement
252
256
But what if enum `Animals` will be in the namespace?
I.e. left part of this expression (before 'if') is a true-branch of the statement. Right part (after 'else') - false-branch, which can be omitted. As a condition you can use any expression convertible to bool.
303
307
308
+
## 'extends' statement
309
+
In general, C++ header files look similar to each other. Almost every header file has got header guard, block of 'include' directives and then block of declarations wrapped into namespaces. So, if you have several different Jinja2 templates for header files production it can be a good idea to extract the common header structure into separate template. Like this:
310
+
```c++
311
+
{% if headerGuard is defined %}
312
+
#ifndef {{headerGuard}}
313
+
#define {{headerGuard}}
314
+
{% else %}
315
+
#pragma once
316
+
{% endif %}
317
+
318
+
{% for fileName in inputFiles | sort %}
319
+
#include "{{fileName}}"
320
+
{% endfor %}
321
+
322
+
{% for fileName in extraHeaders | sort %}
323
+
{% if fileName is startsWith('<') %}
324
+
#include {{fileName}}
325
+
{% else %}
326
+
#include "{{fileName}}"
327
+
{% endif %}
328
+
{% endfor %}
329
+
330
+
{% block generator_headers %}{% endblock %}
331
+
332
+
{% block namespaced_decls %}
333
+
{% set ns = rootNamespace %}
334
+
{#ns | pprint}
335
+
{{rootNamespace | pprint} #}
336
+
{% block namespace_content scoped %}{%endblock%}
337
+
{% for ns in rootNamespace.innerNamespaces recursive %}namespace {{ns.name}}
338
+
{
339
+
{{self.namespace_content()}}
340
+
{{ loop(ns.innerNamespaces) }}
341
+
}
342
+
{% endfor %}
343
+
{% endblock %}
344
+
345
+
{% block global_decls %}{% endblock %}
346
+
347
+
{% if headerGuard is defined %}
348
+
#endif // {{headerGuard}}
349
+
{% endif %}
350
+
```
351
+
352
+
In this sample you can see the '**block**' statements. They are placeholders. Each block is a part of generic template which can be replaced by more specific template which 'extends' generic:
{% for class in ns.classes | sort(attribute="name") %}
360
+
361
+
class {{ class.name }}
362
+
{
363
+
public:
364
+
{% for method in class.methods | rejectattr('isImplicit') | selectattr('accessType', 'equalto', 'Public') %}
365
+
{{ method.fullPrototype }};
366
+
{% endfor %}
367
+
protected:
368
+
{% for method in class.methods | rejectattr('isImplicit') | selectattr('accessType', 'equalto', 'Protected') %}
369
+
{{ method.fullPrototype }};
370
+
{% endfor %}
371
+
private:
372
+
{% for method in class.methods | rejectattr('isImplicit') | selectattr('accessType', 'in', ['Private', 'Undefined']) %}
373
+
{{ method.fullPrototype }};
374
+
{% endfor %}
375
+
};
376
+
377
+
{% endfor %}
378
+
{% endblock %}
379
+
```
380
+
381
+
'**extends**' statement here defines the template to extend. Set of '**block**' statements after defines actual filling of the corresponding blocks from the extended template. If block from the extended template contains something (like ```namespaced_decls``` from the example above), this content can be rendered with help of '**super()**' function. In other case the whole content of the block will be replaced. More detailed description of template inheritance feature can be found in [Jinja2 documentation](http://jinja.pocoo.org/docs/2.10/templates/#template-inheritance).
382
+
383
+
## Error reporting
384
+
It's difficult to write complex template completely without errors. Missed braces, wrong characters, incorrect names... Everything is possible. So, it's crucial to be able to get informative error report from the template engine. Jinja2Cpp provides such kind of report. ```Template::Load``` method (and TemplateEnv::LoadTemplate respectively) return instance of ```ErrorInfo``` class which contains details about the error. These details include:
385
+
- Error code
386
+
- Error description
387
+
- File name and position (1-based line, col) of the error
0 commit comments