Template Symbols and Rules
Introduction
Template Symbol Groups and Template Symbols describe custom file processing (CFP)
template symbols and rules for using them. The location of a symbol in one of the supplied
template files (code_c_template.cgt
,
code_h_template.cgt
, data_c_template.cgt
, or
data_h_template.cgt
) determines where the items associated with that
symbol are located in the corresponding generated file. Template Symbol Groups identifies the symbol groups, starting with the parent
(“Base”) group, followed by the children of each parent. Template Symbols lists the symbols alphabetically.
Note
If you are using custom CGT sections, for files generated to the
_sharedutils
folder, you can only use symbol names in the Base symbol
group.
Template Symbol Groups
Symbol Group | Symbol Names in This Group |
---|---|
Base (Parents) |
|
Declarations |
|
Defines |
|
Definitions |
|
Documentation |
|
| |
Functions |
|
Types | This parent has no children. |
Template Symbols
Symbol Name* | Symbol Group | Symbol Scope | Symbol Description (What the symbol puts in the generated file) |
---|---|---|---|
| Documentation | N/A | User-supplied description of the model or file. Placed in the generated file based on the Stateflow® note, Simulink® annotation, or DocBlock on the model.** |
| Documentation | N/A | Comments located near top of the file. Contains information that includes model and software versions, and date file was generated. |
| Functions | File | C/C++ functions. Must be at the bottom of the template. |
| Documentation | N/A | Date when model was created. From Created on field on Model Properties dialog box. |
| Documentation | N/A | User who created model. From Created by field on Model Properties dialog box. |
| Documentation | N/A | Date file was generated. Taken from computer clock. |
| Base | Data declaration of a signal or parameter. For example, | |
| Base | File | Required |
| Base | File | Data definitions of signals or parameters. |
| Documentation | N/A | Description of model. From Model description field on Model Properties dialog box.** |
| Base | N/A | Comments about how to interpret the generated files. |
| Base | File | Enumerated data type definitions. |
| Declarations | External | *** |
| Declarations | External | *** |
| Declarations | External | *** |
| Declarations | External | *** |
| Documentation | N/A | Name of the generated file. |
| Definitions | File | ***, **** |
| Definitions | File | ***, **** |
| Definitions | File | ***, **** |
| Definitions | File | ***, **** |
| Base | File | Generated function code. |
| Definitions | Global | *** |
| Definitions | Global | *** |
| Definitions | Global | *** |
| Definitions | Global | *** |
| Documentation | N/A | User-supplied revision history of the generated files. Placed in the generated file based on the Stateflow note, Simulink annotation, or DocBlock on the model.** |
| Base | File |
|
| Documentation | N/A | Date when model was last saved. From Last saved on field on Model Properties dialog box. |
| Documentation | N/A | User who last saved model. From Last saved by field on Model Properties dialog box. |
| Defines | File |
|
| Defines | File | C/C++ macros local to the file. |
| Documentation | N/A | Name of the model. |
| Documentation | N/A | Number incremented by 1 each time you save the model. |
| Documentation | N/A | Name of user who last modified the model. |
| Documentation | N/A | User-supplied miscellaneous notes about the model or generated files. Placed in the generated file based on the Stateflow note, Simulink annotation, or DocBlock on the model.** |
| Documentation | N/A | A list of the versions of the toolboxes used in generating the code. |
| Base | Data types of generated code. |
* Symbol names must be enclosed between %< >
. For example,
%<Functions>
.
** This symbol can be used to add a comment to the generated files. See Add Global Comments in the Generated Code. The code generator places the comment in each generated file whose template has this symbol name. The code generator places the comment at the location that corresponds to where the symbol name is located in the template file.
*** The description can be deduced from the symbol name. For example,
GlobalCalibrationScalar
is a symbol that identifies a scalar. It
contains data of global scope that you can calibrate.
**** The FilescopeCalibrationLookup1D
,
FilescopeCalibrationLookup2D
,
FilescopeCalibrationScalar
, and
FilescopeVariableScalar
symbols are not related to the
FileScope
storage class. They do not affect data packaging and are not
affected by data packaging.
Rules for Modifying or Creating a Template
The following are the rules for creating an MPF template. Comparison of a Template and Its Generated File illustrates several of these rules.
Place a symbol on a template within the
%< >
delimiter. For example, the symbol namedIncludes
should look like this on a template:%<Includes>
. Note that symbol names are case-sensitive.Place a symbol on a template where desired. Its location on the template determines where the item associated with this symbol is located in the generated file. If no item is associated with it, the symbol is ignored.
Place a C/C++ statement outside of the
%< >
delimiter, and on a different line than a%< >
delimiter, for that statement to appear in the generated file. For example,#pragma message ("my text")
in the template results in#pragma message ("my text")
at the corresponding location in the generated file. Note that the statement must be compatible with your C/C++ compiler.Use the
.cgt
extension for every template filename. ("cgt
" stands for code generation template.)Note that
%% $Revision: 1.1.4.10.4.1 $
appears at the top of the MathWorks supplied templates. This is for internal MathWorks use only. It does not need to be placed on a user-defined template and does not show in a generated file.Place a comment on the template between
/* */
as in standard ANSI® C1 . This results in/*comment*/
on the generated file.Each MPF template must have all of the Base group symbols, in predefined order. They are listed in Template Symbol Groups. Each symbol in the Base group is a parent. For example,
Declarations
is a parent symbol.Each symbol in a non-Base group is a child. For example,
LocalMacros
is a child.Except for Documentation children, children must be placed after their parent, before the next parent, and before the
Functions
symbol.Documentation children can be located before or after their parent in any order anywhere in the template.
If a non-Documentation child is missing from the template, the code generator places the information associated with this child at its parent location in the generated file.
If a Documentation child is missing from the template, the code generator omits the information associated with that child from the generated file.
1 ANSI is a registered trademark of the American National Standards Institute, Inc.