Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Code Generators


January 1997: Code Generators

Have C++ code generators seen their day in the sun pass? The two tools in this review offer some unique advantages-and disadvantages.

If you're a C++ programmer who seems to be creating the same program over and over again, particularly if your applications involve common database operations, you may be a good candidate for using code generation programs. In this review, we take a look at two C++ code generators, ProtoView's ProtoGen+ Client/Server Suite 5.1 and TechTools' DataBoss 2.0.1.

The case for code generation tools was stronger in the days before Visual Basic and Delphi. Back then, all applications were either written in third-generation programming languages (Pascal, C, COBOL) or with fourth-generation language tools such as dBASE. Developers opting to program in third-generation languages were willing to sacrifice coding speed to gain a fast, small, monolithic executable that could not be reverse-engineered and was easily distributed to customers. Those who chose fourth-generation language tools were willing to sacrifice speed and security to take advantage of an environment that facilitated rapid prototyping-not an inconsiderable benefit when dealing with customers whose needs change on a daily basis.

The arrival of new tools such as Delphi, and to a lesser extent, Visual Basic, created a third family of tools that offer the speed, size, and security of a third-generation language and the benefits of a fourth generation language. Does this mean C++ code generators have seen their day in the sun pass? Perhaps. As we'll see, the two tools in this review offer some unique advantages-and disadvantages.

ProtoGen+ Client/Server Suite

ProtoGen+ Client/Server Suite is Protoview's top-of-the-line offering. It includes the core ProtoGen+ Workbench as well as ODBC drivers and tools for generating graphs from data. ProtoGen+ Workbench includes three major components: a menu design tool, a screen painter, and data entry field controls.

The first decision you have to make when using ProtoGen+ Workbench is whether you're creating an executable or a DLL, as it will generate either. You also must decide which C or C++ compiler to use; ProtoView supports Microsoft, Borland, and Symantec compilers. The primary implication of this choice is whether your application will be generated using Microsoft Foundation Class (MFC) or Borland Object Window Library (OWL) class libraries. You can also specify whether you'll construct your application using the Windows multiple document interface model and if you'll be using version control software.

After specifying a project, one of the first tasks customarily involves creating a menu structure for your application. When you create a new project, you're presented with two similar menus. The upper menu belongs to the ProtoGen+ workbench itself; the lower menu is the first menu for the application you're generating. By clicking on the Edit Menu button, you can specify the structure of your menu and define the hot keys and the symbol that will represent each menu item in the Windows resource file. You can also specify whether the menu item is initially active, checked, grayed, and so on. You can, of course, dynamically change menu attributes during the course of program execution.

In addition to specifying the application's textual menu items such as File, Edit, and Help, you can also modify its toolbar. The toolbar is created with equally familiar buttons: create a new file, open an existing file, save the file, cut, paste, print, and so on. The tools provided for modifying it are the same ones you use to add elements to window dialogs. Thus, they are somewhat awkward to use within the toolbar's narrow confines. However, once you finish struggling with sizing a new button and placing it in roughly the correct location, you can use tools located on the workbench's floating alignment toolbar to align it in various ways with existing buttons. It would have been more convenient if ProtoView had provided a preconfigured library of existing buttons to drag and drop onto the toolbar.

You can assign help text to both menu selections and toolbar buttons. For each, you can specify that the help text is to be displayed in the window's bottom border. You can also provide the user with tips for toolbar buttons; these tips appear as cartoon-like captions when you drag your mouse over a tool button and let it linger for a second or two.

After you've finished creating a menu, you can test it dynamically from within the workbench. A large application can take several minutes if you submit it for compilation, after which you have to find the executable and invoke it. Having a simulation available within the workbench saves time. When you click on the "test" button, the workbench window disappears and is replaced by one containing the menu and toolbar items you've specified.

To create dialog boxes and data entry windows you use the screen painter, which ProtoView calls ViewPaint. ViewPaint consists of a blank window and the two palettes also used for editing toolbars: a palette from which you select the objects you want to place on the blank window (the tools palette), and the alignment palette. The tools palette resembles the controls palette found in Visual Basic, Delphi, and other visual programming tools. With it you select the control-list box, radio buttons, text element, and so on-and place it on the window under construction.

To get you started when constructing new dialogs, ProtoGen+ offers a number of predefined templates, such as a name and address template, to use as the basis for customization. The value of predefined templates becomes more apparent when you want to define a common look for all of your screens. You can also create a custom template and have it appear in the list of available templates.

If you right-click on any screen element that you've defined, you are presented with a floating list of actions that define the properties of that element. Possible actions include link functionality, data elements, edit button code, edit button methods, and SQL data automation. These actions are what separates ProtoView from a simple interface generator.

