A container for holding options. More...
Public Member Functions | |
option_set (bool help=true) | |
Constructs an option_set. More... | |
option_set (std::initializer_list< option > l) | |
Constructs the option_set through std::initializer_list. More... | |
template<typename... Args> | |
void | add (Args &&...args) |
Adds an option to the option_set. More... | |
template<typename Argument > | |
option_set & | remove (const Argument &arg) |
Removes an option from the option_set. More... | |
template<typename T , typename Argument > | |
const T & | get (const Argument &arg) const |
Gets a value stored by an option. More... | |
template<typename T , typename Argument > | |
const T & | get_or (const Argument &arg, const typename std::remove_reference< T >::type &def) const noexcept |
Gets a value stored by an option or a reasonable default. More... | |
template<typename Argument > | |
bool | is_active (const Argument &arg) const noexcept |
Checks if an option's value has been parsed. More... | |
size_t | size () const noexcept |
Returns the number of elements the option_set has. | |
bool | empty () const noexcept |
Checks if the option_set is empty. | |
auto | begin () noexcept-> decltype(options.begin()) |
Returns an iterator pointing to the first option. More... | |
auto | begin () const noexcept-> decltype(options.begin()) |
auto | end () noexcept-> decltype(options.end()) |
Returns an iterator pointing to one past the end. More... | |
auto | end () const noexcept-> decltype(options.end()) |
A container used for holding options. Order is preserved and duplicates are removed if inserted. Note that this container does not meet most of the requirements imposed by the C++ standard. Rather it is used exclusively for the optparse API. Compatibility with the C++ standard is kept mostly to iterators which allow use of the functions in <algorithm>
.
Definition at line 50 of file option_set.hpp.
|
inline |
Constructs an option_set with a help option automatically provided if wanted. The help option automatically provided is --help
with a short option -h
. The description is "shows this message and exits"
.
help | Determines if help option should be automatically added. |
Definition at line 64 of file option_set.hpp.
|
inline |
Constructs the option_set through std::initializer_list. All duplicates are removed. Only the first duplicate is kept. A duplicate is determined by having the same long name and short-name. A help option is automatically provided. If the help option is unwanted then a call to remove with "help"
as a parameter will remove it.
l | The std::initializer_list to construct with. |
Definition at line 82 of file option_set.hpp.
|
inline |
Adds an option to the option_set. Duplicates are removed. The option is constructed as if calling option(std::forward<Args>(args)...)
, that is to say that they're constructed in-place.
args | Arguments to pass to the #option constructor. |
Definition at line 106 of file option_set.hpp.
|
inlinenoexcept |
Returns an iterator pointing to the first option. This member function is defined for iteration purposes and compatibility with <algorithm>
. The iterators returned are RandomAccessIterators. Dereferencing this iterator is undefined behaviour if size == 0.
Definition at line 230 of file option_set.hpp.
|
inlinenoexcept |
Returns an iterator pointing to one past the end. This member function is similar to begin with the same rules. It's undefined behaviour to dereference this iterator at all, regardless of the return of size.
Definition at line 249 of file option_set.hpp.
|
inline |
Gets a value stored by an option. The option is found as if calling option::is on the arg
parameter. If the option is not found an exception is thrown. This function is the equivalent of calling option::get.
std::invalid_argument | Thrown if the option is not found. |
arg | Long or short option to retrieve value of. |
Definition at line 154 of file option_set.hpp.
|
inlinenoexcept |
Gets a value stored by an option or a reasonable default. The option is found as if calling option::is on the arg
parameter. If the option is not found, then the default is returned.
arg | Long or short option to retrieve value of. |
Definition at line 176 of file option_set.hpp.
|
inlinenoexcept |
Checks if an option's value has been parsed. The option is found as if calling option::is on the arg
parameter. This function is the equivalent of calling option::is_active.
arg | Long or short option to retrieve value of. |
true
if the option's value has been parsed, false
otherwise. Definition at line 198 of file option_set.hpp.
|
inline |
Removes an option from the option_set by the argument long or short name. For example, if you want to remove --help
then remove("help")
would remove it. If the option is not found then this function has no effect.
arg | Long or short name to remove. |
Definition at line 130 of file option_set.hpp.