Option++
2.0
C++ library for reading command-line options
|
Holds a group of program options. More...
#include <option_group.hpp>
Public Types | |
using | value_type = option |
Type used to hold option information. | |
using | container_type = std::vector< option > |
Type of container used to hold the options. | |
using | size_type = container_type::size_type |
Type used to represent the size of the container. | |
using | iterator = container_type::iterator |
Plain iterator type. | |
using | const_iterator = container_type::const_iterator |
Constant iterator type. | |
using | reverse_iterator = container_type::reverse_iterator |
Reverse iterator type. | |
using | const_reverse_iterator = container_type::const_reverse_iterator |
Constant reverse iterator type. | |
Public Member Functions | |
option_group () noexcept | |
Default constructor. | |
option_group (const std::string &name) | |
Construct empty named group. More... | |
template<typename InputIt > | |
option_group (const std::string &name, InputIt first, InputIt last) | |
Construct from a sequence. More... | |
const std::string & | name () const noexcept |
Returns the name of the group. More... | |
option & | add_option (const option &opt=option{}) |
Add a program option to the group. More... | |
option & | add_option (const std::string &long_name, char short_name='\0', const std::string &description="", const std::string &arg_name="", bool arg_required=false) |
Construct and add a program option to the group. More... | |
size_type | size () const noexcept |
Return the number of options in the group. More... | |
bool | empty () const noexcept |
Return whether the container is empty. More... | |
iterator | begin () noexcept |
Return an iterator to the first option in the group. More... | |
const_iterator | begin () const noexcept |
Return a const_iterator to the first option . More... | |
iterator | end () noexcept |
Return an iterator to one beyond the last option in the group. More... | |
const_iterator | end () const noexcept |
Return a const_iterator to the end of the container. More... | |
const_iterator | cbegin () const noexcept |
Return a const_iterator to the first option . More... | |
const_iterator | cend () const noexcept |
Return a const_iterator to the end of the container. More... | |
reverse_iterator | rbegin () noexcept |
Return a reverse_iterator to the beginning. More... | |
const_reverse_iterator | rbegin () const noexcept |
Return a const_reverse_iterator to the beginning. More... | |
reverse_iterator | rend () noexcept |
Return a reverse_iterator to the end. More... | |
const_reverse_iterator | rend () const noexcept |
Return a const_reverse_iterator to the end. More... | |
const_reverse_iterator | crbegin () const noexcept |
Return a const_reverse_iterator to the beginning. More... | |
const_reverse_iterator | crend () const noexcept |
Return a const_reverse_iterator to the end. More... | |
iterator | find (const std::string &long_name) |
Search for an option in the group. More... | |
const_iterator | find (const std::string &long_name) const |
Search for an option in the group. More... | |
iterator | find (char short_name) |
Search for an option in the group. More... | |
const_iterator | find (char short_name) const |
Search for an option in the group. More... | |
void | sort () |
Sorts the options by name. More... | |
option & | operator[] (const std::string long_name) |
Subscript operator. More... | |
option & | operator[] (char short_name) |
Subscript operator. More... | |
Holds a group of program options.
Groups can be used to keep options organized when displaying the application's help message.
|
inline |
Construct empty named group.
name | Name of the group. |
|
inline |
Construct from a sequence.
Each option
in the sequence specifies a program option that can be given on the command line.
InputIt | The iterator type (usually deduced). |
name | Group name. |
first | The iterator pointing to the start of the sequence. |
last | The iterator pointing to one past the end of the sequence. |
Add a program option to the group.
Note that the method returns a reference to the instance of the option
that was inserted to allow chaining. For example:
opt | The option to add. |
option
, for chaining. option & optionpp::option_group::add_option | ( | const std::string & | long_name, |
char | short_name = '\0' , |
||
const std::string & | description = "" , |
||
const std::string & | arg_name = "" , |
||
bool | arg_required = false |
||
) |
Construct and add a program option to the group.
long_name | Long name for the option. |
short_name | Short name for the option. |
description | Description of the option. |
arg_name | Name of the option's argument. |
arg_required | Should be true if the option's argument is mandatory. |
option
, for chaining.
|
inlinenoexcept |
Return a const_iterator
to the first option
.
const_iterator
pointing to the first option
.
|
inlinenoexcept |
Return an iterator
to the first option in the group.
iterator
pointing to the first option
.
|
inlinenoexcept |
Return a const_iterator
to the first option
.
const_iterator
pointing to the first option
.
|
inlinenoexcept |
Return a const_iterator
to the end of the container.
const_iterator
pointing to one past the last option
.
|
inlinenoexcept |
Return a const_reverse_iterator
to the beginning.
const_reverse_iterator
pointing to the first option
in the reversed sequence.
|
inlinenoexcept |
Return a const_reverse_iterator
to the end.
const_reverse_iterator
pointing to one past the last option
in the reversed sequence.
|
inlinenoexcept |
Return whether the container is empty.
option
container is empty, false otherwise.
|
inlinenoexcept |
Return a const_iterator
to the end of the container.
const_iterator
pointing to one past the last option
.
|
inlinenoexcept |
Return an iterator
to one beyond the last option in the group.
iterator
pointing to one past the last option
. auto optionpp::option_group::find | ( | char | short_name | ) |
Search for an option in the group.
Looks up an option by its short name and returns an iterator pointing to the option
instance.
short_name | Short name of the option. |
end
if not found. auto optionpp::option_group::find | ( | char | short_name | ) | const |
Search for an option in the group.
Looks up an option by its short name and returns an iterator pointing to the option
instance.
short_name | Short name of the option. |
end
if not found. auto optionpp::option_group::find | ( | const std::string & | long_name | ) |
Search for an option in the group.
Looks up an option by its long name and returns an iterator pointing to the option
instance.
long_name | Long name of the option. |
end
if not found. auto optionpp::option_group::find | ( | const std::string & | long_name | ) | const |
Search for an option in the group.
Looks up an option by its long name and returns an iterator pointing to the option
instance.
long_name | Long name of the option. |
end
if not found.
|
inlinenoexcept |
Returns the name of the group.
option & optionpp::option_group::operator[] | ( | char | short_name | ) |
Subscript operator.
Returns the specified option or creates it if it doesn't exist.
short_name | Short name for the option. |
option
, or a newly created one if it didn't already exist. option & optionpp::option_group::operator[] | ( | const std::string | long_name | ) |
Subscript operator.
Returns the specified option or creates it if it doesn't exist.
long_name | Long name for the option. |
option
, or a newly created one if it didn't already exist.
|
inlinenoexcept |
Return a const_reverse_iterator
to the beginning.
const_reverse_iterator
pointing to the first option
in the reversed sequence.
|
inlinenoexcept |
Return a reverse_iterator
to the beginning.
reverse_iterator
pointing to the first option
in the reversed sequence.
|
inlinenoexcept |
Return a const_reverse_iterator
to the end.
const_reverse_iterator
pointing to one past the last option
in the reversed sequence.
|
inlinenoexcept |
Return a reverse_iterator
to the end.
reverse_iterator
pointing to one past the last option
in the reversed sequence.
|
inlinenoexcept |
Return the number of options in the group.
void optionpp::option_group::sort | ( | ) |
Sorts the options by name.
By default, options are kept in the same order as they were added. Calling this method will sort them by name (that is, for each option, if both long and short names exist, then the long name is used for comparison).