blob: b529776dc351c228016e0d4431eaeebdb17adb11 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
.. _using-code-templates:
Using Code Templates
--------------------
template
^^^^^^^^
The ``template`` node registers a template that can be used to avoid
duplicate code when extending the generated code, and it is a child of the
:ref:`typesystem` node.
.. code-block:: xml
<typesystem>
<template name="my_template">
// the code
</template>
</typesystem>
Use the ``insert-template`` node to insert the template code (identified
by the template's ``name`` attribute) into the generated code base.
insert-template
^^^^^^^^^^^^^^^
The insert-template node includes the code template identified by the name
attribute, and it can be a child of the
:ref:`inject-code`, :ref:`conversion-rule`, ``template``,
``custom-constructor`` and ``custom-destructor`` nodes.
.. code-block:: xml
<inject-code class="target" position="beginning">
<insert-template name="my_template" />
</inject-code>
Use the replace node to modify the template code.
replace
^^^^^^^
The ``replace`` node allows you to modify template code before inserting it into
the generated code, and it can be a child of the ``insert-template node``.
.. code-block:: xml
<insert-template name="my_template">
<replace from="..." to="..." />
</insert-template>
This node will replace the attribute ``from`` with the value pointed by
``to``.
|