| DCMP | UML source objects |
|---|---|
| Conceptual Models Seed Concrete Models | You can select the following
elements from one or more UML projects in the current workspace:
|
| Conceptual Models Drive Development | |
| Reconciled Modeling | You can select one or more elements in the preceding
list. If you select multiple packages or non-nested classifiers as the source of the UML-to-C++ transformation, they must be contained in the same UML model. If you select one or more non-nested classifiers as the source of the UML-to-C++ transformation, the reverse, or C++-to-UML, transformation determines the root-level package of the first non-nested classifier that the reverse transformation processes. The reverse transformation generates its output in this root-level package. |
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 are 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 a suffix that consists of an underscore and an incremental number; for example, _1.
To improve the readability of the generated code and to minimize the differences between the UML model and generated code, correct the unusable names in the source UML model before you run the transformation.
A valid transformation target is a C++ project. If you create a 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.
When the UML-to-C++ transformation runs, it generates output in the target C++ project, and the output has the same hierarchy as the elements in the source UML model. If you select the Reconciled Modeling DCMP in the transformation configuration, when the C++-to-UML, or reverse, transformation generates UML elements in the same hierarchy as the C++ project.
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, forward reference, or none Note: Settings on
the C++ Properties page of the Properties window determine what is
generated in the header and implementation files.
|
| 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 Note: The method body code is also generated in the header
file.
|
| Template parameter | Parameter for a parameterized class |
For more information about how the transformation transforms UML model elements, see the related reference topic at the end of this topic.
To understand how the elements of a source model relate to the elements in a target project, you can have a transformation create trace relationships from the source model elements to the generated elements in the target project. You can then view the trace relationships in a topic diagram by creating and running model queries.
Creating trace relationships is useful in large projects that might contain multiple models and multiple transformation configurations. You can also create and run traceability queries that display how the transformation output relates to software specifications and model elements.
The transformation does not alter the source model when you specify that the transformation generate trace relationships.
| UML element | Transformation output | Derived relationship in a class diagram |
|---|---|---|
![]() |
#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/MyModels/UMLModel.emx#_biwQUHdCEduVaMk1fL7Qcw"
//@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
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int attribute1;
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1();
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation2();
}; //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 for the classes, structs, and unions in a UML mode. 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 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 IBM® Rational® Team Concert, 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.