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:
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.