Modeling Visual C++ Classes

By default, a class in Visual Modeler, which is assigned to a Visual C++ component, is considered to correspond to a class in Visual C++. For classes that should be generated as other code constructs, you have to change their stereotype before you run the Generate Code command.

To specify the implementation type of a class:

1. 	Assign the class to a component with the Visual C++ language assignment.

2. 	Open the specification for the class, by double-clicking on the class.

3. 	On the General tab, click the arrow in the Stereotype field to obtain a list with the available stereotypes.

4. 	Select the stereotype that corresponds to the implementation type of the class.

To specify that a Visual C++ class is not supposed to be generated:

1. 	Open the specification for the class, by double-clicking the class.

2. 	On the Visual C++ tab, select the Generate model property.

3. 	Click in the Value field to obtain a list of the available values, and select False.

Even if the class is selected when the Visual C++ code generator is invoked, no code will be generated for it.

Note: To generate proper code for classes that reference MFC types, you must first import the MFC classes into your model. See Importing MFC Classes.

See Also

Code Generated for Classes

Stereotypes of Classes


Modeling Abstract, Virtual, or Const Methods - VC++

To model either an abstract, virtual, or const method:

1.	Create the method.

2.	In the browser or in the class specification, double-click on the method to open its specification.

3.	In the Stereotype field on the General tab, select Abstract, Virtual, or Const.

To model an abstract const method or a virtual const method:

1.	Create the method.

2.	In the browser or in the class specification, double-click on the method to open its specification.

3.	In the Stereotype field on the General tab, enter “Abstract, Const” or “Virtual, Const”.

Note: You can also specify the stereotype of a method directly on a diagram, by selecting the method in the class compartment and editing the “<<>>” field.

See Also

Code Generated for User-Defined Methods

Stereotypes of Methods


Modeling Pointers, Arrays, and References - VC++

Pointers, arrays, and references can be modeled in two different ways: by using association relationships or by using properties. The chosen approach depends on the type of the referenced item. For built-in or low-level types, properties should be used, whereas association relationships should be used to model pointers, arrays, and references to user-defined classes.

To model a pointer, array, or reference of a built-in or low-level type:

1.	Double-click on the class to which the variable should belong.

2.	On the Properties tab, right-click in the list of properties and click Insert.

3.	In the Name field, enter the name of the variable using Visual C++ syntax (e.g. “pRect” or “ppv[MAX]”.)

4.	Click twice in the Type field and enter the variable type (e.g. “CRect*” or “void**”.) Click here to view a list of examples.

To model a pointer, array, or reference to a user-defined class:

1.	In a class diagram, create an association relationship between the class and the referenced class.

2.	Point to the referenced object’s side of the relationship and press the right mouse button.

3.	Click Role Name on the displayed menu. A default name for the role is inserted into the diagram.

4.	Specify the type of the variable, by editing the role name using Visual C++ syntax. Click here to view a list of examples.

See Also

Code Generated for Association Relationships

Code Generated for Class Properties


To generate:	Enter type:	Enter name:

Crect* 	pRect;	“CRect*”	“pRect”

int 	a[20];	“int”	“a[20]”

Foo& 	rfoo;	“Foo&”	“rfoo”

void** 	ppvArr[20];	“void**”	“ppv[MAX]”


To generate:	Enter role name:

Customer *theCustomer;	“+theCustomer” or

“+*theCustomer”

Customer &theCustomer;	“+&theCustomer”

Customer *Customers[25];	“+Customers[25]”

Customer **ppCust;	“+**ppCust”

Customer *purchasers[MAX];	“+*purchasers[MAX]”


Generating Code for a Component into a New Visual C++ Project

1.	Create a new project in Microsoft Visual C++.

2.	In Visual Modeler, select the component that models the new project. (For information on how to create a new component, see Creating a Visual C++ Component.) To generate only some of the classes that are assigned to the component, select those classes.

3.	Click Generate Code on the Tools menu.

4.	The Open Visual C++ Project for Component… dialog box is displayed, where you associate the selected component with a project file. Select the project file for the project that you created during step 1.

5.	Click Open to start the code generation.

6.	Visual Modeler generates header and body files for all classes assigned to the selected component (except for classes with the model property Generate=False). The result of the code generation is summarized on the Summary page, which is displayed when the code generator has finished.

