Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 13: ANSI C++ and Visual C++ Code Generation and Reverse Engineering

Figure 13.3: ANSI C++ component customization window's Style tab

Under the Indentation area, you choose whether to use spaces or tabs for indentation and the number of spaces or tabs to use. Under Round−Trip Engineering Options, select Code Generation Only for Model IDs if you would like model IDs generated in the source code. Select Code Generation and Reverse Engineering if you would also like to insert model IDs into code that has been reverse engineered. Select Never Generate Model IDs if you don't want to use the IDs at all. Although the IDs are optional, they are recommended if you plan to do round−trip engineering. The ID will help Rose map the appropriate source code to the appropriate class or other model element, even if the class name has been changed.

Under the Brace Styles area, select one of the five indentation styles for namespaces, classes, and functions.

Use the Internal Map tab to set the #include statements that will be created for references to classes within the component. Use the External Map tab to set the #include statements that will be created for references to classes within the component by classes outside of the component. Finally, enter any #include statements for the header or body in the Includes tab.

Role Properties

Role properties are the C++ code−generation properties that affect the code generated for relationships. As with most of the other property sets, there are two places to set these properties. To set them for all relationships, select Tools → Options, then click the ANSI C++ tab and select Role from the drop−down list box. To set them for a single relationship, open the relationship specification window. On the ANSI C++ tab of the relationship specification window, you can change the properties for that relationship.

Table 13.6 lists the role properties, their meanings, and their default values.

Table 13.6: Role Code−Generation Properties

Property

Purpose

Default

Synchronize

Controls whether the relationship will be included in

True

 

code generation and reverse engineering.

 

CodeName

Sets the name of the relationship in the generated

<blank>

 

code.

 

Const (Rose 2000A)

False

False

427

Chapter 13: ANSI C++ and Visual C++ Code Generation and Reverse Engineering

InitialValue

Sets the initial value of the attribute created to support

<blank>

 

the relationship.

 

Generalization Properties

As with other relationships, you can set code−generation properties for generalization (inheritance) relationships in C++. There is, however, only one property you can set for a generalization relationship. The Synchronize property controls whether the relationship will be included in code generation and reverse engineering. The default value is True.

Visual C++ Code−Generation Properties

The Visual C++ add−in includes a Model Assistant, which you use to set the code−generation properties for your classes, attributes, operations, and other model elements. Once the properties have been set, the Visual C++ add−in includes a wizard that will walk you through all the steps needed to generate your code.

Class Model Assistant

To start the Model Assistant, right−click a class or component and select Model Assistant. The Model Assistant for a class is shown here:

As you can see, the Model Assistant lets you set code−generation properties for the class, as well as its attributes, operations, and associations. In Rose, you can automatically generate certain operations, such as a constructor and a destructor, by selecting them in the Class Operations section of the treeview.

To begin, select the class name (in this example "NewClass" at the top level of the treeview). Select the Generate Code check box if you would like Rose to generate Visual C++ code for this class. In the Class Type list box, select the class stereotype: class, structure, union, typedef, or enum. In the Code Template list box, you can optionally select a template to use. A template contains attributes, operations, and code that can be

428

Chapter 13: ANSI C++ and Visual C++ Code Generation and Reverse Engineering

used to create a class. In the Documentation field, you can enter text that will be generated as comments in the code.

In the Attributes section of the treeview, you can select an attribute to modify. Once you select an attribute, you can then set its data type using the Type field. Standard Visual C++ data types will appear in the list. If the attribute should have a default value, fill in the Initial Value field. Set the attribute's visibility (public, private, or protected). By default, Rose sets all attributes to Private. The Static check box will add the "static" keyword to the generated code. As with classes, text entered in the Documentation field will appear as a comment in the generated code.

Select an operation in the Operations section of the treeview. In the Return Type field, set the data type of the operation's return value. Standard Visual C++ data types are listed in this field. Set the visibility (public, protected, or private) using the Access Level field. By default, an operation has public visibility. You can create a virtual or abstract operation by setting the Operation Kind field. Select the Inline check box to include the "inline" keyword with the operation. An inline operation's definition is generated in the header file for the class. Select the Const check box to add the "const" keyword to the operation and to signify that the operation will return a constant. To make an operation static or to give it friend visibility, select Static or Friend from the list in the Linkage field.

429

Chapter 13: ANSI C++ and Visual C++ Code Generation and Reverse Engineering

By default, Rose will not add code to the body of a generated method. To add some default code, select the Replace Existing Code Body check box and add the text in the Default Code Body field. Add comments to the Documentation field.

An operation's parameters are listed in the treeview under the operation name. To edit a parameter, select it in the treeview. You can then change its data type, default value, and documentation.

As with ANSI C++, associations in Visual C++ are generated as attributes. In the Model Assistant, the attributes generated for associations are listed in the Associations portion of the treeview. In the Implementation field, you can set the type of reference to generate. By default, Rose will generate a pointer to the referenced class. You can also use an array, reference, or user−defined type. Select the appropriate value from the Implementation list box.

430