YGP::IVIOApplication Class Reference

Class to handle the startup of a program, which includes reading the data stored in an INI file and (afterwards) the parsing of the parameters before the actual run of the program. More...

List of all members.

Classes

struct  longOptions
 Helper-structure to store long-options. More...

Public Member Functions

 IVIOApplication (const int argc, const char *argv[], const longOptions *pOpt=NULL)
virtual ~IVIOApplication ()
int run ()

Static Public Member Functions

static void initI18n ()
static void initI18n (const char *package, const char *dir)

Protected Member Functions

virtual bool handleOption (const char option)=0
const char * getOptionValue ()
const char * checkOptionValue () const
void setLongOptions (const longOptions *pLongOpts)
void setLongOptions (const longOptions *pLongOpts, unsigned int numLongOpts)
virtual void readINIFile (const char *)
Program-handling
virtual int perform (int argc, const char *argv[])=0
virtual const char * name () const
virtual const char * description () const =0
const char * filename () const
Help-handling
virtual bool shallShowInfo () const
virtual void showHelp () const =0

Protected Attributes

unsigned int args
const char ** ppArgs


Detailed Description

Class to handle the startup of a program, which includes reading the data stored in an INI file and (afterwards) the parsing of the parameters before the actual run of the program.

Furthermore in case of a segmentation fault a stacktrace is dumped to the systemlog (or to stdout).

The INI file is named according the name-method, with the following changes (depending on the operating system):

Parameters starting with a minus (-) (in Windoze also a with a slash (/)) are treated as options and reported via the handleOption-method. Every option can also be represented in a verbose way starting with two minus-characters (--). What follows is only a short description; more information can be found in the getopt man page (which unfortunately can't be found on a Windows system, but such is life).

The parameters are parsed from left to right. Each parameter is classified as a short option, a long option (both reported via the handleOption()-method), an argument to an option, or a non-option parameter.

A simple short option is a minus (-) (or might be a slash (/) in Windoze) followed by a short option character. If the option has an argument, it may be written directly after the option character or as the next parameter (ie. separated by whitespace on the command line).

It is possible to specify several short options after one minus (-), as long as all (except possibly the last) do not have arguments.

A long option normally begins with `--' followed by the long option name. If the option has an argument, it may be written directly after the long option name, separated by an equal-sign (=), or as the next argument (ie. separated by whitespace on the command line). Long options may be abbreviated, as long as the abbreviation is not ambiguous.

Every parameter which is not an option or an argument to an option or after a '--'-parameter is a non-option parameter and is passed to the perform()-method. Options are inspected before that method is called!

Note:
The options -h and -? causes the call of the showHelp()-method!
Programmers information:

Unlike in the UNIX getopt-function, optional paramters need not to be marked in a special way. Instead use the checkOptionValue()-method to retrieve the value of the possible argument, analyze it (like for having no leading minus (-)) and retrieve it with the getOptionValue()-method if OK.

As a further feature a stackdump is logged in case of a protection fault.


Constructor & Destructor Documentation

YGP::IVIOApplication::IVIOApplication ( const int  argc,
const char *  argv[],
const longOptions pOpt = NULL 
)

Constructor; the parameters specify the number of and an array with the program-arguments (as passed to the main-function) and a table to map the verbose long-options to their short equivalent.

If the third parameter is NULL, no long options are used.

Parameters:
argc Number of arguments
argv Array of pointers to argumetns
pOpt Pointer to long-option-table

YGP::IVIOApplication::~IVIOApplication (  )  [virtual]

Destructor.


Member Function Documentation

const char* YGP::IVIOApplication::checkOptionValue (  )  const [inline, protected]

Returns the value to the current option, but without "consuming" it.

This enables to check the value.

virtual const char* YGP::IVIOApplication::description (  )  const [protected, pure virtual]

Returns a description to the program.

const char* YGP::IVIOApplication::filename (  )  const [inline, protected]

Returns the name of the program as passed by the operating system (argv[0]).

const char * YGP::IVIOApplication::getOptionValue (  )  [protected]

Returns the value to the current option and increases the pointer the next option.

These parameter are searched using the following algorithm:

  • The remaining characters in a list of simple options (e.g. if called for the option d in "-dlevel1" the method would return "level1") or the value behind the equal sign (=) if given in a long option.
  • The next argument of the application.
  • NULL
    Returns:
    char* Parameter for the option

virtual bool YGP::IVIOApplication::handleOption ( const char  option  )  [protected, pure virtual]

Handle the options of the program. The current (parsed) option is passed.

void YGP::IVIOApplication::initI18n ( const char *  package,
const char *  dir 
) [static]

Initializes the program for internationalization by setting the current locale and loading the message file.

Parameters:
package Name of the message-catalog
dir root-directory for message-catalogs
Remarks:
If the GNU gettext library is not installed or supported, the methods only sets the locale!

void YGP::IVIOApplication::initI18n (  )  [static]

Initializes the program for internationalization by setting the current locale.

const char * YGP::IVIOApplication::name (  )  const [protected, virtual]

Returns the name of the application.

The default action is to return the name of the file as stored in index 0 of the argv-array, stripped of any path information.

Returns:
const char* Name of programm

virtual int YGP::IVIOApplication::perform ( int  argc,
const char *  argv[] 
) [protected, pure virtual]

Performs the job of the program.

virtual void YGP::IVIOApplication::readINIFile ( const char *   )  [inline, protected, virtual]

Parses some initialization data from a file specified by pFile.

Parameters:
Name of file to read

int YGP::IVIOApplication::run (  ) 

Runs the application; first the method readINIFile() is called to read the data from an INI file.

Then the options are checked. If an invalid or a help-option is passed, the help-screen is displayed, else the actual job of the application is performed.

Returns:
int Status

void YGP::IVIOApplication::setLongOptions ( const longOptions pLongOpts,
unsigned int  numLongOpts 
) [protected]

Sets a table which maps options to a verbose version.

This table must not contain entries with either '\0' as short option or NULL as long option.

Parameters:
pLongOpts Pointer to an array of longOptions
numLongOpts Number of elements in the array
Precondition:
  • pLongOpts not NULL
  • all long-entries not NULL
  • all short-entries not '\0'

void YGP::IVIOApplication::setLongOptions ( const longOptions pLongOpts  )  [protected]

Sets a table which maps options to a verbose version.

This table must be terminated with an entry where the short option is '\0' and the associated long options is NULL; the previous entries must not have lines with those values.

Parameters:
pLongOpts Pointer to an array of longOptions; terminated with a longOption with NULL as longVal
Precondition:
  • pLongOpts not NULL
  • all long-entries not NULL
  • all short-entries not '\0'
  • An entry with an { NULL, '\0' } at the end

virtual bool YGP::IVIOApplication::shallShowInfo (  )  const [inline, protected, virtual]

Returns true, if a short programm information (name and release) should be displayed (default: Yes).

virtual void YGP::IVIOApplication::showHelp (  )  const [protected, pure virtual]

Returns true, if a short programm information (name and release) should be displayed (default: Yes).


Member Data Documentation

unsigned int YGP::IVIOApplication::args [protected]

Number of arguments passed to the program (argc).

const char** YGP::IVIOApplication::ppArgs [protected]

The arguments passed to the program (argv).


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

YGP Version 0.9.31 - Generated on Wed Nov 18 11:25:27 2009 by doxygen 1.5.8