7.	Review the generated source code before you continue modeling and coding.

See Also

Components and Visual C++

Creating a VC++ Component

Assigning Classes to Existing Components

Updating a Visual C++ Project from Changes in a Model


Updating a Visual C++ Project from Changes in a Model

The Visual C++ code generator can be used to add new classes to a project, but it cannot be used to update the existing classes in a project.

When generating Visual C++ code for a class, Visual Modeler creates a new header and body file for the class. The code generated into the new files is based on the information found in the model. If the class and its header and body files already exist in the target project, any modifications you have made to the code will be lost in the new header and body files. Therefore, the Visual C++ code generator can only be used the first time a Visual C++ class is generated.

Note: If the header or body file of a generated class already exists in the target project, Visual Modeler renames the existing files before creating the new files. Header files will be renamed with a “.~h” suffix and body files will be renamed with a “.~cp” suffix.

To rename, delete, or update an existing class in a Visual C++ project:

If you have renamed or deleted a class, or updated its properties, methods, or associations in the model, and want to make the same changes to the corresponding class in a Visual C++ project, you have to update the code manually.

To add new classes to a Visual C++ project:

1.	Open the model from which you want to generate code.

2.	Assign the new classes to the Visual C++ component that implement them.

3.	Select the new classes only.

4.	Choose Generate Code from the Tools menu. The Open Visual C++ Project for Component… dialog box is displayed. If you have generated code from this component before, the corresponding project file is selected by default.

5.	If needed, associate the component with a Visual C++ project by selecting the project file. Then click Open.

6.	Visual Modeler starts Microsoft Visual C++, if needed, opens the selected project, and generates header and body files for the selected classes. If Visual Modeler detects a header or body file with the same name as a selected class, you have to confirm the renaming of each such file before the new file is created (as in the dialog box below). Header files will be renamed with the “.~h” suffix and body files will be renamed with the “.~cp” suffix.

7.	The result of the code generation is summarized on the Summary page, which is displayed when the code generator has finished. Be sure to review the generated source code before you continue modeling and coding.

See Also

Creating a VC++ Component

Assigning Classes to Existing Components

Generating Code for a Component into a New Visual C++ Project


Creating a VC++ Component

To create a new component with classes assigned to it:

1.	Select the classes that are to be assigned to the new component.

2.	On the Tools menu, click Assign to New Component.

3.	Select the desired component type from the list. A new component of the chosen type is created in the model with the selected classes assigned to it.

4.	To change the name of the new component, click on the component in the browser and edit the default generated name.

When generating code for the component, you will associate the component with its Visual C++ project.

To create a new component and assign classes manually:

1.	Create a new component in the browser or on a component diagram.

2.	Double-click on the new component to open its specification.

3.	In the Language field on the General tab, select Visual C++. Optionally, select or enter the stereotype that corresponds to the type of the corresponding Visual C++ project.

4.	On the Realizes tab of the Component Specification, select Show all classes. Assign each class that should belong to the new component by clicking with the right mouse button on the class, and then click Assign on the displayed menu.

When generating code for the component, you will associate the component with its Visual C++ project.

See Also

Components and Visual C++

Assigning Classes to Existing Components


Assigning Classes to Existing VC++ Components

To assign several classes to an existing component:

1.	Select the component in the browser or in a component diagram, and open its specification.

2.	On the Realizes tab, select the Show All Classes option.

3.	Select the classes that are to be assigned to this component, right-click on the selection and click Assign on the displayed menu.

Note:  You can also drag each class or interface from the browser and drop it on the appropriate component in a component diagram or in the browser, or on the Realizes tab of the Component Specification.

To assign one class to existing components:

1.	Select the class in the browser or in a diagram, and open its specification.

2.	On the Components tab, select the Show All Components option.

3.	Right-click on the appropriate component and click Assign.

Note:  You can also drag the component from the browser and drop it on the appropriate class in a diagram or in the browser, or on the Components tab of the Class Specification.

See Also

Creating a VC++ Component


Reviewing the Generated Visual C++ Code

After generating Visual C++ code from a model, you should review the code before you continue modeling and coding. To review the generated code:

1.	Open the log in Visual Modeler by selecting Log on the Window menu to view the status of the code generation.

