C++ transformation

The C++ transformation converts UML model elements to C++ code.

What can be converted to C++

The C++ transformation can convert the following UML model elements to C++ code.
  • Model
  • Package
  • Class
  • Enumeration
  • Component
  • Artifact
You can use components and artifacts to organize the elements of your model that you want to convert to C++ code. Selecting an artifact or component causes the C++ transformation to convert related packages and classes to C++ code when any of the following relationships exist:
  • An artifact has a manifestation relationship to components and the components have a usage relationship to packages and classes
  • An artifact has a manifestation relationship to packages or classes
  • A component has a usage relationship to packages and classes

How model elements are converted to C++

The following table shows how the C++ transformation convert the following UML model elements to C++ code.

UML model element C++
Package Folder
Class Class (.h and .cpp files)
Generalization relationship Class inheritance
Association relationship Class attribute
Property Class attribute
Enumeration Enum (.h file)
Operation Operation
Parameter Operation argument
Usage relationship Inclusion
Template parameter Parameter for a parameterized class
Template binding relationship Instantiated class (.h file)

How C++ standard operations are generated

Standard operations are constructors, copy constructors, destructors, and assignment operators. You can specify which of the standard operations the C++ transformation generates. You can also add a stereotype, which represents one of the standard operations, to the operation of a class in your model. The C++ transformation applies the visibility of the UML operation to the generated standard operations, but ignores the name and parameters of the UML operation. The C++ transformation generates standard operations for unions that you have explicitly added to a UML model.

C++ visualization diagrams

You can generate UML visualization diagrams at the same time that you generate C++ code from your UML model. Use UML visualization diagrams to view a graphical representation of your C++ code that you can edit at a graphical or code level. The C++ transformation creates a UML visualization diagram for each UML package. The UML visualization diagram contains the non-nested classes, structures, unions, and enumerations that the C++ transformation generated for the UML package.
Note: The automatic generation of UML visualization diagrams increases the time it takes to generate C++ code and memory consumption.

Where C++ code files are generated

The C++ transformation can only output C++ code files to C++ projects and C++ project folders.

Alternate names for generated files

You can use the mapping feature to specify alternate names for files that the transformation generates without modifying the source model. You can specify absolute and relative file names. Absolute file names must specify an existing project. The transformation creates parent directories that do not already exist. The transformation replaces file name extensions with standard C++ file name extensions such as .h or .cpp.

The transformation bases the names of UML visualization diagrams on the name of the package that contains them. Mapping artifacts do not directly affect the naming of UML visualization diagrams.

The C++ transformation prohibits the following characters in mapping file and directory names:
  • Asterisk (*)
  • Question mark (?)
  • Quotation marks (")
  • Less than symbol (<)
  • Greater than symbol (>)
  • Vertical bar ( | )
Note: Prohibited characters are replaced with an underscore (_) during transformation.

Related tasks
Generating C++ code from a model
Applying the C++ transformation profile

Related reference
Installed transformations

Terms of use | Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.