Stereotypes of the UML-to-C++ transformation profile

The UML-to-C++ transformation profile contains stereotypes that you can apply to parameters, properties, documentation, specific relationships, classes, packages, and models. Each stereotype has a set of previously defined valid attributes and types.

The following table lists the stereotypes of the profile and their related properties and types.

Note: Do not apply more than one stereotype to a UML model element. The transformation processes only one stereotype for each model element. For UML classes and operations, the transformation processes one stereotype in the order listed in the following table.
Stereotype Applies to Properties Type
«cpp_assignment» Operations isInline Boolean with a default value of false
«cpp_body_comment» Comments that you want to appear in the source code, such as comments for functions and static variables    
«cpp_constructor» Operations isExplicit, isInline Boolean with a default value of false
«cpp_copy_constructor» Operations isExplicit, isInline Boolean with a default value of false
«cpp_dependency» Dependency relationships isInclusionInHeader Boolean with a default value of false; if the value is set to true, it generates an #include directive in the header file
«cpp_destructor» Operations isVirtual, isInline Boolean with a default value of false
«cpp_friend» Dependency relationships   Generates an #include directive in the header file
«cpp_generalization» Generalization relationships, InterfaceRealization relationships GeneralizationKind Enumeration with public, protected, private, and default values (0-public, 1-protected, 2-private, 3-default)
isVirtual Boolean with a default value of false; indicates virtual inheritances
«cpp_namespace» Packages NamespaceName String
«cpp_operation» Operations isInline Boolean with a default value of false; if the value is set to true, it generates the operation as inline and adds the operation body to the corresponding header file
isVirtual Boolean with a default value of false; if the value is set to true, it generates the operation as a virtual function
isFriend Boolean with a default value of false; if the value is set to true, it generates a friend operation
«cpp_properties» Classes, Interfaces, or Enumerations bodyFileExtension C++ body file with the specified extension
headerFileExtension C++ header file with the specified extension
For example, to generate code for a C++ template class in a header file that has .inc as a file name extension, you can apply this stereotype to the class, and set this property to ".inc".
Note: You must associate the .inc file name extension to a C++ header file so that the C/C++ Development Tools recognize .inc as a valid C++ file name extension.
«cpp_struct» Classes    
«cpp_type» Properties, Parameters arrayDimensions String; typically used for specifying multidimensional arrays that are not supported in UML 2.0.

For example, for a property: [10][20]; for a non-return type parameter: [][10]

InitializerKind Enumeration with constructor and assignment values (0-constructor)

If InitializerKind is set to 0, the transformation generates a constructor initializer

If InitializerKind is set to 1, the transformation generates an assignment statement in the constructor

See Example of how the UML-to-C++ transformation transforms elements with the «cpp_type» stereotype applied below.

isAuto, isMutable, isRegister, isVolatile Boolean with a default value of false
qualifier String; contains the part of a C++ type that cannot be modeled in UML, and that appears before the variable name and after the type, such as ** and &
For example, const int **a[12][33] can be represented by these items:
  • A UML property named a
  • isReadOnly=true
    Note: isReadOnly generates the const keyword
  • «cpp_type» stereotype applied
  • qualifier stereotype property set to **
  • arrayDimensions stereotype property set to [12][33]
«cpp_typedef» Classes arrayDimensions String
ImplementationType Specifies the type to which the typedef refers; can be a primitive type or a user-defined type.

User-defined types can be fully qualified or not. If a type name is not fully qualified, the scope of the typedef is applied to the user-defined type.

qualifier Specifies pointer types, constants, and so on
For example, the transformation generates const int **Typedef1[12][13] for the following UML element:
  • A class named Typedef1, stereotyped as «cpp_typedef»
  • ImplementationType int
  • arrayDimensions[12][13]
  • qualifier const **
«cpp_union» Classes isAnonymousUnion Boolean with a default value of false

Example of how the UML-to-C++ transformation transforms elements with the «cpp_type» stereotype applied

In this example, a UML class named Class1 contains the following attributes:
  • An integer attribute named attribute1 with a default value of 5; InitializerKind is set to 0
  • A Boolean attribute named attribute2 with a default value of true; InitializerKind is set to 1
The «cpp_type» stereotype is applied to both attributes. The UML-to-C++ transformation configuration is configured to generate constructors, and no traceability options are enabled. The following table lists the C++ code that the transformation generates.
UML element Transformation output
This image illustrates the class that is described in the example. Class1.cpp:
#include "Class1.h" 
//Begin section for file Class1.cpp
//TODO: Add definitions that you want preserved
//End section for file Class1.cpp


//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
Class1::Class1() : 
attribute1(5)
{
    //TODO Auto-generated method stub
    attribute2 = true;
}

Feedback