The link functionality option lets you tie a button or menu item to another dialog or to an external executable program. Data elements are variables provided for you to store user input. The ProtoView+ Workbench creates a C structure where all the data elements for a screen you have defined are stored. You can reference this structure, or individual elements of it, in your own custom code. You won't need custom code for simple editing, however. You can associate each field with a variety of macros to control input masks, help messages, allowable input strings or characters, and the like.

One of the strengths of ProtoGen+ lies in its support for user-customized code. For example, when you edit button code, you see the C or C++ code that ProtoGen+ has generated for you. For ordinary applications, this default code may be all that is required. However, should you decide that custom coding is required, ProtoView has provided a way to insert it. Consider this sample code, generated as part of a case statement that specifies the behavior associated with an OK button:

    case IDOK :
    
            //Regen_IDOK
    
            //Regen_IDOK
    
            break; 

All of the C or C++ code required to compile an executable is generated as the screen is created. Thus, each action associated with the screen has a corresponding snippet of code; the case statement shown previously is the code associated with an OK button from an About window. If you wish to count the number of times a user accesses the About screen during the course of a program's execution, you can insert a line (such as counter++; between the bracketing pairs of //Regen_IDOK comments. By providing these placeholders for custom code, ProtoView makes it easier for you to identify where the ProtoGen+ code ends and yours begins. Because the code is generated and saved with the project on-the-fly, as the screen is created, there's no danger of losing the custom source code (as would happen if you had to modify the source code after it was generated).

If you link some behavior, such as an external program, to a button or other control on the screen, ProtoGen+ will insert a pair of comments before the link, as shown previously, and another pair of comments following the code invoking the link. These two pairs of bracketing comments provide you with places to insert code so you can specify the behavior that is to occur both before and after the link.

If you wish to define custom code that will be used in several places in your application, rather than coding it repeatedly in each place it's required, you can assign a method to the control. This forces the generated and compiled code to go to one of two DLLs that are loaded into memory along with the application. Although Protoview provides many common routines in these two DLLs, you can modify them to add methods specific to your application.

ProtoGen+ Client/Server Suite adds version control, integrated ODBC driver access, Crystal Reports, and graphing to the basic ProtoGen+ Workbench. The version control interface only supports Intersolv's PVCS, but ProtoView promises that future releases will support other version control products. As with other products that offer PVCS integration, the interface between ProtoGen+ and PVCS consists of calls to get and put the current files to the PVCS repository, instead of to independent disk files. You can also add comments to each revision and display revision history information.

The ODBC driver support and associated functionality represent the core of the Client/Server Suite database enhancements. The primary component, SQL View, provides a tool slightly reminiscent of the PowerBuilder DataWindow. In SQL View, you create a map that binds SQL fields to the fields displayed on your form. ProtoView handles one-to-many links with a scrolling list from which you select the specific record you wish to work with. In addition to populating a form table with them, you can bind any button to an SQL View command. For example, you could display a customer's order, and from a button on the order screen bind another screen that would display information about the customer.

SQL View supports a wide variety of other functions you can use to enhance your application. For example, you can define the behavior that results when the user double-clicks on a field in a spreadsheet data control that you had previously filled with data retrieved from your SQL tables. This lets you display detailed information when the user requires it, but otherwise keeps the form uncluttered.

The Crystal Reports provided for reporting purposes is the same product several other vendors use; it has become something of a standard. Because of its familiarity we won't explore it further.

The graphics server provides you with the ability to define graphs. It lets you take data-either static or retrieved from a database-and display it in graphs of various forms, much like you would do with a spreadsheet.

ProtoGen+ is an impressive product, but not without flaws. First, it's unfortunate that it cannot generate code for other platforms, since internally it already works at the source code level. It should not be difficult, for example, to add the ability to generate Motif-based applications. Without such cross-platform support, the developer has little incentive to use it instead of a dedicated Windows tool that generates code internally, such as Delphi. The other flaw-if I can call it that-is that the documentation lacks a good index, and the glossary supplied only references the Workbench tools and not the Client/Server Suite tools.

DataBoss 2.0.1

I cannot say as much about DataBoss for Windows. I worked with an earlier DOS version several years ago, and at that time DataBoss filled a real need in the marketplace. Developers were limited to either hand-coding C or Pascal programs or using bloated database products such as dBASE. DataBoss provided a nice compromise between those two camps.

Today, however, a tool that generates C++ code for accessing dBASE-format files is not exactly state-of-the-art. DataBoss does offer some nice features, as we'll see, but it's difficult to see their value when you're questioning the basic reason for having such a program.

The simplest way to introduce you to DataBoss is to show you how it compares to ProtoGen+. While the documentation for ProtoGen+ is written with experienced programmers in mind, the documentation for DataBoss appears to have been written more for computer-literate users. The product's simplicity and organization reflect that orientation as well. You begin by defining a single-table database or by importing the fields from an existing table. Although you can use other files as validation tables and establish a parent-child relationship between two files, DataBoss doesn't let you join tables for queries. Presumably you would be able to externally join tables and then make them available to DataBoss, but you cannot do that on-the-fly. ProtoGen+, because it uses ODBC and SQL, is able to perform more sophisticated data manipulation tasks.

