Several factors determine how the UML-to-C++ transformation
generates C++ elements from classes, enumerations, and interfaces.
References to Standard Template Library classes
By
default, if a model contains a reference to a class in the Standard
Template Library (STL), the transformation generates an include directive
that specifies the name of the corresponding header file. For example,
if a model contains a reference to the STL class named vector<>,
the transformation generates the following include directive:
#include <vector>.
Tip: You can edit this preference for the UML-to-C++ transformation.
UML classes
The transformation generates
a header file, and optionally, a body file, for each class that you
specify in the source of the transformation configuration. By default,
a body file has .cpp as a file name extension. The transformation
generates C++ structs, unions, and typedefs from UML classes that
have the «cpp_struct», «cpp_union», or «cpp_typedef» stereotype applied.
You must apply the C++ transformation profile before you can apply
these stereotypes to elements in your model. The transformation does
not generate body files for the following items:
- Classes that have the «cpp_typedef» stereotype applied
- Classes that have the «cpp_struct», «cpp_typedef», or «cpp_union»
stereotype applied, and that do not contain operations
- Classes that have the «cpp_struct», «cpp_typedef», or «cpp_union»
stereotype applied, and that contain only abstract operations
- Classes that do not have a stereotype applied, and do not contain
operations
- Classes that do not have a stereotype applied, and contain only
abstract operations
The transformation assigns the name of the class to the header
file and the body file. If the name of the class does not conform
to C++ naming rules, or if the name is not unique, the transformation
assigns a new name to the header and body file. The generated body
file contains an #include directive for the corresponding header file.
The
transformation generates in header files the code for UML template
classes, and method bodies for template classes.
UML enumerations
The transformation generates
a C++ enum for each UML enumeration that you specify in the source
of the transformation configuration. If necessary, the transformation
assigns a unique name that conforms to C++ rules; otherwise, the generated
C++ enumeration has the same name as the UML enumeration. The transformation
transforms UML enumeration literals into C++ enumeration literals.
To
generate anonymous enumerations, you must apply the C++ Transformation
profile to the source model; then apply the «cpp_enum» stereotype
to the enumeration and set its isAnonymousEnum property
to true.
UML interfaces
The transformation transforms
UML interfaces into C++ classes. UML operations in the interface are
transformed into pure virtual C++ methods.
Nested UML classes, enumerations, and interfaces
The
transformation does not generate a separate header and body file for
nested elements. Instead, the transformation adds information about
the nested elements to the header and body file of the class that
contains the nested elements.