Interpretation of source code by C++-to-UML transformations
By default, the transformation generates UML elements that have the same name and visibility as the source C++ elements. If the transformation cannot transform a C++ element, it ignores the element. The following table lists the output that the transformation generates when it transforms C++ code elements into UML model elements.
| C++ element | UML element |
|---|---|
| Class |
|
| Enumeration |
|
| Namespace |
|
| Nested class, struct, or union |
|
| Specialized template instance |
|
| Struct |
|
| Typedef |
|
| Union |
|
Global variables and global functions
If a C++ project contains a header file that contains global variables but does not contain a class with the same name as the header file itself, the transformation generates a UML class that has the «cpp_globals» stereotype applied. For each global variable in the header file, the transformation generates a corresponding UML attribute in this UML class. For each global method in the header file, the transformation generates a corresponding UML operation in this UML class. The first row in the following table provides an example of this scenario.
| C++ code | Generated UML elements |
|---|---|
Code for a header file called Class1.h:
|
![]() |
Code for a header file called Class1.h:
|
![]() |
- The transformation transforms
global variables into attributes that have the following characteristics:
- The «cpp_type» stereotype is applied
- The isGlobal property is set to true
- The UML class that contains the generated attribute has the same name as the C++ source file that contains the global variable
- The transformation transforms global functions into operations
that have the following characteristics:
- The «cpp_operation» stereotype is applied
- The isGlobal property is set to true
- The UML class that contains the generated operation has the same name as the C++ source file that contains the global function
Preprocessor directives
The transformation does not transform preprocessor directives in the C++ code because these C++ elements cannot be represented in UML. You must specify user-defined preprocessor directives in the user-defined section in the C++ source files.
C++ template classes
If the source C/C++ Development Tools (CDT) project includes a template instantiation that instantiates a class that does not exist in the source CDT project, the transformation transforms the template instantiation into a UML primitive type. The transformation transforms the references to the template instantiation into the appropriate reference to the UML primitive type in the target model.
| C++ template class | UML element |
|---|---|
| Template class definition |
|
| Template class instantiation in a typedef definition |
|
| Template class instantiation not in a typedef definition |
|
C++ member variables in a class, struct, or union
- The generated property has the same name and visibility as the C++ member variable.
- The transformation sets the Type property to an existing C++ primitive
type if the corresponding type of the C++ member variable is a C++
primitive type. Consider the following code:
The transformation creates a mapping between the type of the property x in the UML class named Class1, and the int C++ primitive type. The C++ type library contains the int primitive type.class Class1{ int x; }The following tables list how the transformation sets the Type property if the type of the C++ member variable is a user-defined type.
If the type of the C++ member variable is a user-defined type, the transformation sets the UML Type property to the value of a UML element that corresponds to the user-defined type in the target UML model. If the transformation cannot determine the UML element in the model that corresponds to the user-defined type, the transformation creates a UML primitive type with the same name as the UML element, and sets the Type of the UML property as equal to the name of the new UML primitive type.
| C++ code sample | Value of the Type property |
|---|---|
|
The transformation sets the Type of the property named x1 in UML class Class3 to Class2, which the transformation creates in the target UML model |
The example in the following table lists how the transformation sets the value of the UML Type property when the type of the C++ member variable references a type that is defined in a different CDT project.
| C++ code sample | Value of the Type property |
|---|---|
| CDTProject1 project contains a class named Class1. CDTProject2 project contains a class named Class2:
|
The transformation creates a mapping between the type of the UML property x to the visual element that corresponds to the class named Class1 in the C++ source project named CDTProject1 |
The following table lists additional information that the transformation generates for specific member variables.
| C++ member variable | Additional characteristics of the transformation output |
|---|---|
| const | isStatic property is true |
| mutable | The transformation applies the «cpp_type» stereotype to the property; the isMutable property of the stereotype is set to true |
| static | isStatic property is true |
| volatile | The transformation applies the «cpp_type» stereotype to the property; the isVolatile property of the stereotype is set to true |
C++ member functions in a class, struct, or union
The transformation transforms a C++ member function in a class, struct, or union into a UML operation in the corresponding UML class. The UML operation that the transformation generates has the same name and visibility as the C++ member function. The following table lists the additional information that the transformation generates for specific function parameters.
| C++ member function | Additional characteristics of the transformation output |
|---|---|
| Assignment | The transformation applies the «cpp_assignment» stereotype; the generated operation has the same name and visibility as the = assignment operator. |
| Const | The transformation sets the isQuery property to true. |
| Constructor | The transformation applies the «cpp_constructor»
stereotype. If the constructor methods in the C++ code are overloaded,
for each constructor method in the code, the transformation generates
a corresponding constructor method in the target model. If the transformation encounters duplicate constructor methods in the code, the transformation generates a constructor method for the first one that it encounters. |
| CopyConstructor | The transformation applies the «cpp_copy_constructor»
stereotype. If the copy constructor methods in the C++ code are overloaded,
for each copy constructor method in the code, the transformation generates
a corresponding copy constructor method in the target model. If the transformation encounters duplicate copy constructor methods in the code, the transformation generates a copy constructor method for the first one that it encounters. |
| Destructor | The transformation applies the «cpp_destructor»
stereotype. If the destructor methods in the C++ code are overloaded,
for each destructor method in the code, the transformation generates
a corresponding destructor method in the target model. If the transformation encounters duplicate destructor methods in the code, the transformation generates a destructor method for the first one that it encounters. |
| Friend | The transformation applies the «cpp_operation» stereotype, and sets the isFriend property to true. |
| Inline | The transformation applies the «cpp_operation» stereotype, and sets the isInline property to true. |
| Pure virtual | The transformation sets the isAbstract property to true. |
| Static | The transformation sets the isStatic property to true. |
| Virtual | The transformation applies the «cpp_operation» stereotype, and sets the isVirtual property to true. |
C++ function parameters
- The generated parameter has the same name as the C++ parameter. If the C++ parameter is a return parameter, the transformation generates a parameter that has the parameter type name.
- The transformation sets the Type property of the parameter to a primitive type, or to an existing UML element in the model.
- The transformation sets the default value of the UML parameter
as equal to the value of the C++ parameter. Consider the following
C++ code:
The transformation sets the default value of the generated UML parameter x, in the operation op, to 5.class one{ int op(int x=5); }
| C++ function parameter | Transformation output |
|---|---|
| Reference | The transformation sets the Direction property to inout |
| Return | The transformation sets the Direction property to return |
| Regular (not reference or return parameters) | The transformation sets the Direction property to in |
Type modifiers
C++ member variables, member functions, and parameters might specify type modifiers, such as pointers to types, reference types, and array types. These type modifiers cannot be represented in UML. The following table lists how the transformation transforms type modifiers.
| Type modifier | Transformation output |
|---|---|
| Pointer to a C++ type | The transformation applies the «cpp_type» stereotype
to the UML parameter or property that it generates, and sets the qualifier
attribute to a pointer operator. Consider the following C++ code:
The transformation generates a UML class named MyClass that contains a name variable with the following properties: ![]() |
| Reference to a C++ type | The transformation sets the qualifier attribute
to a reference operator. The transformation only applies the «cpp_type» stereotype when it transforms multiple reference types in the source code. If the transformation transforms a C++ parameter that is a reference type, it sets the direction attribute of the UML parameter to inout. Consider the following C++ code:
The transformation generates a UML class named MyClassClone that contains a return parameter with the following properties: ![]() |
| Array | For a single-dimension array, the transformation sets the multiplicity of the UML parameter or property as equal to the value of the single dimension. The transformation only applies the «cpp_type» stereotype when it transforms multiple dimensional arrays in the source code. The following example shows how the transformation sets the multiplicity for an attribute of type int x[10]: ![]() The transformation sets the lower and upper bound of the multiplicity property to the value of the single dimension of the attribute. |







