argagg: argagg::option_results Struct Reference

argagg

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
argagg::option_results Struct Reference

Represents multiple option parse results for a single option. If treated as a single parse result it defaults to the last parse result. Note that an instance of this struct is always created even if no option results are parsed for a given definition. In that case it will simply be empty. More...

`#include <argagg.hpp>`

## Public Member Functions
std::size_t | count () const
| Gets the number of times the option shows up.
option_result & | operator[] (std::size_t index)
| Gets a single option parse result by index.
const option_result & | operator[] (std::size_t index) const
| Gets a single option result by index.
template<typename T>
T | as () const
| Converts the argument parsed for the LAST option parse result for the parent definition to the provided type. For example, if this was for "-f 1 -f 2 -f 3" then calling this method for an integer type will return 3. If there are no option parse results then a std::out_of_range exception is thrown. Any exceptions thrown by option_result::as() are not handled.
template<typename T>
T | as (const T &t) const
| Converts the argument parsed for the LAST option parse result for the parent definition to the provided type. For example, if this was for "-f 1 -f 2 -f 3" then calling this method for an integer type will return 3. If there are no option parse results then the provided default value is returned instead.
template<typename T>
| operator T () const
| Since we have the option_results::as() API we might as well alias it as an implicit conversion operator. This performs implicit conversion using the option_results::as() method.
bool | operator! () const
| Explicitly define a unary not operator that wraps the implicit boolean conversion specialization in case the compiler can't do it automatically.

## Public Attributes
std::vector< option_result > | all
| All option parse results for this option.

## Detailed Description

Represents multiple option parse results for a single option. If treated as a single parse result it defaults to the last parse result. Note that an instance of this struct is always created even if no option results are parsed for a given definition. In that case it will simply be empty.

To check if the associated option showed up at all simply use the implicit boolean conversion or check if count() is greater than zero.

Definition at line 332 of file argagg.hpp.

## Member Function Documentation

## ◆ as() [1/2]

template<typename T>

T argagg::option_results::as | ( |  | ) | const

Converts the argument parsed for the LAST option parse result for the parent definition to the provided type. For example, if this was for "-f 1 -f 2 -f 3" then calling this method for an integer type will return 3. If there are no option parse results then a std::out_of_range exception is thrown. Any exceptions thrown by option_result::as() are not handled.

Definition at line 809 of file argagg.hpp.

## ◆ as() [2/2]

template<typename T>

T argagg::option_results::as | ( | const T & | t | ) | const

Converts the argument parsed for the LAST option parse result for the parent definition to the provided type. For example, if this was for "-f 1 -f 2 -f 3" then calling this method for an integer type will return 3. If there are no option parse results then the provided default value is returned instead.

Definition at line 819 of file argagg.hpp.

## ◆ count()

std::size_t argagg::option_results::count | ( |  | ) | const
| inline

Gets the number of times the option shows up.

Definition at line 788 of file argagg.hpp.

## ◆ operator T()

template<typename T>

argagg::option_results::operator T | ( |  | ) | const

Since we have the option_results::as() API we might as well alias it as an implicit conversion operator. This performs implicit conversion using the option_results::as() method.

Note
  An implicit boolean conversion specialization exists which returns false if there is no argument for this single option instance and true otherwise. This specialization DOES NOT convert the argument to a bool. If you need to convert the argument to a bool then use the as() API.

Definition at line 829 of file argagg.hpp.

## ◆ operator!()

bool argagg::option_results::operator! | ( |  | ) | const
| inline

Explicitly define a unary not operator that wraps the implicit boolean conversion specialization in case the compiler can't do it automatically.

Definition at line 843 of file argagg.hpp.

## ◆ operator[]() [1/2]

option_result & argagg::option_results::operator[] | ( | std::size_t | index | ) |
| inline

Gets a single option parse result by index.

Definition at line 795 of file argagg.hpp.

## ◆ operator[]() [2/2]

const option_result & argagg::option_results::operator[] | ( | std::size_t | index | ) | const
| inline

Gets a single option result by index.

Definition at line 802 of file argagg.hpp.

## Member Data Documentation

## ◆ all

std::vector<option_result> argagg::option_results::all

All option parse results for this option.

Definition at line 338 of file argagg.hpp.

The documentation for this struct was generated from the following file:

- /tmp/pkg/src/argagg-0.4.7/include/argagg/argagg.hpp