2.	Compile compile the project (in Microsoft Visual C++) to make sure that the generated code is free from syntax errors.

3.	Inspect the generated source code by browsing the code generated for each class.

When you are satisfied, save the code in your Microsoft Visual C++ environment.


Browsing the Generated Code for a Class in the Model - VC++
Browsing the Code Generated for a Class - VC++

To open the implementation file that corresponds to a class in the model:

1.	Select the class in Visual Modeler.

2.	Click Source Code on the Browse menu. You can also click Browse Code on the context menu, or use the CTRL+K shortcut key.

To open the header file that corresponds to a class in the model:

1.	Select the class in Visual Modeler.

2.	Press CTRL+H.


Adding External Components to a Model - VC++

To add an external software module to your model:

1.	Drag the module (the .exe, .dll, .ocx, or .tlb file) from the Microsoft Visual Component Manager or from the Microsoft Explorer and drop it in an open component diagram, or on a component package in the browser.

2.	If the module contained all necessary information (Note: which is not always the case if you drag it from the Microsoft Explorer) the component is created in the following way:

•	If the drop target is a component package or one of its diagrams, the new component will belong to that package. Otherwise, the new component is added to the top-level of the Component View and to the main component diagram.

•	A logical package with the same name as the new component is created in the logical view. The new logical package contains the interface items that are provided by the corresponding software module. The interface of the new component can now be used by the classes in the model.

•	If the drop target is a logical package or one of its diagrams, the logical package for the new component is added to that package.

If the module did not contain the necessary information, Visual Modeler assumes that you want to attach the file to the drop target instead. If that was not your intention, open the specification of the drop target and, on the Files tab, remove the file from the list.


Importing MFC Classes - VC++

To be able to show how the classes in your model depend on the classes in MFC 4.21, you can use a special command to add the MFC classes to your model.

To import the classes in MFC 4.21 into your model:

1.	Choose Visual C++ from the Tools menu, and click Import MFC 4.21 Classes.

2.	The command creates a component in the component view and a logical package, called MFC 4.21, in the logical view. The created logical package contains all the classes of MFC 4.21, but no properties and methods.

Important: In order to generate proper code for classes, properties, and methods that reference MFC types, you must have the MFC classes imported into your model. The code generator needs the imported MFC classes to determine which header files to include in the generated classes. If the referenced MFC classes are not present in the model, the generated code may not compile.


Model to Visual C++ Mapping Overview

The notations provided by Visual Modeler are more abstract than the Visual C++ programming language. Some types of model elements do not correspond to any elements in Visual C++ at all, but many of them result in several lines of Visual C++ code when generated.

The specifications and model properties of the model elements are used to produce Visual C++ source code. For each model element there is a default mapping, but you can also control what code to generate by changing the model properties for the model element.

Click on an element type below to get an explanation of the meaning of it as well as the mapping to Visual C++ code:

Logical View

Classes

Interfaces

Class Utilities

Logical Packages

Properties

Methods

Relationships

Association Relationship

Aggregation Relationship

Generalization Relationship

Dependency Relationship

Component View

Components

Interfaces


Code Generated for Classes - VC++

In the UML notation, classes and logical packages are used to capture the logical model of a software system and components are used to capture the physical model. To generate Visual C++ code for a class, the class has to be assigned to one or more Visual C++ components. This assignment is captured on the Components tab in the class's specification.

A class that is assigned to a Visual C++ component in the model is by default generated as a Visual C++ class. The stereotype of the class controls the kind of project item to generate from the class. Thus, by changing the stereotype of the class, struct, union, and enum data types can also be generated.

For Visual C++ classes with the model property Generate set to False, the Visual C++ code generator does not generate any code.

The Header File

For each class, the Visual C++ code generator produces the following code constructs in the header file:

•	A Class Base List, taken from the class's name and generalization relationships

•	A Class Access Specification for public, protected, and private declarations that are generated for the class

•	Data Members, which are generated from the association relationships, aggregation relationships, and properties

•	Member function declarations for methods defined in the class specification

The Implementation File

For each class, the Visual C++ code generator produces the following code constructs in the implementation file:

•	Skeletal member function bodies for methods

 Example

See Also

Model Properties for Classes

Stereotypes of Classes

Modeling Visual C++ Classes


Example of Code Generated for a Class

