Comparison of a Template and Its Generated File
This figure shows part of a user-modified custom file processing (CFP) template and the resulting generated code. The figure illustrates how you can use a template to:
Define what code the code generation software should add to the generated file
Control the location of code in the file
Optionally insert comments in the generated file
Notice %<Includes>
, for example, on the template. The term
Includes
is a symbol name. A percent sign and brackets (%<
>
) must enclose every symbol name. You can add the desired symbol name (within
the %< >
delimiter) at a particular location in the template. This is
how you control where the code generator places an item in the generated file.
Template and Generated File
Mapping Template Specification to Code Generation
This part of the template... | Generates in the file... | Explanation | ||
---|---|---|---|---|
Line | Description | |||
(1) | /*#INCLUDES*/ %<Includes > | 26–28 | An /*#INCLUDES*/ comment, followed by
#include statements | The code generator adds the C/C++ comment as a header, and then interprets the
%<Includes> template symbol to list the required
#include statements in the file. This code is first in this
section of the file because the template entries are first. |
(2) | /*#DEFINES*/ %<Defines> | 30 | A /*#DEFINES*/ comment, but no
#define statements | Next, the code generator places the comment as a header for
#define statements, but the file does not need
#define . No code is
added. |
(3) | #pragma string1 | 31 | #pragma statements | While the code generator requires %<>
delimiters for template symbols, it can also interpret C/C++ statements in the
template without delimiters. In this case, the generator adds the specified
statements to the code, following the order in which the statements appear in the
template. |
(5) | #pragma string2 | 42 | ||
(4) | /*DEFINITIONS*/ %<Definitions> | 32–41 | /*DEFINITIONS*/ comment, followed by definitions | The code generator places the comment and definitions in the file between the
#pragma statements, according to the order in the template. It
also inserts comments (lines 33 and 36) that are preset in the model's Configuration
Parameters dialog box. |
(6) | %<Declarations> | 43 | No declarations | The file needs no declarations, so the code generator does not generate declarations for this file. The template does not have a comment to provide a header. Line 43 is left blank. |
(7) | %<Functions> | 44–74 | Functions | Finally, the code generator adds functions from the model, plus comments that are preset in the Configuration Parameters dialog box. But it adds no comments as a header for the functions, because the template does not have one. This code is last because the template entry is last. |
For a list of template symbols and the rules for using them, see Template Symbol Groups, Template Symbols, and Rules for Modifying or Creating a Template. To set comment options, in the Configuration Parameters dialog box, select the Code Generation > Comments pane. For details, see Configure Code Comments.