The UML-to-C++ transformation adds the @generated tag to the following elements:
When you rerun a UML-to-C++ transformation, by default, the transformation does not overwrite method bodies that the transformation generates, or that a user creates. The transformation always preserves method bodies, whether or not you remove the @generated tag.
Although the transformation always preserves method bodies, you must remove the @generated tag from a method to preserve structural changes to the method. For example, you must remove the @generated tag for the method if you change the method signature, add initializers to a constructor, add exceptions to methods, or add comments to the source code.
| UML model element | Generated code | Modified code | Generated code after you rerun the transformation |
|---|---|---|---|
![]() |
Class1.h:#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
//TODO: Add definitions that you want preserved
//End section for file Class1.h
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{
//Begin section for Class1
//TODO: Add attributes that you want preserved
//End section for Class1
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int attribute1;
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1();
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation2();
}; //end Class Class1
#endif
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)"
int Class1::Operation1()
{
//TODO Auto-generated method stub
return 0;
}
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Class1::Operation2()
{
//TODO Auto-generated method stub
return 0;
}
|
Class1.h:#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
#include Class2.h
//End section for file Class1.h
class Class1:public Class2
{
//Begin section for Class1
//TODO: Add attributes that you want preserved
//End section for Class1
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int attribute1;
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1(int parameter1);
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation2();
}; //end Class Class1
#endif
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)"
int Class1::Operation1(int parameter1)
{
int j = 1;
return j;
}
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Class1::Operation2()
{
int i = 2;
return i;
}
|
Class1.h:#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
#include Class2.h
//End section for file Class1.h
class Class1:public Class2
{
//Begin section for Class1
//TODO: Add attributes that you want preserved
//End section for Class1
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int attribute1;
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1();
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation2();
}; //end Class Class1
#endif
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)"
int Class1::Operation1()
{
//TODO Auto-generated method stub
return 0;
}
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Class1::Operation2()
{
int i = 2;
return I;
}
|
| Transformation output | Location and use of the user defined sections |
|---|---|
| Header files and body files | The transformation adds one user-defined section
to the beginning of each of these files. You can use this section
to specify the following types of statements:
|
| Classes, unions, structs, enumerations | You can use these user-defined sections to specify attributes, operations, or both, that you cannot model in UML. For example, you can specify function pointer attributes, such as int myFunction(int* myOtherFunction)attributes in a user-defined section. |
Although the @generated tag and user-defined sections offer flexibility, to avoid possible problems, you should make structural changes to the source UML model instead of the generated code. You can also run the reverse transformation to add new methods or attributes to the source UML model.
| UML model element | Generated code | Attribute added outside a user-defined section | Attribute added to a user-defined section |
|---|---|---|---|
![]() |
Class1.h:
#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
//TODO: Add definitions that you want preserved
//End section for file Class1.h
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{
//Begin section for Class1
//TODO: Add attributes that you want preserved
//End section for Class1
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int attribute1;
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1();
}; //end Class Class1
#endif
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)"
int Class1::Operation1()
{
//TODO Auto-generated method stub
return 0;
}
|
Class1.h:
#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
//TODO: Add definitions that you want preserved
//End section for file Class1.h
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{
//Begin section for Class1
//TODO: Add attributes that you want preserved
//End section for Class1
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int attribute1;
bool attribute2;
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1();
}; //end Class Class1
#endif
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)"
int Class1::Operation1()
{
//TODO Auto-generated method stub
return 0;
}
|
Class1.h:
#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
//TODO: Add definitions that you want preserved
//End section for file Class1.h
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{
//Begin section for Class1
bool attribute2;
//End section for Class1
private:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int attribute1;
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1();
}; //end Class Class1
#endif
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)"
int Class1::Operation1()
{
//TODO Auto-generated method stub
return 0;
}
|