The following example illustrates the code generated for an Order class.

Class Diagram:

Generated Header File:

class Orderrow;

class Customer;

class Order

{

public:

    bool register();

    float sum();

    bool add_orderrow(Orderrow new_row);

    Customer purchaser();

    int order_ID();

protected:

private:

    int orderID;

    Orderrow* theOrderrows;

    Customer* thePurchaser;

};

Generated Implementation File:

#include "Order.h"

#include "Orderrow.h"

#include "Customer.h"

...

bool Order::add_orderrow(Orderrow new_row)

{

    return (bool)0;

}

...


Class Base List - VC++

The class definition head may include a base list which contains one entry for each of the class's generalization relationships. Each entry in the base list may include additional keywords to indicate visibility and whether or not the inheritance is virtual. In a model, visibility and virtual inheritance are specified in the specification for the generalization relationship.

The example below is a class diagram and sample class definition for class Rectangle, which has a virtual inheritance relationship with class Shape.

Class Diagram:

Generated Code:

class Rectangle : virtual public Shape {

...

}


Class Access Specification - VC++

Within the class definition body, the Visual C++ code generator produces declarations for the class data members and member functions, grouped according to their access. The Visual C++ code generator produces the appropriate access keyword preceding each of four separate access levels:

{

public:

// Public members...

protected:

// Protected members...

private:

// Private members...

};

The UML notation has four levels of visibility, while Visual C++ has only three. Accordingly, the private implementation level is realized as a second private level. By default, all data members are generated in this part, regardless of the visibility specified in their corresponding association relationship, aggregation relationship, or property specification. While there is nothing to prevent a friend function from accessing private implementation members directly, the intent of private implementation access is to indicate that its data members and member functions should never be accessed directly outside the class, even by friends.

The access of each class member is determined by the value of the Export Control field in the member’s specification.


Interfaces and Visual C++

An interface specifies the externally-visible methods of a class and/or component, and has no implementation of its own. Thus, no code is generated from interfaces in the model, but they are used to represent the interface classes of software modules that are reverse engineered into the model.

Interfaces belong to the logical view, but they are displayed also on component diagrams to represent the interface of the components. In Visual Modeler, an interface is represented by a class with the stereotype Interface.

See Also

Components and Visual C++


Code Generated for Class Utilities - VC++

For a class utility, the Visual C++ code generator produces the same header and implementation code as for a class. However, since class utilities do not have instances, all methods, association relationships, aggregation relationships, and properties for a class utility are static.

The Header File

The Visual C++ code generator produces the following code constructs in the header file for the class utility:

•	The class definition, including the class name and base list

•	Declarations for static member functions from the methods listed in the class specification

•	Declarations for static data members

The Implementation File

The Visual C++ code generator produces the following code constructs in the implementation file:

•	Definitions for static data members

•	Skeletal definitions for static member functions

See Also

Code Generated for Classes


Logical Packages and Visual C++

Logical packages are used to logically partition the model, and have no direct mapping to Visual C++ code. Thus, no Visual C++ code is generated for logical packages.


Code Generated for Class Properties - VC++

By default, a class property is represented in code as a data member. The default code that is generated is a private implementation data member whose type and name is taken from the Property Specification in the model. By specifying additional information in the property name and type, pointers, arrays, and references can also be generated (see Pointers, Arrays, and References in Visual C++.)

A number of factors affect the actual code that is generated for a class property:

•	The type of the data member is affected by the type specified in the model.

•	The visibility adornment, determined by the Export Control field of the Property Specification, affect the access level of the data member.

Note: The initial value of the property, specified on the General tab of the specification, does not result in any Visual C++ code.

 Example

See Also

Pointers, Arrays, and References in Visual C++


Example of Code Generated for a Class Property

The following example illustrates the code generated for the properties of a Customer class.

Class Diagram:

Generated Code:

class Customer

{

public:

    int CustomerID;

protected:

private:

    CString Name;

    CString Address;

};


Pointers, Arrays, and References in VC++

Pointers, arrays, and references can be modeled by using association relationships or properties. The chosen approach depends on the type of the referenced item. Class properties are used for pointers, arrays, and references of built-in or low-level types, whereas association relationships are used for pointers, arrays, and references to user-defined classes.

Class Properties

