Introduction:

In the preceding sections, we have introduced most of the details of our classes. Now it is time to put them together into a program that does something useful. Some examples of interesting IFC applications include:

Utility main;

In this section, we'll introduce you to the preprocessor, command line processing, and template object declarations.

For more information on main programs, see Lippman and Lajoie, Chapter 1.

Include Files:

At the top of the file containing any main program, you will see code similar to the following: These include statements are similar to the conditionals previously discussed in Section 1. Before the compiler creates binaries from your code, a program called the preprocessor looks over your files and expands these include statements into the full code of the files you name between the angle brackets. Those files are header files, and contain the declarations of all the classes you will use in your main program. If you forget to include your header files, you'll get many compiler errors about things that haven't been declared.

For more information on including header files, see Lippman and Lajoie, Section 1.3.

Command Line Arguments:

One of the more tedious tasks in C++ is processing command line arguments. Although code for this is fairly simple, it is important that all programs have the same user interface, and that this be implemented without replicating command line parsing code in each main program. For example, all utilities use an option of -help to display a help message, and -debug FULL to run the program in a pseudo-debug mode. The Shell library provides some tools to facilitate command line parsing and other related tasks. The CommandLine class provides the necessary tools to process command line arguments in a standard way.

Using CommandLine is straightforward. First, you instantiate CommandLine like any other class. Then you pass the system variables argc and argv to CommandLine's parse method. The arguments are now in your CommandLine object, indexed from left to right (as they appear on the command line) starting at index zero. To extract arguments into modifiable objects, you call CommandLine's getArgument() method: The CommandLine class wraps a tedious mass of code into an easy to use interface. It is central to our command line processing, and its convenient packaging makes it easy to integrate into your code.

For more information on basic command line processing, see Lippman and Lajoie, Section 7.8.

Templates:

We've talked about template classes, and you've read about template functions. Of course, we don't let you use templates quite the same way as you've learned in your basic computer science classes. Canned math classes are derived from templates to provide an easy interface to some of the most commonly used classes in our environment. On the other hand, you very well may find yourself needing a DoubleLinkedList one day, and then you'll have to know how to declare a template object.

Template object declarations are basically the same as any other object declaration. You give a type and a name to your new object. When you use a template, though, the type must include a completed parameter list for the template. For example, the first Data Structures example declares a DoubleLinkedList in line 18: The "<String>" that follows the class name is the parameter list for the template, and tells the template to generate a copy of the class that uses the String class to store data. If you wanted the linked list to hold floats instead, the code would look like: The data structures library is an excellent example of why templates are so powerful for application programming.

For more information on using templates, see Lippman and Lajoie, Section 16.2.