Inherits gears::optparse::value_base.
|
(Note that these are not member functions.)
|
template<typename Container , typename Action = store<typename Container::value_type>> |
std::unique_ptr< value_base > | compose (std::string metavar="", Action action=Action{}) |
| Returns a typed_value for composed values. More...
|
|
template<typename T , typename Action = store<T>> |
std::unique_ptr< value_base > | bind_to (T &t, std::string metavar="", Action action=Action{}) |
| Returns a typed_value that binds the result to a variable. More...
|
|
template<typename T > |
std::unique_ptr< value_base > | constant (const T &t) |
| Returns a typed_value that returns a constant value. More...
|
|
template<typename T , typename Action = store<T>> |
std::unique_ptr< value_base > | value (std::string metavar="", Action action=Action{}) |
| Returns a regular typed_value. More...
|
|
template<typename T , typename Action > |
std::unique_ptr< value_base > | custom (Action action, std::string metavar="") |
| Returns a typed_value with a custom action. More...
|
|
template<typename Container , typename Action = store<typename Container::value_type>> |
std::unique_ptr< value_base > | list (size_t arguments, std::string metavar="", Action action=Action{}) |
| Returns a typed_value that handles a list of values. More...
|
|
template<typename T>
struct gears::optparse::typed_value< T >
A class that represents a command line value to be used with command line options that expect one or more arguments to be given. This class is usually not used explicitly as many factory functions are provided for common use cases.
- Template Parameters
-
T | The type of argument expected. |
Definition at line 51 of file value.hpp.
template<typename T>
template<typename Action >
Specifies the action callback to use for parsing. All parsing of values is done through a callback mechanism called actions. The signature of an action must be T(const std::string&, const std::string&)
. Many actions are provided with a reasonable default, this should only be called if you have created a custom action. The first argument passed is the key of the command line option, and the second one is the value. For example, passing --foo=test
on the command line would result in the first argument being --foo
and the second being test
.
- Parameters
-
action | The action callback to use. |
- Returns
- A reference to the typed_value object.
Definition at line 119 of file value.hpp.
template<typename T , typename Action = store<T>>
std::unique_ptr< value_base > bind_to |
( |
T & |
t, |
|
|
std::string |
metavar = "" , |
|
|
Action |
action = Action{} |
|
) |
| |
|
related |
Returns a typed_value that when parsed, binds the result to an l-value variable. For example, having an option being declared like so:
int x;
opt::option test = { "test", 't', "tests something", opt::bind_to(x) };
When the command line is parsed with 10
as a value, e.g. --test=10
then the variable x will contain the value 10
.
- Parameters
-
t | The variable to bind the result to. |
metavar | The metavar variable to assign to the optparse::value. |
action | The action to use for parsing the value. Defaults to optparse::store. |
- Returns
- A polymorphic
typed_value
to use with optparse::option.
Definition at line 204 of file value.hpp.
template<typename Container , typename Action = store<typename Container::value_type>>
std::unique_ptr< value_base > compose |
( |
std::string |
metavar = "" , |
|
|
Action |
action = Action{} |
|
) |
| |
|
related |
Returns a typed_value for composed values. Composed values return a list of all the elements concatenated. For example, having a composed optparse::option would allow things like --test=10 --test=20 --test=30
to produce a list of [10, 20, 30]
.
- Parameters
-
metavar | The metavar variable to assign to the optparse::value. |
action | The internal action to parse the values to. |
- Returns
- A polymorphic
typed_value
to use with optparse::option.
Definition at line 177 of file value.hpp.
template<typename T , typename Action >
std::unique_ptr< value_base > custom |
( |
Action |
action, |
|
|
std::string |
metavar = "" |
|
) |
| |
|
related |
Returns a typed_value with a custom action. This is typically used if you want to just specify a custom action parser. Every other factory function provides an action parameter to handle inputting custom actions, so this one is provided to switch the parameter list of optparse::value.
- Template Parameters
-
T | The type of value to store. |
- Parameters
-
action | The action used to parse values. |
metavar | The metavar variable to assign to the optparse::value. |
- Returns
- A polymorphic
typed_value
to use with optparse::option.
Definition at line 265 of file value.hpp.
template<typename T , typename Action = store<T>>
std::unique_ptr< value_base > value |
( |
std::string |
metavar = "" , |
|
|
Action |
action = Action{} |
|
) |
| |
|
related |
Returns a regular typed_value. If a command line value is required for your interface, this is the recommended way of creating values. If you prefer the parameters to be (action, metavar) then optparse::custom implements this order.
- Template Parameters
-
T | The type of value to store. |
- Parameters
-
metavar | The metavar variable to assign to the optparse::value. |
action | The action used to parse values. If not provided, defaults to optparse::store. |
- Returns
- A polymorphic
typed_value
to use with optparse::option.
Definition at line 244 of file value.hpp.