UML-to-C++ transformations

The UML-to-C++ transformation transforms UML model elements into C++ code.

Valid transformation sources

The UML-to-C++ transformation can convert the following UML source objects into C++ code:
  • Models
  • Packages
  • Classes
  • Enumerations
  • Interfaces
  • Components

You can specify the model elements that the transformation should convert to C++ code when you create or edit a transformation configuration, or by selecting model elements directly in the model. Selected model elements serve as the source of a transformation. The transformation generates an error message if you select both a container and its model elements or the same model element twice.

You can use components to organize the elements of a model that you want to convert to C++ code. If you select a component, the UML-to-C++ transformation converts related packages and classes to C++ code when a component has a usage relationship to packages and classes.

Note: If you enable the reverse transformation, you must specify a model as the transformation source. The C++-to-UML, or reverse, transformation transforms C++ source objects into UML objects and stores these objects in the UML model that you specify.

Valid names for transformation sources

Names for UML source elements can begin with a lowercase letter, uppercase letter, or an underscore (_). The subsequent characters can be lowercase letters, uppercase letters, or numbers. You can use a colon (:) in an operation name to specify fully qualified names for friend functions. The transformation prefixes a name that begins with a number or an invalid character with an underscore (_). The transformation checks that names in a relevant namespace are unique; if the names are not unique, the transformation assigns the duplicate name with _<number> as a suffix.

To improve the readability of the generated code and to minimize the differences between the UML model and generated code, you should correct invalid names in the source UML model before you apply the transformation.

Valid transformation targets

A valid transformation target is a C++ project that contains at least one source folder. If you create a new target container, you can create a standard make C++ project, which uses either a makefile that you create or an existing makefile, or you can create a managed make project, which generates the makefile for you automatically.

Transformation of UML model elements

The following table lists how the UML-to-C++ transformation transforms UML model elements into C++ code.

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

C++ standard operations

Standard operations are constructors, copy constructors, virtual and non-virtual destructors, assignment operators, and getter and setter methods. You can specify which standard operations the UML-to-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 UML-to-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 UML-to-C++ transformation generates standard operations for classes, structs, and unions that you add to a UML model.

The transformation generates constructors and copy constructors by default. You can further control how the transformation generates standard operations by adding operations with specific stereotypes to the UML model. If you create an operation in a class and assign it one of the standard operation stereotypes, the transformation generates the standard operation that you specified.

Location of transformation output

The transformation generates C++ code files in the C++ projects and C++ project folders that you specify as the target of the transformation.

Relative path information for generated #include directives

By default, the transformation generates #include directives that specify relative path information. To instruct the transformation to exclude relative path information, add the following line of code to the eclipse.ini file: -DEXCLUDE_PATH_FOR_INCLUDES=true.

Alternate file name extensions for C++ body files

You can specify alternate file name extensions, such as .cc, for C++ body files that the UML-to-C++ transformation generates. By default, the transformation generates C++ files that have .cpp as a file name extension. To specify a different file name extension, set the BODY_FILE_EXTENSION system property in the eclipse.ini file. For example, to generate files that have .cc as a file name extension, add the following code to the eclipse.ini file: -DBODY_FILE_EXTENSION=.cc.

Integration with team support

The transformation provides integration functionality with CVS, Rational® ClearCase®, and Rational ClearCase LT version control systems, which enables you to automatically check out files or add new files.

Related tasks
Transforming UML models into C++ code
Creating or editing UML-to-C++ transformation configurations
Specifying sources and targets for UML-to-C++ transformations
Enabling team capabilities
Setting preferences for UML-to-C++ transformations
Running UML-to-C++ transformations
Related reference
Interpretation of UML model elements by UML-to-C++ transformations

Feedback