FleCSI User API Version: 2.3.0
 
Loading...
Searching...
No Matches
program_option< ValueType > Struct Template Reference

The program_option type is a wrapper that implements a useful subset of Boost's Program Options utility. More...

Public Member Functions

bool has_value () const
 Return whether the option was set.
 
 operator ValueType () const
 Get the value, which must exist.
 
template<class F = decltype((default_check))>
 program_option (const char *name, const char *help, size_t count, F &&check=default_check)
 Construct a positional program option.
 
template<class F = decltype((default_check))>
 program_option (const char *section, const char *flag, const char *help, std::initializer_list< initializer_value > values={}, F &&check=default_check)
 Construct a program option.
 
ValueType value () const
 Get the value, which must exist.
 

Detailed Description

template<typename ValueType>
struct flecsi::program_option< ValueType >

The program_option type is a wrapper that implements a useful subset of Boost's Program Options utility.

Creating an instance of this type at namespace scope will add a program option that can be queried after the initialize function is called.

A validation function can have the signature bool(ValueType,std::stringstream&) or bool(flecsi::any,std::stringstream&). An error message may be written to the stream. In the latter, deprecated case, use option_value to obtain the ValueType.

Constructor & Destructor Documentation

◆ program_option() [1/2]

template<typename ValueType >
template<class F = decltype((default_check))>
program_option ( const char *  section,
const char *  flag,
const char *  help,
std::initializer_list< initializer_value >  values = {},
F &&  check = default_check 
)

Construct a program option.

Parameters
sectionThe options description label.
flagThe command-line option in long, short, or dual form, e.g., "option,o" -> --option or -o.
helpThe help message for the option.
valuesMechanism to set optional value attributes. Supported keys are option_default, option_implicit, option_zero, and option_multi. If an option_default value is specified, it will be used if the flag is not passed to the command line. If an option_implicit value is specified, it will be used if the flag is passed to the command line without a value. If option_zero is passed, the flag will not take any values, and must have an option_implicit value specified. If option_multi is passed, the flag will take multiple values.
checkAn optional, user-defined predicate to validate the option passed by the user; see signature below.
program_option<int> my_flag("My Section",
"flag,f",
"Specify the flag [0-9].",
{
{option_default, 1},
{option_implicit, 0}
},
[](int value, std::stringstream &) {
return value >= 0 && value < 10;
});
The program_option type is a wrapper that implements a useful subset of Boost's Program Options utili...
Definition options.hh:62
ValueType value() const
Get the value, which must exist.
Definition options.hh:224

◆ program_option() [2/2]

template<typename ValueType >
template<class F = decltype((default_check))>
program_option ( const char *  name,
const char *  help,
size_t  count,
F &&  check = default_check 
)

Construct a positional program option.

Parameters
nameThe name for the positional option.
helpThe help message for the option.
countThe number of values to consume for this positional option. If -1 is passed, this option will consume all remaining values.
checkAn optional, user-defined predicate to validate the option passed by the user.

Member Function Documentation

◆ value()

template<typename ValueType >
ValueType value ( ) const

Get the value, which must exist.

◆ operator ValueType()

template<typename ValueType >
operator ValueType ( ) const

Get the value, which must exist.

◆ has_value()

template<typename ValueType >
bool has_value ( ) const

Return whether the option was set.