soma-io  4.7.0
CartoApplication Class Reference

#include <soma-io/doc/getopt_doc.h>

Detailed Description

carto::CartoApplication is normally the entry point of the options parsing system. It inherits OptionsParser to benefit from its addOption(), addOptionSeries() and alias() methods, and parsing is triggered by the initialize() function.

carto::CartoApplication adds the commandline description, and some standard common options which all cartograph commands will provide:

  • -h / –help prints the commandline and its parameters descriptions
  • –verbose sets the verbosity level of the commandline (more messages may be printed when the verbosity level increases)
  • –version shows version information about cartograph libraries and possibly of upper-level libraries based on cartograph
  • –info prints various information about the libraries, like plugins list, supported IO formats and objects types, versions, external shared data paths, etc.

carto::CartoApplication may be subclassed in upper-level libraries which may add some other common options. For instance, AIMS programs will use AimsApplication instead of carto::CartoApplication.

A normal Cartograph program will generally have a main() function looking like the following example:

#include <cstdlib>
#include <iostream>
using namespace soma;
using namespace carto;
using namespace std;
int main( int argc, const char **argv )
{
try
{
CartoApplication app( argc, argv, "The commandline help description" );
string inputparam1;
int inputparam2 = 0;
app.addOption( inputparam1, "-i1", "first input parameter" );
app.addOption( inputparam2, "-i2", "second input parameter", true );
// commandline parsing is done by initialize()
app.initialize();
// now inputparam1 is filled, and inputparam2 too if provided
}
catch( user_interruption & )
{
// when the -h option is used, the help is displayed, and a
// user_interruption exception is thrown to avoid running the
// normal program execution. So we must silently catch it because
// it is not really an error
}
catch( exception & e )
{
// all other exceptions are catched here (commandline errors like
// missing or unrecognized option, or any other exception thrown
// during the program execution)
cerr << e.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

The documentation for this class was generated from the following file: