next up previous contents
Next: Options Up: GetPot Version 1.0 Powerful Previous: Installation   Contents

Overview

When an experienced programmer starts to write the main()-routine in C or C++ he produces by reflex a certain code fragment. Programmers who tasted GetOpt write by reflex an extended version such as the following:

#include<iostream>
#include<GetPot>
...
int main(int argc, char** argv)
{
   GetPot   cl(argc, argv);
...

The first object created in the application is of type GetPot. It uses argc and argv to build its internal database of command line arguments. This is all that is required to start doing fancy things. If one wants to parse an input file, one has to specify the filename to the constructor, i.e.

...
   GetPot   ifl("sprites.pot");
...
defines the file 'sprites.pot' to be the input file for GetPot's internal database. All functions explained in the following text work independently of the way the database was constructed. They can be applied to any object of type GetPot, whether it was build from a command line or an input file. Input files, however, provide some special features described in section 8. Distributions of GetPot versions 1.0 and above contain a getpot-mode for emacs to highlight GetPot input files.

There are four different types of command line arguments that are known to GetPot:

Options:
Arguments like --help, -h, and --force can be easily checked for existence. Further, an elegant means is provided to parse arguments that follow specific arguments.

Variables:
Variables can be defined on the command line and read out as numbers, strings or mixed type vectors.

Flags:
GetPot checks if an argument, or any option (argument starting with a single '-') contains a specific letter.

Nominus Arguments:
GetPot lets you iterate through arguments that do not start with a minus-sign.

The very basic idea of the GetPot is to specify the expected return type through a default argument3. There are three basic types known to GetPot: int, double, and const char*. A set of functions of the same name with an overloaded version for each type is called a function group.


next up previous contents
Next: Options Up: GetPot Version 1.0 Powerful Previous: Installation   Contents
Frank-Rene Schaefer 2002-09-14