The type of a modeled pointer, array, or reference is given by the type of the corresponding property in the model. For example, the properties of this class:

generates the following Visual C++ code:

int	a[20];	// an array of 20 ints

Crect*	pRect;	// a pointer to a CRect

Foo&	rfoo;	// a Foo reference

void**	ppvArr[MAX];	// an array of MAX pointers

// to pointer to void

Association Relationships

The name of a role specifies the type of the generated pointer, array, or reference. By default, Visual Modeler generates a pointer for each navigable role in the model, unless the role name specifies a reference (as in Example 2). Thus, it is not necessary to explicitly specify a pointer in the role name (see Example 1). If the role name explicitly specifies a pointer, an array, or a variation (pointer to pointer, array of pointers, etc.,) the information in the role name is used unchanged (see Example 3-4).

Example 1: Pointer

 and

both generate the following Visual C++ declaration in the Order class:

Customer	*theCustomer;

Example 2: Reference

generates the following Visual C++ declaration in the Order class:

Customer	&theCustomer;

Example 3: Array of pointers

generates the following Visual C++ declaration in the Order class:

Customer	*customers[25];

Example 4: Pointer to pointer

generates the following Visual C++ declaration in the Order class:

Customer	**ppCust;

See Also

Code Generated for Class Properties

Code Generated for Association Relationships

Modeling Pointers, Arrays, and References


Code Generated for User-Defined Methods - VC++

When generating code for a class, the Visual C++ code generator produces a skeletal member function for each method that is listed in the class specification. For each such method, the Visual C++ code generator produces a member function declaration in the header file for the class. The Visual C++ code generator uses the information in the method's specification, as well as the method model properties, to generate the member function.

For each user-defined method of a class, the Visual C++ code generator produces a declaration together with any comments in the header file and a member function head in the implementation file, as explained below:

      The Header File

•	Comments generated from fields in the method specification, such as Documentation.

•	The member function declaration, generated from fields in the method specification, such as Name, Arguments, and Return Class.

−	The declaration is generated under the appropriate access keyword, according to the value of the Export Control field of the method specification.

•	Additional keywords, such as virtual or const, may be generated for the member function declaration based on the value of the method’s stereotype, or the OperationKind and OperationIsConst model properties on the Visual C++ tab.

      The Implementation File

•	A member function head, generated from fields in the method specification, such as Name, Formal Parameters, and Result.

•	Additional keywords, such as virtual or const, may be generated for the member function declaration based on the value of the method’s stereotype, or the OperationKind and OperationIsConst model properties on the Visual C++ tab.

 Example

See Also

Model Properties for User-Defined Methods

Stereotypes of User-Defined Methods

Modeling Abstract, Virtual, or Const Methods


Example of Code Generated for A method

The following example illustrates the code generated for the “sum” method of a class called Order.

Class Diagram:

Generated Header File:

class Order

{

public:

    /*

     * Calculates the total sum of the order.

     */

    float sum();

...

};

Generated Implementation File:

...

float Order::sum()

{

    return (float)0;

}

...


Code Generated for Association Relationships - VC++

An association is a relationship among two or more classes. Code can be produced to efficiently traverse the relationship in one or both directions.

The ends of each association are called a role. Roles may be labeled with an identifier that describes the role that an associate class plays in the association. A role has properties that affect the generated code which traverses to that role. For example, marking a role navigable means that traversal from the opposite role's class to this role's class is to be implemented. Relative to a given direction of traversal, the roles may be designated as the client role and the supplier role, respectively. Of course, these designations are exchanged when considering traversal in the opposite direction.

By default, a new association relationship becomes navigable in both directions. To remove the navigability for one of the directions, point to that end of the association and press the right mouse button. Clear the Navigable option on the displayed menu.

An association relationship is represented in code as a data member in each client class whose corresponding supplier role is marked navigable. The data member is a pointer variable whose type is the supplier class. By specifying additional information in the role name, pointers, arrays, and references can also be generated (see Pointers, Arrays, and References in Visual C++.)

The name of a generated data member becomes the same as the corresponding role. If the role is unlabeled, the name becomes the same as the related class with the prefix “the…”.

The visibility adornment of a role, determined by the Export Control field on the Role’s General tab in the association specification, affects the access level of the generated data member.

 Example

See Also

