The QM™ code generation process consists of replacing the code-generation directives in the file templates in the model with the corresponding pieces of auto-generated code in the files generated on disk. All other code fragments surrounding the code-generation directives in the file-templates are simply copied to the files on disk. The picture below illustrates the process:
To work effectively with the code-generation directives in QM™, you need to understand the difference between declarations and definitions in C or C++.
A declaration introduces an identifier and describes its type, be it a type name (struct/class/typedef), object (variable), or a function. A declaration is what the C or C++ compiler needs to accept references to that identifier. These are declarations:
extern
only for declarations of variables.A definition actually instantiates/implements the identifier. It's what the linker needs in order to link references to those entities. These are definitions corresponding to the above declarations:
The general syntax of the code-generating directives in the QM file templates is $<directive> ${<model-item>}, where $<directive> is one of:
and <model-item> denotes a Fully-Qualified Name of the model item to expand.
The use of Fully-Qualified Item Names is necessary to unambiguously identify model items for code generation. For example, a class Ship
residing inside the package AOs
will be specified inside a code-generating directive as AOs::Ship
.
Such fully-qualified item names can be, of course, typed by hand in the QM file templates. However, to avoid errors, the Model Explorer allows you to drag-n-drop a model item onto a file-template to create a fully-qualified item name, as illustrated in the animation below:
Next: $declare${}