Menu creation in DataBoss follows a similar process to that used in ProtoGen+. Menu items can be associated with data entry screens that you've defined, but they can't be associated with external programs. You define screens in DataBoss by placing controls on a grid, but the selection of controls is greatly simplified compared to that available in ProtoGen+, or in Visual Basic and Delphi. The emphasis is more on making predefined functionality available than on providing maximum flexibility. For example, you can use OK and Cancel buttons directly, without assigning text to them or defining their behavior.

To locate a set of records from which you can find the specific record you want to work with, DataBoss provides a query function that lets you substitute a temporary index for the permanent index. You specify the field you want the query ordered by and the condition you want met. For example, in an employee payroll file you could tell DataBoss to order the file by last name and then specify a condition in which the salary is greater than $100,000.

Unlike ProtoGen+, which relies on a third-party reporting product, DataBoss incorporates a simple report generator. The DataBoss report generator lets you define headers and footers-which can be triggered by a change in data so you can start a new page as required-but does not offer any subtotaling and totaling. You can, however, define a filter window where the user can specify a filter to limit the records displayed in the report.

You can customize DataBoss by writing one-line C++ functions that are called for common operations such as validation or returning errors. For more complex functions, you must write them in a separate .CPP file that is compiled and linked as part of the application.

DataBoss appears to have been designed to generate applications that will be used as one component in a typical user's working environment. Thus, an import and export facility is provided, although the file formats available are limited to ASCII (both delimited and fixed-position) and dBASE files. In addition, the instructions detail how to generate files that can be used as mail merge files for various Windows word processors. This functionality relies more on the word processors' ability to use dBASE files than in the ability of DataBoss to export mail merge files.

One convenient feature of DataBoss is its support for remote and mobile computing. The examples provided assume that file updates are transmitted to and from laptops in the field using messaging systems such as Motorola's EMBARC system. However, the file format lends itself to use with many other transmission systems, such as modems, LANs, and even sneaker net (floppy disks). The relevant DataBoss functionality focuses on creating a log of updates to the master system. This log can then be transmitted to the remote systems and used to update the remote databases to correspond with the changes in the master database.

ProtoGen+ and DataBoss are obviously targeted at different market segments. The question is whether either product meets a real need in a changed Windows programming environment. If you're firmly committed to C or C++ programming, and insist on seeing all the code that is used to generate your executables, then perhaps these products will offer you advantages. If you're simply looking for another way to generate applications, the cost of these code generators, added to the cost of a C++ compiler, will probably exceed that of a dedicated rapid development product such as Visual Basic or Delphi. In addition, when you use a code generator, you not only have to worry about whether it and the compiler are working correctly, you have to make sure that they are interfacing correctly.

If these products offered a unique advantage to developers-such as cross-platform support-there would be much more justification for using them. So far, I haven't found a compelling reason to switch to this hybrid method of application generation.

ProtoGen+ Client/Server Suite 5.1

RATING: * * *

Pros and Cons

PROS:

  1. You have immediate, direct, and interactive access to generated C++ code.

  2. Test capability for menus, screens, and dialogs save you from having to compile after every change.

  3. The product has strong database access and display tools.

CONS:

  1. The index and glossary are poor; some capabilities are inadequately explained.

  2. There is a lack of cross-platform support.

  3. Toolbar development is awkward.

Company Information

ProtoGen+ Client/Server Suite 5.1

ProtoView Development Corp.

2540 Rte. 130

Cranbury, N.J. 08512

Tel: (609) 655-5000

Fax: (609) 655-5353

CompuServe: GO PROTOVIEW


Price: $1,999

Software Requirements: Windows 3.1, Windows 95, or Windows NT

Hardware Requirements: 100MB hard drive space, 8MB RAM, 486 or better

Technical Support: Free lifetime support via fax, BBS, e-mail, and CompuServe; free telephone support for 30 days after first phone call; paid telephone support available after initial 30 days

Money-Back Policy: Only within the first 30 days

DataBoss 2.0.1

RATING: * * ½

Pros and Cons

PROS:

  1. This is a simple, easy product for users.

  2. The existing DOS product has been upgraded to Windows.

  3. It supports remote updates of database subsets.

CONS:

  1. You can't join two or more tables in an application.

  2. The query requires you to know the table structure.

  3. This product is too simplistic for professional application developers.

Company Information

DataBoss 2.0.1

TechTools Inc.


Price:$249

Software Requirements:Windows 3.1 or Windows 95

Hardware Requirements: 6MB hard drive space, 4MB RAM, 386 DX or higher

Technical Support: Free lifetime via fax, e-mail, BBS, web page; no telephone support

Money-Back Policy: Within first 60 days


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.