class GradSoft::ProgOptions

class for parsing argument line

Public Methods

[more] ProgOptions(const char* optPrefix="--", const char* pkgPrefix="", bool allowUnknownOptions=false)
constructor of ProgOptions.
[more]virtual ~ProgOptions()
[more]void put(const char* option, const char* description, bool haveArgument = false, bool (*callback)(const ProgOptions*, const char*, void*)=NULL, void* callbackData =NULL )
put option to set of parsed options.
[more]bool parse(int argc, char** argv)
The main work of ProfOptions is here.
[more]bool parseFile(const char* fname, const char* executable="unspecified")
This method forms argument vector from options set in given file, and parses it like parse(int,char**).
[more]bool parseString(const char* str, const char* executable="unspecified")
forms argument vector from the string transmitted like to parseFile(const char*) and parses it like to parse(int,char**)
[more]bool saveToFile(const char* fname)
save option set to file.
[more]bool is_set(const char* option) const
[more]const char* argument(const char* option) const
[more]int argc() const
[more]char** argv() const
[more]void setAdditionalHelp(bool onTop, const char* help)
set additional help message, which is printed in outHelp call.
[more]void outHelp(std::ostream& os) const
out help message to stream os
[more]void allowUnknownOptions(bool allow=true)
set property "allow unknown options".
[more]bool isUnknownOptionsAllowed() const
report value of "allow unknown options" property
[more]void putArgs(const char* executable, int argc, char** argv)
put additional arguments, which must be parsed with readed options

Public Members

class ArgsHolder
class to hold a copy of argument vector given


Documentation

class for parsing argument line

o ProgOptions(const char* optPrefix="--", const char* pkgPrefix="", bool allowUnknownOptions=false)
constructor of ProgOptions.

Invariants:
caller is responsible for memory allocation for optPrefix and pkgPrefix, i. e. this parameters must be present in memory and be unchanged during lifetime of ProgOptions (string constants are ok).
Parameters:
optPrefix - - option prefix. all options must begin with optPrefix
pkgPrefix - - package prefix. (default -e empty) ( i. e. option have format <optPrefix><pkgPrefix>XXX )
allowUnknowOptions - - are we exit, when we meet unknown option during parse ?

ovirtual ~ProgOptions()

ovoid put(const char* option, const char* description, bool haveArgument = false, bool (*callback)(const ProgOptions*, const char*, void*)=NULL, void* callbackData =NULL )
put option to set of parsed options. (i. e. after call of put("OptionName", ... ) parse will understood construction <optPrefix><pkgPrefix><OptionName>.
Parameters:
option - - option name.
description - - description of option
haveArgument - - is this option have argument ?
callback - - user function, which will be called during parsing of command line, if such option belong to one.
callbackData - - additional data, which will be passed to callback function.

obool parse(int argc, char** argv)
The main work of ProfOptions is here. The function do next: check: if argv[i] have form <optPrefix><option>, if yes, and appropriative option have parameter: read parameter, (which can be in next input word, or in current word after = [i. e. --x=Y and --x Y are identical]), than call callback with argument, if it was set in put call; than initialize data structure. if option have form <optPrefix><pkgPrefix>help, than output help message.
Parameters:
- argc, argv -- command line.
Returns:
true, if options was parsed successfully, and it was not option <optPrefix><pkgPrefix>help, otherwise false
Preconditions:
all parsed options must be setted before call of parse.
Postconditions:
is_set(), argument(), argc() and argv() methods being functionally.

obool parseFile(const char* fname, const char* executable="unspecified")
This method forms argument vector from options set in given file, and parses it like parse(int,char**).

Parameters:
fname - : the name of file for parsing
Returns:
true, if operation was successfull false otherwise
Preconditions:
The file to parse must be formatted (turn to Programming Guide for details). If the format is not observed, the method ceases from the work, prints message, and returns the 'false'
See Also:
parse(int,char**)

obool parseString(const char* str, const char* executable="unspecified")
forms argument vector from the string transmitted like to parseFile(const char*) and parses it like to parse(int,char**)

Parameters:
str - : the string for parsing
Returns:
true, if operation was successfull false otherwise
See Also:
parse(int,char**)

obool saveToFile(const char* fname)
save option set to file. @precondigion must be called afer parse
Parameters:
fname - is a reference to string with name of file
Returns:
true, if operation was successfull false otherwise

obool is_set(const char* option) const
Returns:
true, if options was set in parse arguments

oconst char* argument(const char* option) const
Returns:
argument of options, if option have argument and it was set in parse argument, otherwise - NULL

oint argc() const

ochar** argv() const

ovoid setAdditionalHelp(bool onTop, const char* help)
set additional help message, which is printed in outHelp call. (actually 2 messages: one on top of option description, second - on bottom)
Parameters:
onTop - - where to place message ?
help - - message to output.

ovoid outHelp(std::ostream& os) const
out help message to stream os

ovoid allowUnknownOptions(bool allow=true)
set property "allow unknown options". if it is set to true, than unknow options are ignored by parse, otherwise it's caused Parser to report error.
Parameters:
allow - - value of property to set.

obool isUnknownOptionsAllowed() const
report value of "allow unknown options" property

ovoid putArgs(const char* executable, int argc, char** argv)
put additional arguments, which must be parsed with readed options


This class has no child classes.
Friends:
class WordSequence

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.