Model Properties for Roles

Pointers, Arrays, and References in Visual C++


Example of Code Generated for an Association Relationship

The following example illustrates the code generated for an association relationship with a role called Purchaser. Note that the name of the generated data member is the same as the corresponding role.

Class Diagram:

Generated Code:

class Order

{

public:

    Customer* Purchaser;

...

};


Code Generated for Aggregation Relationships - VC++

The aggregate association adornment denotes a whole or part relationship. An aggregate relationship corresponds to an association relationship with the aggregation adornment set. Note, however, that aggregate adornments are purely conceptual and have no effect on code generation. It is the relationship’s navigability that determines whether to generate a data member or not. By default, a new aggregation relationship becomes navigable in one direction, and a data member for the associated class is generated into the aggregate class.

 Example

See Also

Model Properties for Roles


Example of Code Generated for an Aggregation Relationship

The following example illustrates the code generated for an aggregation relationship. Note that a data member is only generated for the navigable side of the relationship.

Class Diagram:

Generated Code:

class CustomerList

{

public:

    Customer* Customers;

...

};


Code Generated for Generalization Relationships - VC++

When the Visual C++ code generator produces a definition for a class (the client) that inherits from another class (the supplier), the name of the supplier class is inserted into the base list of the class definition head. The access of the generalization relationship, and whether or not the inheritance is virtual, are determined by information in the generalization relationship specification.

When generating code for the client class, the Visual C++ code generator also generates an #include directive referencing the file that contains the supplier class. The name of the header file to be included is defined by the HeaderFile model property of the supplier class.

 Example


Example of Code Generated for a Generalization Relationship

The example below is a class diagram and code generated for the class Rectangle, which has a virtual inheritance relationship with class Shape.

Class Diagram:

Generated Header File:

#include "Shape.h"

class Shape;

class Rectangle : virtual public Shape {

...

}


Code Generated for Dependency Relationships - VC++

When the Visual C++ code generator produces a definition for a class (the client) that depends on another class (the supplier), a forward class declaration for the supplier class is inserted into the header file.

Also, an #include directive referencing the file that contains the supplier class is generated into the body file of the client class. The name of the header file to be included is defined by the HeaderFile model property of the supplier class.


Components and Visual C++

Components in the model are used to represent the software modules that together realize the modeled system. The implementation language of a component is defined by the Language field in its specification, and the type of a component, which is specified by its stereotype, indicates the type of the corresponding software module.

A Visual C++ component in the model represents a build unit in the target environment and thus corresponds directly to a Visual C++ project. Note that creating a component in Visual Modeler does not automatically create a Visual C++ project. The project has to be created manually and when generating code for the component you will have to associate the component with its project.

Components are also used to represent any external software modules that the modeled system uses. Any software module that has a Type Library in it can be dragged from the Microsoft Explorer or Microsoft Visual Component Manager and dropped in Visual Modeler. A component representing the external software module is then created in the model, and the interface of the component becomes one or several interface elements in the model. Then you can show how classes and components depend on the interface of other components by establishing any relationship between classes and interfaces, and dependency relationships between components and interfaces.

See Also

Stereotypes of Components


Visual C++ Model Properties Overview

The information contained in a model element's specification and model properties controls all aspects of code generation for that model element. The following Visual C++ model property groups exist:

Class Properties

Method Properties

Note: Not all model elements for which code is generated require model properties. For example, there are no model properties for generalization relationships. Also, for model elements without a code mapping, such as packages, there are no model properties.


Model Properties for Components - VC++

There are currently no Visual C++ model properties for components.


Model Properties for Logical Packages - VC++

There are currently no model properties for logical packages because no code is generated for them.


Model Properties for Classes - VC++

Model properties for classes control the Visual C++ code produced for each class. Use the following model properties to specify additional details when generating the class:

Generate

HeaderFile

To learn more about a model property and its values, click on its name.

The model properties for a class are available on the Visual C++ tab of the Class Specification.

See Also

Code Generated for Classes


Model Properties for Roles - VC++

There are currently no Visual C++ model properties for roles.


Model Properties for User-Defined Methods

When generating code for a class, a skeletal method declaration is produced for each user-defined method that is defined in the class specification. Use the following model properties to specify additional details when generating the member functions:

OperationIsConst

