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 for 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.
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.
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.
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 class | Header file (.h file) that has the same name as the UML template
class The method body code is also generated in the header file |
| Template parameter | Parameter for a parameterized class |
You can configure the transformation to create derived relationships between the transformation source and target. This functionality enables traceability between the UML model elements and generated source code. When you run the transformation, in the generated header file or files, the transformation adds a unique identifier to the source code comments of each transformed element that supports the @generated tag. If necessary, the transformation also refactors the code to reflect the changes to the model. These identifiers enable the UML-to-C++ transformation and, if enabled, the C++-to-UML transformation, to move or rename model or code elements without deleting and then adding the element. This functionality enables the transformation to accurately merge source and target elements, instead of using only the name of the element.
#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
//TODO: Add definitions that you want preserved
//End section for file Class1.h
//@uml.annotationsderived_abstraction="platform:/resource/MyProj/Blank%20Model.emx#_c8rj0FJQEdyKkf6pJAs7Ow"
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{
//Begin section for Class1
//TODO: Add attributes that you want preserved
//End section for Class1
public:
//@uml.annotationsderived_abstraction="platform:/resource/MyProj/Blank%20Model.emx#_c8rj0FJQEdyKkf6pJAs7Ow?DEFCONSTRUCTOR"
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
Class1();
}; //end class Class1
#endif
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.
The transformation generates C++ code files in the C++ projects and folders that you specify as the target of the transformation.
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. You must enable team capabilities to work with configuration management systems.