Getting started

Transforming a UML model to C++

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:

  1. In Rational Software Architect, switch to the Modeling perspective.

  2. Click File > New > UML model.

  3. Accept the default values, click Finish.

  4. 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: 

  1. In the Model Explorer view, right-click the UML model; then click Transform > Run Transformation > UML to C++

  2. In the Run Transformation dialog, on the Target page, click New Project to create new destination C++ project. 

  3. In the New Project wizard, in the Project name field, type Hello World and click Finish.

  4. 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.

How UML model elements map to C++ code

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)

Customizing the generated code

You can customize the generated code by applying stereotypes form the C++ Transformation profile. For example, to specify UML operation as inline operation: 

  1. Apply the C++ Transformation profile to the model. 

  2. Apply the cpp_operation stereotype to the operation.

  3. In Properties view, on the Advanced page, set isInline to True.

  4. 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:

  1. Click Window > Preferences.

  2. 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.

Top

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