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 defined valid attributes and types.

This content applies to version 7.5.4 or later. The following table lists the stereotypes of the profile and their related properties and types.

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
memberInitializers This string specifies the initializer list of the constructor of a class. The list specifies the initial values of the attributes of the class or the parent class.
For example, specify the following string to generate an initializer list for a constructor method for a class named Class1 that has an integer attribute named attribute1 and a string attribute named name1:
attribute1(10),name1("Class1")
Do not enclose the string with single quotation marks. The transformation generates the following constructor:
Class1::Class1() :
attribute1(10),name1("Class1")
{
//TODO Auto-generated method stub
}
«cpp_copy_constructor» Operations isExplicit, isInline Boolean with a default value of false
memberInitializers This string specifies the initializer list of the constructor of a class. The list specifies the initial values of the attributes of the class or the parent class.
For example, specify the following string to generate an initializer list for a constructor method for a class named Class1 that has an integer attribute named attribute1 and a string attribute named name1:
attribute1(10),name1("Class1")
Do not enclose the string with single quotation marks. The transformation generates the following constructor:
Class1::Class1() :
attribute1(10),name1("Class1")
{
//TODO Auto-generated method stub
}
«cpp_dependency» Dependency relationships isForwardReference Boolean with a default value of false; if the value is set to true, it generates a forward declaration of the supplier type in the header file of the client class
Even if you set this property to true, the transformation does not generate a forward reference in the following situations:
  • If the supplier is a typedef, nested type, or enumeration
  • If the client class contains any non-reference or non-pointer types that are of the supplier type
isInclusionInHeader Boolean with a default value of false; if the value is set to true, it generates an #include directive in the header file of the client class
«cpp_destructor» Operations isVirtual, isInline Boolean with a default value of false
«cpp_enum» Enumerations isAnonymousEnum Boolean with a default value of false; if the value is set to true, the transformation generates an anonymous enumeration
«cpp_external_inclusion» Classes, interfaces includeType Enumeration with values that specify how the transformation generates include directives when the imported class is not part of the transformation source
relativeToFolderInput String; required if you specify the Generate include directives that are relative to this folder value in the includeType property
specificFileNameInput String; required if you specify the Generate an include directive that contains the following file name value in the includeType property
«cpp_friend» Dependency relationships   Generates an #include directive in the header file, and declares the supplier class as a friend of the client class
«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_internal_inclusion» Classes, interfaces includeType Enumeration with values that specify how the transformation generates include directives when the importing class and the imported class are part of the transformation source
relativeToFolderInput String; required if you specify the Generate include directives that are relative to this folder value in the includeType property
specificFileNameInput String; required if you specify the Generate an include directive that contains the following file name value in the includeType property
«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
isGlobal Boolean with a default value of false; if the value is set to true, it generates a global function
«cpp_properties» Classes, interfaces, 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 (CDT) recognize .inc as a valid C++ file name extension.
«cpp_struct» Classes    
«cpp_type» Properties, parameters arrayDimensions This string is typically used to specify multidimensional arrays that UML 2.0 does not support.

For example, use this string to specify an array for a property: [10][20]; or for a non-return type parameter: [][10]

InitializerKind This enumeration has constructor and assignment values (0-constructor).

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

If the InitializerKind property 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.

isAuto, isMutable, isRegister, isVolatile Boolean with a default value of false
qualifier This 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
  • The isReadOnly stereotype property set to true
    Note: The isReadOnly property generates the const keyword
  • The «cpp_type» stereotype applied
  • The qualifier stereotype property set to **
  • The arrayDimensions stereotype property set to [12][33]
Attributes isGlobal Boolean with a default value of false; if the value is set to true, it generates a global variable
«cpp_typedef» Classes arrayDimensions String
ImplementationType This string specifies the type to which the typedef refers; it 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 This string specifies pointer types, constants, and so on.
For example, the transformation generates const int **Typedef1[12][13] for a UML element of the following description:
  • 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; the InitializerKind property is set to 0
  • A Boolean attribute named attribute2 with a default value of true; the InitializerKind property 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