控制生成的代码中的 include 声明 UML to C++ Transformation 可以自动生成恰当的 include 声明。 然而,您可能想要根据需要生成更合适的 include 声明。例如,已确定要使用本地方法体的某个类型变量,因此,想要生成包括在文件中的 include 声明建模时,您可能需要创建两个类之间的依赖,然后将 cpp_dependency 原型应用在依赖。这个原型和名为 IsInclusionInHeader 的属性一起出现,该属性值默认为 false。如果需要将 include 声明包括在生成的文件体中,请将这个属性值设为 false;如果需要将 include 声明生成在头文件中,那么,可以不设置依赖的 cpp_dependency 原型,也可以应用原型并将 IsInclusionInHeader 属性值设为 true。
使用文件级别得重用保护部分 如果要使用标准库的类型,或者一些源代码的其它库,您需要在模型中将这些类型设置为普通的字符串。例如,如果要将一个属性声明为整型,您需要在模型中指定它的类型为 vector
转换时,将会把这些类型当成原始类型,并且不会生成任何 include 声明或其它声明。因此,您需要将这些都明确地包含进源文件中。
比如,对于 vector 类型,您应当明确地将 include 声明放置在源代码中,比如 #include 。如列表1所示,在应用 UML 向 C++ 的转换过程中,每个生成的文件都一字不漏地包含一些段落的内容。请注意 //TODO: Add definitions that you want preserved。您添加到 Begin section 和 End section 中的任何内容都将被保存下来。请在此处添加声明,比如这里的 #include 。
列表1. 类 Car 所生成代码
#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
#include "MyType.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
public:
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Operation1()const throw ( MyType);
}; //end Class Class1
#endif |