plll
1.0
|
Parses command line arguments and makes them accessible. More...
#include <arguments.hpp>
Classes | |
class | Value |
Stores the value of one command line argument. More... | |
Public Member Functions | |
ArgumentParser (int argc, char **argv) | |
Parses the command line arguments. Ignores the name of the current program. | |
template<class Fun > | |
void | enumerateUnprocessedArguments (Fun f) const |
Calls a functor for every unchecked label/values pair. More... | |
const std::list< std::string > & | getNames () const |
Retrieves a list of names, i.e. arguments not starting with - or preceeded with -- . | |
const Value * | getValue (const std::string &arg) const |
Looks up the value of a label. More... | |
bool | hasNoArguments () const |
Quick tests whether arguments were given. | |
bool | hasUnprocessedArguments () const |
Tests for unchecked label/values pairs. More... | |
Parses command line arguments and makes them accessible.
Typically, the command line of a command line program is an array of strings:
"<executable name>" "-value=1" "-R" "name1" "-h=" "name2" "--" "-name3", "--debug=all"
The ArgumentParser
class' constructor accepts such a list of C strings as provided to the main()
function, and splits it up in a list of names, in this case "name1", "name2" and "-name3" (because "-name3" is preceeded with "--", it is not treated as a value), and a list of values with lables. Here, the values with their labels are:
"value"
-> "1"
,"R"
-> (empty),"h"
-> ""
,"-debug"
-> "all"
.Integers and floating point numbers are detected, and it is tried to parse them (as long
or double
), with a warning system (Value::hasOverflow()
returns true
if the value apparently does not fit in these types).
Definition at line 42 of file arguments.hpp.
|
inline |
Calls a functor for every unchecked label/values pair.
Calls the functor f
for every argument not checked yet with getValue()
. The functor f
is called for every such argument with parameters of type std::string
for the argument name and plll::ArgumentParser::Value *
for its value.
Definition at line 256 of file arguments.hpp.
|
inline |
Looks up the value of a label.
Retrieves a plll::ArgumentParser::Value
object for the given argument label arg
if it was found, or NULL
in case the argument was not found.
Definition at line 223 of file arguments.hpp.
|
inline |
Tests for unchecked label/values pairs.
Returns true
if arguments exists whose existence haven't been checked with getValue()
.
Definition at line 243 of file arguments.hpp.