class for parsing argument line
Public Methods
-
ProgOptions(const char* optPrefix="--", const char* pkgPrefix="", bool allowUnknownOptions=false)
- constructor of ProgOptions.
-
virtual ~ProgOptions()
-
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.
-
bool parse(int argc, char** argv)
- The main work of ProfOptions is here.
-
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**).
-
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**)
-
bool saveToFile(const char* fname)
- save option set to file.
-
bool is_set(const char* option) const
-
-
const char* argument(const char* option) const
-
-
int argc() const
-
char** argv() const
-
void setAdditionalHelp(bool onTop, const char* help)
- set additional help message, which is printed in outHelp call.
-
void outHelp(std::ostream& os) const
- out help message to stream os
-
void allowUnknownOptions(bool allow=true)
- set property "allow unknown options".
-
bool isUnknownOptionsAllowed() const
- report value of "allow unknown options" property
-
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
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 ?
virtual ~ProgOptions()
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.
(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.
bool 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.
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**).
- 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**)
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**)
- Parameters:
- str - : the string for parsing
- Returns:
- true, if operation was successfull
false otherwise
- See Also:
- parse(int,char**)
bool 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
bool is_set(const char* option) const
-
- Returns:
- true, if options was set in parse arguments
const char* argument(const char* option) const
-
- Returns:
- argument of options, if option have argument and it was set
in parse argument, otherwise - NULL
int argc() const
char** argv() const
void 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.
void outHelp(std::ostream& os) const
-
out help message to stream os
void 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.
bool isUnknownOptionsAllowed() const
-
report value of "allow unknown options" property
void 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++.