OperationKind

To learn more about a model property and its values, click on its name.

The model properties for a method are available on the Visual C++ tab of the Method Specification.

See Also

Code Generated for User-Defined Methods


Model Properties for Generalization Relationship - VC++

There are currently no Visual C++ model properties for generalization relationships.


OperationKind (Method Property) - VC++

The OperationKind property specifies the kind of member function that is generated for a user-defined method. The Visual C++ code generator produces additional keywords in the declaration of the member function based on the value of the OperationKind property.

The following table summarizes the possible values for the OperationKind property. In this table, result is the return type of the member function, fname is the name of the member function, and params is the formal parameter list:

If you select:	The Visual C++ code generator produces:

Non-virtual 	(Default) result fname (params);

Virtual	virtual result fname (params);

Abstract	virtual result fname (params) = 0;

Select Abstract to generate a pure virtual function for which the Visual C++ code generator produces a member function declaration, but no function definition.

Note: The operation kind can also be specified by giving a method the corresponding stereotype. In case of a conflict, the Visual C++ code generator uses the value of the stereotype. For example, for a method with the stereotype Abstract and OperationKind=Non-virtual, the Visual C++ code generator produces an abstract member function.

See Also

Stereotypes of Methods


OperationIsConst (Method Property) - VC++

The OperationIsConst property specifies whether or not the Visual C++ code generator produces the member function for a user-defined method with the const keyword. Const member functions cannot modify class data members.

The following table summarizes the possible values for the OperationIsConst property. In this table, result is the return type of the member function, fname is the name of the member function, and params is the formal parameter list:

If you select:	The Visual C++ code generator produces:

True	result fname (params) const;

False 	(Default) result fname (params);

Note: Generation of const member functions can also be specified by giving a method the stereotype Const. In case of a conflict, the Visual C++ code generator uses the value of the stereotype. For example, for a method with the stereotype Const and OperationIsConst=False, the Visual C++ code generator produces a const member function.

See Also

Stereotypes of Methods


Generate (Class Property) - VC++

The Generate property specifies whether or not the Visual C++ code generator will generate any code for the class specification.

This property allows you to prevent code from ever being generated for a class, even if it is selected when the Visual C++ code generator is invoked.

If you enter:	The action is:

True	(Default) The Visual C++ code generator generates code for the class.

False	The Visual C++ code generator will not generate any code for the class.


HeaderFile (Class Property) - VC++

The HeaderFile property specifies the name of the header file of the class. The Visual C++ code generator uses the value of this property when generating #include directives for this class into other classes.

If you enter:	The action is:

AUTO GENERATE	(Default) The Visual C++ code generator generates an #include "name_of_class.h" directive for this class. For example, if class Rectangle inherits from class Shape, and HeaderFile =  AUTO GENERATE for Shape, the following include directive is generated into Rectangle:

#include "Shape.h"

file_name.h	The Visual C++ code generator generates an #include "file_name.h" directive for this class. In the above example, if HeaderFile = c:/project/common/Shape.h for class Shape, the following include directive is generated into Rectangle:

#include "c:/project/common/Shape.h"

<file_name.h>	The Visual C++ code generator generates an #include <file_name.h> directive for this class. In the above example, if HeaderFile = <Shape.h> for class Shape, the following include directive is generated into Rectangle:

#include <Shape.h>


Code Generation Overview - VC++

Using the Visual C++ code generator, you can produce Visual C++ source code from the information contained in a model. Code is generated from the selected classes, or from all classes that are assigned to a selected component, into the selected Visual C++ project.

The code generated for each model element is determined by that element’s specification and model properties. For each class, Visual Modeler produces a corresponding Visual C++ class, union, struct, or enum data type depending on the stereotype of the class. Each relationship and property of the classes is translated into a corresponding code declaration depending on the required implementation strategy. For all user-defined methods, the code generator produces skeletal method declarations and inserts the documentation of the method in the generated header file as a code comment.

Note: When generating Visual C++ code, Visual Modeler creates new header and body files for all selected classes. If the header or body file of a generated class already exists in the target project, Visual Modeler renames the existing files before creating any new files. Header files will be renamed with the “.~h” suffix and body files will be renamed with the “.~cp” suffix.

See Also

Generating a New Visual C++ Project from a Model

