The transformation generates member variables from UML association relationships. From non-composition associations, the transformation adds the pointer operator (*) to the type qualifier of the attribute. The following table lists the association end properties that the transformation uses to generate C++ elements.
| UML property | C++ element |
|---|---|
| Name | New member variable |
| Visibility | Visibility of the member variable |
The transformation generates an inheritance for the target of a UML generalization relationship and supports multiple inheritance. The transformation includes the target header file in the generated header file. You can specify the scope of the inheritance, and whether or not the inheritance is virtual, by setting the properties of the «cpp_generalization» stereotype.
A dependency relationship usually references a class or an enumeration. By default, the transformation generates a forward reference in the C++ header file, and generates an #include directive in the body file.
To transform a dependency relationship into an #include directive in a header file, set the isInclusionInHeader field of the «cpp_dependency» stereotype to true. Applying the «cpp_friend» stereotype to a dependency relationship also generates an #include directive in the header file, and adds the friend keyword preceding the dependency element name.
A UML class can implement a UML interface. The transformation transforms this relationship into an inheritance on a C++ class. The transformation applies the public keyword to the inheritance if the «cpp_generalization» stereotype is applied to the realization relationship, and if the GeneralizationKind property has a value of public.
The following table lists the code that the transformation generates when it transforms the implementation relationship between Class2 and Interface1, and the dependency relationship with the «cpp_friend» stereotype applied between Class2 and Class1.
| UML elements | Transformation output |
|---|---|
![]() |
#ifndef CLASS2_H
#define CLASS2_H
//Begin section for file Class2.h
//TODO: Add definitions that you want preserved
//End section for file Class2.h
#include "Interface1.h"
#include "Class1.h"
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class2 : Interface1
{
//Begin section for Class2
//TODO: Add attributes that you want preserved
//End section for Class2
public:
friend class Class1;
}; //end Class Class2
#endif
|
The transformation generates a template class from a UML class that has template parameters.
The transformation transforms a UML class that has a binding relationship with a template class named Class1 into an instantiation of the template class Class1. The transformation uses the parameter substitution that the binding relationship specifies to resolve formal parameters into actual parameters.
If a class is the consumer in multiple binding relationships, the transformation only transforms the first binding relationship that it encounters.
The transformation adds the data types of template parameters to the instantiated class inclusion list.
The transformation does not support complex usage patterns of template classes, such as the inclusion of static variables in templates and parameterized classes that are used as formal parameters.
| UML elements | Transformation output |
|---|---|
![]() |
TemplateClass1.h:#ifndef TEMPLATECLASS1_H
#define TEMPLATECLASS1_H
//Begin section for file TemplateClass1.h
//TODO: Add definitions that you want preserved
//End section for file TemplateClass1.h
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
template <class T1>
class TemplateClass1
{
//Begin section for TemplateClass1
//TODO: Add attributes that you want preserved
//End section for TemplateClass1
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
T1 attribute1;
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1(T1 Parameter1);
}; //end Class TemplateClass1
#endif
TemplateClass.cpp:
#include "TemplateClass1.h"
//Begin section for file TemplateClass1.cpp
//TODO: Add definitions that you want preserved
//End section for file TemplateClass1.cpp
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
template <class T1> int TemplateClass1<T1>::Operation1(T1 Parameter1)
{
//TODO Auto-generated method stub
return 0;
}
ParamClass1.h:
#ifndef PARAMCLASS1_H
#define PARAMCLASS1_H
//Begin section for file ParamClass1.h
//TODO: Add definitions that you want preserved
//End section for file ParamClass1.h
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class ParamClass1
{
//Begin section for ParamClass1
//TODO: Add attributes that you want preserved
//End section for ParamClass1
}; //end Class ParamClass1
#endif
UserClass1.h:
#ifndef USERCLASS1_H
#define USERCLASS1_H
//Begin section for file UserClass1.h
//TODO: Add definitions that you want preserved
//End section for file UserClass1.h
#include "TemplateClass1.h"
#include "ParamClass1.h"
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class UserClass1
{
//Begin section for UserClass1
//TODO: Add attributes that you want preserved
//End section for UserClass1
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
TemplateClass1<ParamClass1> attribute1;
}; //end Class UserClass1
Binding1.h:
#ifndef BINDING1_H #define BINDING1_H //Begin section for file Binding1.h //TODO: Add definitions that you want preserved //End section for file Binding1.h #include "TemplateClass1.h" #include "ParamClass1.h" typedef TemplateClass1<ParamClass1> Binding1; #endif |