Chapter 5. Getting Started with the C++ Browser

This chapter is designed to get you up and running with the C++ Browser. It tells you what you need to run the Browser, shows you how to start it, and presents a brief overview of its main windows and menus. It also provides a brief explanation of pertinent concepts concerning C++ class structure. If you are already familiar with C++ and the basic components of the C++ Browser, and want to perform a specific task, see Chapter 6, “Using the C++ Browser: A Sample Session.” If you need specific reference information on any part of the Browser's user interface, see Chapter 7, “C++ Browser Reference.”

The chapter contains the following sections:

Starting the C++ Browser

The C++ Browser is integrated with, and must be launched from, the WorkShop Static Analyzer, cvstatic. The Static Analyzer creates a fileset, or list of source files, it then uses to build a static analysis database used by both the Static Analyzer and the C++ Browser. The Browser accesses this database when it displays C++ class, member, and method information.

Thus, to use the Browser to view your C++ classes, you must perform these tasks:

  1. Start the Static Analyzer.

  2. Create a fileset that contains the files defining the C++ classes you wish to examine.

  3. Build a static analysis database from the fileset.

  4. Launch the C++ Browser from the Static Analyzer.

The following sections describe the previous steps in detail.

Starting the Static Analyzer

To start the Static Analyzer, perform these steps in your shell window:

  1. Move to the directory containing your source files or your database (unless your fileset has path information to the source directory).

    cd source_directory
    

  2. Start the Static Analyzer. If you want to build a database, enter:

    cvstatic &
    

    If you have already built a database, enter:

    cvstatic -readonly & 
    

Creating a Fileset

When you start the Static Analyzer, it creates a default fileset that includes all C, C++, and Fortran files in the directory from which you started it. You need to create a custom fileset. The Static Analyzer builds the database from your fileset.

If a fileset exists, select “Change Fileset” from the Admin menu and select files from the Fileset Selection Browser window that appears.

To create a new fileset, perform these steps:

  1. From the Static Analyzer's Admin menu, select “Edit Fileset.”

  2. In the Fileset Editor window, first ensure that the Directories field shows the location of your source files. If your source files are in a different directory, click the Move Directory Parser button.

  3. Click the C++ toggle under the list of files, to restrict the files shown.

  4. Click the Move Files Parser button to move the list of files into the Parser Fileset list box. Files in this box are parsed, and the information goes to the static analysis database when you scan.

    If you are not satisfied with the files in the Parser Fileset list box, remove them all. Select all the lines and then click the Remove button. Continue moving directories and files to create the parser fileset.

  5. When you are satisfied with the files in the Parser Fileset field, click OK.

For detailed information on how to create a custom fileset, as well as general information on filesets and their use, see Chapter 4, “Creating a Fileset and Generating a Database,” in the CASEVision/WorkShop User's Guide.

Creating a Static Analysis Database

If you are recreating the database, rescan using one of the following methods. If you've just modified source code and want to update, select “Rescan” from the Admin menu. To completely rebuild the cross-reference database, select “Force Scan” from the Admin menu.

To build a new database, select “Force Scan” from the Admin menu.

Launching the C++ Browser from the Static Analyzer

To launch the Browser from the Static Analyzer, choose the “C++ Browser” command from the Static Analyzer's Admin menu. The Class View window of the C++ Browser appears, along with the chooser window, List of Classes (see Figure 5-1). The Class View window and other major components of the Browser interface are described in the next section, “Understanding C++ Browser Concepts and Components.”

Figure 5-1. Static Analyzer Launches C++ Browser


Understanding C++ Browser Concepts and Components

You can use the Browser to view the C++ classes used in any application or library. Specifically, you view classes present in the sources included in the fileset. The Browser's Class View window (described on page 74) shows the internal structure of a class and its relationships with other classes in a textual, outline format. The Class Graph window displays the same information as a graphical view of the class structure, providing more of a global perspective of the overall class structure. Thus, you can simultaneously examine the overall class structure, as well as the details of an individual class (its methods, members, friends, and so on).

This section describes the basic user interface design of the C++ Browser. It also introduces the concept of queries, the means by which the Browser and the Static Analyzer let you narrow your search for specific information.

C++ Class Structure and the Current Class

The C++ Browser displays three main types of information:

  • the members of a class (current class) that you select from the set of classes found in the given fileset.

  • the classes in the given fileset related to the current class and, conversely, the interclass relationships between the current class and other classes, and global relationships between all the classes found in the given fileset

  • the calling structure of member functions (methods) belonging to selected classes

This section provides a brief overview and explanation of the different terms the Browser uses to refer to the members, classes, and interclass relationships it displays.

Members

The C++ Browser displays four kinds of class members:

  • types define data types declared by a class.

  • data members are variables that contain state information for a class.

  • methods, or member functions, define how a class interacts with other classes and structures.

  • virtual methods define how an instantiated object interacts in conditions when parent and child classes have identically named methods that perform different functions. Using virtual methods for an object ensures that the method invoked is defined by the class from which the object was instantiated, regardless of type casting.

Each of these four kinds of members come in two types:

  • static members, meaning that all objects of a given class contain the same value for a given member, and when that value is changed, it changes for all instances of that class

  • instance (non-static) members, meaning that the value of the given member can be different for each instance of that class

Finally, each of these kinds of members can fall into one of three categories, based on their accessibility:

  • public members can be accessed by any method or C-style function

  • protected members can be accessed only by methods in derived classes, friend classes, or friend functions (see the next section, “Related Classes and Functions”).

  • private members can be accessed only by methods in the class in which they are defined, friend classes, or friend functions.