Updating a Visual C++ Project from Changes in a Model

Visual C++ Model Properties Overview

Model to Visual C++ Mapping


Visual C++ Model Properties

The notations supported by Visual Modeler are more abstract than the Visual C++ programming language. Model properties enable you to provide language-specific information that is not expressed in the UML notation, but that is necessary for generating Visual C++ code.

When a model element is created, Visual Modeler assigns each model property a default value, which you can optionally modify. By modifying the model properties, you can control the kinds of Visual C++ code constructs that are generated for the model element. The model properties of a model element are available on the Visual C++ tab of its specification.

See Also

Visual C++ Model Properties Overview

For general information about model properties, please refer to the Index or Contents tab of the on-line help.


Fundamental Data Type - VC++

Fundamental types and standard objects built into the Visual C++ environment (byte, char, and int, etc.) are automatically included when a new model is created.


Visual C++ Project

A Visual C++ project is a specially formatted file (.dsp) that identifies the folders and files containing your application's source code.

Code generation is performed between the classes that are assigned to a selected component and the header and implementation files in the selected Visual C++ project.


Project Item - VC++

A project item is an item that occurs in a Visual C++ project, such as a class, struct data type, union data type, or enum data type.


Import MFC 4.21 Classes (Visual C++:Tools Menu)

Use this command to import the classes in the MFC 4.21 type library into the model. The command creates a logical package, called MFC 4.21, containing the classes that are found in MFC 4.21. The command also creates a component, with the same name as the logical package, in the component view.

Use the imported classes to show how the classes of your model depend on the classes in MFC 4.21.


Visual C++ Stereotypes Overview

The following model elements have Visual C++ specific stereotypes:

Class Stereotypes

Method Stereotypes

Component Stereotypes


Stereotypes of Classes - VC++

The stereotype of a class controls the Visual C++ code produced for the class. You define the stereotype on the General tab in the Class Specification.

The following stereotypes of classes are used when generating Visual C++ code:

Stereotype:	The Visual C++ code generator produces:

“Enum”	An enum data type

“Struct”	A struct data type

“Union”	A union data type

“Interface”	No code for interfaces

Any other value	A class

See Also

Code Generated for Classes

Modeling Visual C++ Classes


Stereotypes of Methods - VC++

The stereotype of a method controls the Visual C++ code produced for the method. You define the stereotype on the General tab in the Method Specification.

The following stereotypes of methods are used when generating Visual C++ code. In this table, result is the return type of the member function, fname is the name of the member function, and params is the formal parameter list.

Stereotype:	The Visual C++ code generator produces:

“Abstract”	virtual result fname (params) = 0;

Select Abstract to generate a pure virtual function for which the Visual C++ code generator produces a member function declaration, but no function definition.

“Virtual”	virtual result fname (params);

“Const”	result fname (params) const;

“Const, Abstract” 	virtual result fname (params) const = 0;

“Const, Virtual” 	virtual result fname (params) const;

Any other value	If the stereotype is undefined, the Visual C++ generator produces code based on the value of the OperationKind and OperationIsConst model properties.

As shown in the table, you can generate a const virtual function or const abstract function by specifying a combination of the corresponding stereotypes. The order between the two stereotypes is not significant. Also, instead of a comma, you can use a space or a semi-colon as the stereotype delimiter. For example, “Abstract, Const” and “Const Abstract” are equivalent.

Note: The code to be generated for a method can also be specified by the OperationKind and OperationIsConst model properties. In case of a conflict, the Visual C++ code generator uses the value of the stereotype.

See Also

Code Generated for Methods

Modeling Abstract, Virtual, or Const Methods


Stereotypes of Components - VC++

The stereotype of a component indicates to what type of Visual C++ project the component corresponds. You define the stereotype on the General tab in the Component Specification

The following Visual C++ component stereotypes are available by default:

Stereotype:	Meaning:

“DLL”	Represents a Visual C++ project of the type Win32 Dynamic-Link Library.

“EXE”	Represents a Visual C++ project of the type Win32 Application.

Note: The stereotype of a Visual C++ component is only used for documentation purposes. Thus, when generating Visual C++ code for a component, Visual Modeler generates the code into the selected project, which may be of a different type than the component’s stereotype.

See Also

Components and Visual C++

Creating a VC++ Component