The following procedures explain how to create a UML model and transform it into C++ code for a sample project.
To create a UML model:
In Rational Software Architect, switch to the Modeling perspective.
Click File > New > UML model.
Accept the default values, click Finish.
In the Model Explorer view, right-click the
new UML model (denoted by this icon: ); then click Add
UML > Class
The model that you created has one class: Class1.
To transform the model to C++ code:
In the Model Explorer view, right-click the UML model; then click Transform > Run Transformation > UML to C++.
In the Run Transformation dialog, on the Target page, click New Project to create new destination C++ project.
In the New Project wizard, in the Project name field, type Hello World and click Finish.
In the Run Transformation dialog, click Run.
The Hello World project has two new files: Class1.h and Class1.cpp. These files have skeleton C++ code that you can use to start your C++ project. To view these files in the editor double-click them in the Model Explorer view.
The following table lists which UML model elements are transformed into which C++ code elements. For more detailed description see "Interpretation of UML objects."
UML |
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 parameterized class |
"Binding" relationship |
Instantiated class (.h file) |
You can customize the generated code by applying stereotypes form the C++ Transformation profile. For example, to specify UML operation as inline operation:
Apply the C++ Transformation profile to the model.
Apply the cpp_operation stereotype to the operation.
In Properties view, on the Advanced page, set isInline to True.
Run the UML to C++ transformation.
In addition to stereotypes, you can customize the generated code code through transformation properties and code templates.
To specify transformation properties:
Click Window > Preferences.
Expand Modeling, expand Transformations, and click UML to C++ Transformation.
You can use these preferences to change appearance of the generated code and specify standard C++ operations.