Overview of variants

Variants are used to implement and/or customize advanced code generation from a UML model.

This chapter covers the concept of code generation using variants, the syntax of templates, type libraries and other elements, and common techniques used to make the most of the flexibility and customization capabilities of the Cxx Designer engine.

Concepts

The Cxx Designer engine is based on the following concepts:

  • Active code templates: An active code template (ACT) is a python or java file. It generally follows the text that needs to be generated, involving the navigation through the UML model, extraction of the information from it into the result text, and so on. Active code templates can refer to each other, to allow a better separation of concerns. For information on the syntax of templates and an example of a simple active code template, please see "Template syntax".

  • Product definition file: For each particular model element being processed, the product definition corresponding to its metaclass is considered. A typical generation product is a python file whose content associates the element with a particular ACT, and navigates to some other model elements (typically owned by the current element) to repeat the product process recursively. For more information and an example of a product definition file, see "Product file syntax".

  • Type definitions: A type definition is an XML document that contains additional meta-information for better translation of UML constructs to respective programming language constructs. A typical example is the translation of a UML type into a programming language type. The type definition mainly contains a type expression template that can be used to declare variables for the type in question, as well as several important meta-attributes that are used during generation to find the best matching representation (type definition) for a UML construct, based on its multiplicity and other more advanced characteristics. For an example of an ACT type definition, please see "Type definition syntax".

  • Type library: A type library contains type definition, for example corresponding to a certain general-purpose library that exists for a programming language. For an example of a library definition.

  • Variant: A variant is a customization unit for the Cxx module, containing ACT files, product files or type libraries. A variant must be declared in a Cxx project before being utilized.

Variant’s content example

A variant has a specific directory organization, to make the customization easier. The following image shows the content of the standard variant.

image
Standard variant content

The "acts" directory groups together all active code templates, the "products" directory contains product definition files, and the "types" directory contains all type libraries.

The "description.txt" file is mandatory, and must contain the variant’s description, which will be displayed at runtime when choosing the current variant for a project.

A variant may redefine only part of the module’s behaviour, as the standard behaviour will be taken into account in other cases.

Note: An empty “init.py” file must be created in a variant in order for python ACTs to work correctly.