#include <ArgParser.hpp>
an argument parser that does not require registration.
For details and more examples, see the fsc::ArgParser member function documentation.
Definition at line 83 of file ArgParser.hpp.
Public Member Functions | |
| ArgParser () noexcept | |
| default constructor More... | |
| ArgParser (int const &argc, char *argv[]) | |
| construct from command line More... | |
| ArgParser (std::string const &cline) | |
| string constructor More... | |
| poly_type const & | operator[] (std::string const &key) const |
| get named argument if set More... | |
| poly_type const & | operator[] (size_type const &key) const |
| get free argument if set More... | |
| template<typename T > | |
| T | get (std::string const &key, T const &def) const |
| get named argument if set, else a default More... | |
| std::string | get (std::string const &key, char const *def) const |
special treatment of char const * More... | |
| template<typename T > | |
| T | get (size_type const &pos, T const &def) const |
| get free argument if set, else a default More... | |
| std::string | get (size_type const &pos, char const *def) const |
special treatment of char const * More... | |
| std::string const & | cwd () const noexcept |
| returns the current working directory More... | |
| std::string const & | pwd () const |
| returns the program working directory More... | |
| std::string const & | progname () const |
| returns the program name More... | |
| size_type | freeargc () const noexcept |
| returns the number of free arguments | |
| bool | is_set (std::string const &key) const noexcept |
| check if flag or named argument is set More... | |
| bool | is_set (size_type const &pos) const noexcept |
| check if free argument is set More... | |
| template<typename T > | |
| void | def (std::string const &key, T const &def) |
| set a named argument if not already set More... | |
| void | def (std::string const &key) |
| set a flag More... | |
| void | merge (ArgParser const &rhs, bool const &overwrite=true) noexcept |
| merge two argument parsers More... | |
| bool | parse_file (std::string const &filename, bool const &overwrite=true) |
read a file, parse the content and merge into this More... | |
| template<typename S > | |
| void | print (S &os) const noexcept |
| prints the argument parser in a verbose form More... | |
|
inlinenoexcept |
default constructor
does not generate pwd and progname.
Definition at line 95 of file ArgParser.hpp.
|
inline |
construct from command line
| argc | length of argv |
| argv | array of arguments given via command line |
the only constructor that can set pwd and progname since it can be extracted from argv[0]. Throws a std::runtime_error if the command line is ill-formed.
Definition at line 106 of file ArgParser.hpp.
|
inlineexplicit |
string constructor
| cline | a string that simulates a command line |
construct the ArgParser with a string instead of the command line to parse. Throws a std::runtime_error if the string is ill-formed. Does not generate pwd and progname.
Definition at line 121 of file ArgParser.hpp.
|
inlinenoexcept |
returns the current working directory
the cwd should always be set
Definition at line 202 of file ArgParser.hpp.
|
inline |
set a named argument if not already set
| key | name of the named argument |
| def | is a default that is set if there is no named argument key |
If there is already a flag with name key a std::runtime_error is thown.
Definition at line 257 of file ArgParser.hpp.
|
inline |
set a flag
| key | name of the flag |
If there is already a named argument with name key a std::runtime_error is thown.
Definition at line 267 of file ArgParser.hpp.
|
inline |
get named argument if set, else a default
| key | name of the named argument |
| def | is a default that is returned if key is not found |
If key is found but not convertibly to decltype(def), a std::runtime_error is thrown.
Definition at line 156 of file ArgParser.hpp.
|
inline |
special treatment of char const *
| key | name of the named argument |
| def | is a default that is returned if key is not found |
If key is found but not convertibly to std::string, a std::runtime_error is thrown.
Definition at line 169 of file ArgParser.hpp.
|
inline |
get free argument if set, else a default
| pos | position of the free argument |
| def | is a default that is returned if there is no free argument at position pos |
If the free argument at pos is found but not convertibly to decltype(def), a std::runtime_error is thrown.
Definition at line 181 of file ArgParser.hpp.
|
inline |
special treatment of char const *
| pos | position of the free argument |
| def | is a default that is returned if there is no free argument at position pos |
If pos is found but not convertibly to std::string, a std::runtime_error is thrown.
Definition at line 195 of file ArgParser.hpp.
|
inlinenoexcept |
check if flag or named argument is set
| key | is a named parameter or flag |
returns true if key is a flag or named argument. Note that it is not allowed to have a flag and named argument with the same name.
Definition at line 236 of file ArgParser.hpp.
|
inlinenoexcept |
check if free argument is set
| pos | is the position of a potential free argument |
returns true if pos < freeargc().
Definition at line 244 of file ArgParser.hpp.
|
inlinenoexcept |
merge two argument parsers
| rhs | is the argument parser that is merged into this one. |
| overwrite | defines the merging-behavior on conflicts |
The merging policy works as follows:
rhs if overwrite == true (a std::runtime_error is thrown if there is a flag - named argument collision)overwrite == true the free arguments are overwritten by the free arguments of rhs, otherwise nothing is done.rhs if overwrite == true, otherwise nothing is done. Definition at line 289 of file ArgParser.hpp.
|
inline |
get named argument if set
| key | is the name of the desired named argument |
If key is not found, a std::runtime_error is thrown.
Definition at line 132 of file ArgParser.hpp.
|
inline |
get free argument if set
| key | position of the free argument |
If key >= freeargc() a std::runtime_error is thrown, i.e. there is no free argument at the position key
Definition at line 143 of file ArgParser.hpp.
|
inline |
read a file, parse the content and merge into this
| filename | is the name of the input file |
| overwrite | defines the merging-behavior on conflicts |
the file is loaded an parsed in a seperate ArgParser inastance an the merged into this. For the mergin behavior see merge .
Definition at line 319 of file ArgParser.hpp.
|
inlinenoexcept |
prints the argument parser in a verbose form
| os | an std::ostream like object |
Definition at line 339 of file ArgParser.hpp.
|
inline |
returns the program name
Only works if the progname is set, which only happens in the command line constructor. If not set, a std::runtime_error is thrown.
Definition at line 220 of file ArgParser.hpp.
|
inline |
returns the program working directory
Only works if the pwd is set, which only happens in the command line constructor. If not set, a std::runtime_error is thrown.
Definition at line 210 of file ArgParser.hpp.