Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
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

As with attributes, you set the default value in the Initial Value field, set the visibility to Public, Private, or Protected, and check the Const or Static boxes if these keywords are needed. In the Multiplicity field, enter the multiplicity of the relationship.

Component Properties

The Model Assistant is also used to set the code−generation properties for components. Specifically, each component must be assigned to a Visual C++ project before code generation can be completed. You can also assign each component to a project during the code−generation process—the wizard will give you the option to assign components to projects. The Component Model Assistant window is shown here:

431

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

To open the Model Assistant for a component, right−click the component and select Properties. On the General tab, map the component to an existing Visual C++ project file. Optionally, you can set a Visual C++ workspace file as well. If the file is an IDL file, set the IDL filename and path.

The Internal Map tab is used to set up the mapping of classes within the component to include statements. For each mapping, set the class (an asterisk [*] refers to all classes), include the filename, and include the file location. You can add as many mappings as needed.

The External Map tab is very similar, but is used to set up the include statements needed by classes in other components to reference classes in this component.

On the Includes tab, you can set up includes statements to be generated in the header and body files for each class in the component. Add as many includes statements as you need, adding each on a separate line.

Use the COM tab to control how ATL objects will be generated for this component. The Update ATL Artifacts check box controls whether code is generated for ATL objects at all. If you do update the code, complete the rest of the settings on this screen to control how the code is updated:

The Use Smart Pointers for Interface Associations check box will use the Visual C++ smart pointer functionality during code generation and reverse engineering.

The Generate #Import Statements check box controls whether #import statements are created and where they are created.

If there is a value in the Put #Import Statements In field, Rose will put all #import statements in that file.

432

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

If Include Full Path on Imports is checked, Rose will use the full path in the #import statement.

If Use Default Attributes is checked and there is a value in that field, Rose will use the field value when attributes are unspecified in the model.

Finally, you can use the Copyright tab to set copyright information for the component. Text you enter here will be entered into the header and implementation files for the classes in that component.

Project Properties

Using the menu command Tools → Visual C++ → Properties, you can set properties that apply to the whole Rose model.

Table 13.7 lists each Visual C++ project property, its purpose, and the tab on the Visual C++ Properties window you use to set the property.

Table 13.7: Visual C++ Project Properties

Property

Purpose

Tab

Generate Model IDs

Controls whether Rose model IDs are inserted into the

Code Update

 

source code.

 

Generate Documentation

Controls whether comments you entered into the

Code Update

 

Documentation field of a class or other model element

 

 

are generated as comments in the source code.

 

Generate #Include

Controls whether #include statements are added to the

Code Update

Statements

header file.

 

Apply Pattern on Code

Controls whether to apply the selections you made on

Code Update

 

 

 

433

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

Generation

the Operations and Accessors tabs to the generated

 

 

code.

 

Generate Debug

Controls whether AssertValid and Dump operations

Code Update

Operations for MFC

are created for MFC classes.

 

Classes

 

 

Create Backup Files

Controls whether backup files are created for source

Code Update

 

code before Rose modifies them.

 

Support CodeName

Gives the user the option of naming an element

Code Update

 

differently in the model and the source code.

 

Reverse Engineer

Pulls comments from the source code into the

Model Update

Documentation

Documentation field of the model element.

 

Create Overview

Creates an overview diagram for reverse−engineered

Model Update

Diagrams

code.

 

Update Model IDs in

Adds model IDs to the code during the

Model Update

Code

reverse−engineering process.

 

Default Package

Sets the package in which reverse−engineered

Model Update

 

elements are placed.

 

Attribute Types

Controls which types will be modeled as attributes

Model Update

 

rather than roles in reverse engineering.

 

Containers

Sets the container classes that can be used in the

Containers

 

Implementation field for a role.

 

Class Operations

Controls which operations will be generated for a

Class Operations

 

class.

 

Accessors

Controls whether Get and Set operations are generated

Accessors

 

for an attribute or role.

 

Visual C++ and ATL Objects

The Rose Visual C++ add−in includes support for ATL objects. If you are using ATL in your model, you should first import the standard ATL classes. This step will help ensure that the round−trip engineering process works properly. You can import ATL 3.0 classes into your model by selecting Tools → Visual C++ → Quick Import ATL 3.0. The ATL 3.0 classes will be imported into a package called ATL 3.0 in the Logical view. Once the import is complete, you can create relationships between your classes and the ATL classes.

Converting an Existing Class to an ATL Object

You can create new ATL objects in Rose or simply convert existing classes in your Rose model to ATL.

To convert an existing class:

1.

Right−click the class and select COM → New ATL Object.

2.

You will see the ATL Object Properties window.

3.

In the C++ section, enter the short name of the C++ class. The Class field will already be completed for you.

4.

434