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 |
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):
~/.name
.HOMEDRIVE%HOMEPATHname.ini
.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!
-h
and -?
causes the call of the showHelp()-method!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.
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.
argc | Number of arguments | |
argv | Array of pointers to argumetns | |
pOpt | Pointer to long-option-table |
YGP::IVIOApplication::~IVIOApplication | ( | ) | [virtual] |
Destructor.
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:
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.
package | Name of the message-catalog | |
dir | root-directory for message-catalogs |
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.
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
.
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.
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.
pLongOpts | Pointer to an array of longOptions | |
numLongOpts | Number of elements in the array |
pLongOpts
not NULLvoid 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.
pLongOpts | Pointer to an array of longOptions; terminated with a longOption with NULL as longVal |
pLongOpts
not NULLvirtual 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).
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).