The C++ Browser displays class members in a hierarchical, expandable outline format based on the categories described above. The layout of the member list display is customizable (see “Customizing the C++ Browser”), and the default display is described in “The Class View Window” and in detail in Chapter 7, “C++ Browser Reference.”

Related Classes and Functions

The C++ Browser displays this information about class structure from the point of view of a chosen current class:

  • base classes, meaning the current class and its ancestors

  • derived classes, meaning subclasses of the current class

  • classes whose members the current class uses or classes that are components of the current class

  • classes that members of the current class are used by or classes of which the current class is a component

  • friend classes and friend functions of the current class

Like the member information, the Browser displays related class information in a hierarchical, expandable outline format based on the categories described previously.

The layout of the related class list display is also customizable (see “Customizing the C++ Browser”), and the default display is described below in “The Class View Window” and in detail in Chapter 7, “C++ Browser Reference.”

Interclass Relationships

There are four main types of interclass relationships displayed by the C++ Browser:

  • inheritance, which describes the relationship of parent classes to derived classes

  • containment, which describes the relationship of container classes to the classes they contain

  • interaction, which describes the relationship of classes using methods of other classes.

  • friends, which describes the relationship of classes declaring other classes as friends.

The Browser displays this information in a graphical tree format as shown in Figure 5-2. For more information on the details of the user interface, see “The Class Graph Window” and Chapter 7, “C++ Browser Reference.”

Figure 5-2. Interclass Relationships


Main C++ Browser Windows

The C++ Browser uses three main windows (also called views) to display different sets of information about classes, class members, and interclass relationships.

  • The Class View window contains member and class information, organized in an expandable, hierarchical outline format. The Class View window allows you to make queries on listed members and classes, and lets you invoke the other main Browser windows from pop-up menus and the menu bar.

  • The Class Graph window contains a graphical display of the current class (as displayed in the Class View window) and related classes found in the static analysis database.

  • The Call Graph window contains a graphical display of the calling relationships of methods and virtual methods selected from the Class View window.

Some of the features of these windows are described below.

The Class View Window

Class View is the primary C++ Browser window. It opens when you launch the Browser from the Static Analyzer's Admin menu. Figure 5-3 shows an example of the Class View window.

You can use the Class View window to:

  • view lists of members defined in the current class and classes associated with the current class in an expandable side-by-side display

  • issue queries about a selected member or class to examine details of its structure and how other members or classes relate to it

  • open Class Graph and Call Graph windows to further explore class and method relationships

  • display detailed results of your queries in the Static Analyzer, or use the annotated scroll bar to find the results of your queries quickly within the Class View member and related class lists

  • view source files containing class and member definitions

  • generate reference pages

Directly below the menu bar is the Current Class field, an editable text field (with name completion) that contains the name of the current viewpoint class. Below this, the Class View window presents two lists containing information about the currently selected class:

  • The member list (on the left) gives you a detailed view of the members of the current class.

  • The related class list (on the right) shows the relative position of the current class in your application's or library's class hierarchy.

    Figure 5-3. The Class View Window


By default, the Browser sorts the members and classes under keyword headings, discussed previously in “C++ Class Structure and the Current Class”. Ways of altering the sorting scheme are discussed in “Customizing the C++ Browser”.

The Class View window features annotated scroll bars in its member and related class lists. When you issue a query, the scroll bar contains marks (“annotations”) that indicate the relative location of members or classes identified by the query within each list. For more information on issuing queries, and on using the Class View window in general, see Chapter 6, “Using the C++ Browser: A Sample Session.”

The Class Graph Window

The Class Graph window provides a graphical view of class structure (see Figure 5-4). You can choose to display a directed graph of any of four interclass relationships, and can switch between these graphs at will, or display multiple graph windows, each displaying a different relationship. You can choose to view relationships among all the classes in the static analysis database, or just those that directly involve the class. Double-clicking on a class node in the Class Graph selects the class as the new current class in the Class View window.

Buttons located at the bottom of the Class Graph window allow you to adjust the view of the class structure. You can

  • enlarge or shrink the class nodes to fit them into the same-size window

  • invoke a graph overview window that serves as a navigational aid by providing a miniature, schematic view of the entire graph you're exploring

  • toggle a display of multiple connections between two nodes

  • align nodes to clarify the display

  • turn the direction of the tree graph by 90 degrees so that the tree graph grows downwards instead of to the right

  • choose which one of the four interclass relationships so displayed at any given time

The Class Graph View menu gives you different options for setting the scope of the graph. You can

  • show the global relationships of the entire set of classes found in the current fileset

  • simplify a complicated graph by showing only related (recursively derived) classes of the current class

  • show a butterfly view of the current class, showing only the immediate base and derived classes of the selected class

Figure 5-4 shows an example of the Class Graph window.

Figure 5-4. The Class Graph Window


The Call Graph Window

The Call Graph window allows you to graphically view the calling structure of class methods and virtual methods. Methods selected from the Class View window can be added or deleted from the Call Graph window. Double-clicking on a method node in the Call Graph window opens a view of the source code defining the method.

Buttons located at the bottom of the Call Graph window adjust the view of the class structure. You can

  • enlarge or shrink the class nodes to fit them into the same-size window

  • invoke a graph overview window that serves as a navigational aid by providing a miniature, schematic view of the entire graph you're exploring

  • toggle a display of multiple connections between two nodes

  • align nodes to create a more clear graph

  • turn the direction of the tree graph by 90 degrees so that the tree graph grows downwards instead of to the right

Figure 5-5 shows an example of the Call Graph window.

Figure 5-5. The Call Graph Window