SB++
Sandbox applications
Loading...
Searching...
No Matches
arg::Arg Class Reference

A command-line argument. More...

#include <arguments.hpp>

+ Collaboration diagram for arg::Arg:

Public Member Functions

 Arg (const config &c, const std::function< std::string(const std::string_view &)> &handler=[](const std::string_view &value){return std::string(value);}, const std::function< std::string(const std::string_view &)> &m_handler=[](const std::string_view &value){return std::string(value);})
 Construct an argument.
 
bool digest (const shared::vector &args, uint_fast8_t &x)
 Digest arguments.
 
void update ()
 Update configurations.
 
std::string get_help () const
 Get the help text for the argument.
 
auto && get (this auto &&self)
 Get a mutable reference to the stored value.
 
void emplace (const std::string &val)
 Emplace a value.
 
auto && mod (this auto &&self)
 Get a mutable reference to the stored modifier.
 
const bool & is_list () const
 Return whether the argument is a list.
 
const bool & is_flagset () const
 Return whether the argument is a flagset.
 
uint_fast8_t level () const
 Return the current level of the argument.
 
auto && get_list (this auto &&self)
 Return a mutable reference to each unique value passed to the argument.
 
auto && get_valid (this auto &&self)
 Return a set of all valid values.
 
std::vector< std::pair< std::string, std::string > > get_modlist () const
 Return all values paired with their modifiers.
 
const bool & updates_sof () const
 
const uint_fast8_t & position () const
 Return the position of the argument.
 
 operator bool () const
 Return whether the argument was set.
 
const bool operator< (const std::string_view &val) const
 Check if the current value is underneath the provided.
 
const bool operator>= (const std::string_view &val) const
 Check if the current value meets the provided.
 

Detailed Description

A command-line argument.

Constructor & Destructor Documentation

◆ Arg()

arg::Arg::Arg ( const config & c,
const std::function< std::string(const std::string_view &)> & handler = [](const std::string_view& value){return std::string(value);},
const std::function< std::string(const std::string_view &)> & m_handler = [](const std::string_view& value){return std::string(value);} )
inline

Construct an argument.

Parameters
cTHe configuration structure.
handlerThe regular lambda for parsing arguments.
m_handlerThe lambda for parsing modifier arguments.

Member Function Documentation

◆ digest()

bool arg::Arg::digest ( const shared::vector & args,
uint_fast8_t & x )
inline

Digest arguments.

Parameters
argsThe list of command line arguments.
xThe current position within the list.
Returns
: Whether the current argument was consumed.

◆ emplace()

void arg::Arg::emplace ( const std::string & val)
inline

Emplace a value.

Parameters
valThe value to emplace.
Exceptions
std::runtime_errorif the valid is invalid.
Note
For single value arguments, this overwrites the stored value. For lists, it emplaces to the back of the list if its valid.
Warning
This function uses the same parsing logic as initial argument parsing, which means invalid values will throw exceptions.
+ Here is the caller graph for this function:

◆ get()

auto && arg::Arg::get ( this auto && self)
inline

Get a mutable reference to the stored value.

Returns
The reference.
Exceptions
std::runtime_errorif the argument is a list, use get_list() instead.

◆ get_help()

std::string arg::Arg::get_help ( ) const
inline

Get the help text for the argument.

Returns
The string.

◆ get_list()

auto && arg::Arg::get_list ( this auto && self)
inline

Return a mutable reference to each unique value passed to the argument.

Returns
The set.
Exceptions
std::runtime_errorif the argument is not a list.

◆ get_modlist()

std::vector< std::pair< std::string, std::string > > arg::Arg::get_modlist ( ) const
inline

Return all values paired with their modifiers.

Returns
A vector of pairs.
Exceptions
std::runtime_errorif the argument is not a list, or doesn't allow modifiers.

◆ get_valid()

auto && arg::Arg::get_valid ( this auto && self)
inline

Return a set of all valid values.

Returns
The set.

◆ is_flagset()

const bool & arg::Arg::is_flagset ( ) const
inline

Return whether the argument is a flagset.

Returns
Whether the argument is a true/false with a list of flags

◆ is_list()

const bool & arg::Arg::is_list ( ) const
inline

Return whether the argument is a list.

Returns
Whether the argument accepts multiple values.

◆ level()

uint_fast8_t arg::Arg::level ( ) const
inline

Return the current level of the argument.

Returns
The current level.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mod()

auto && arg::Arg::mod ( this auto && self)
inline

Get a mutable reference to the stored modifier.

Returns
The modifier.
Note
This function returns an empty string if a modifier does not exist or is allowed.

◆ operator bool()

arg::Arg::operator bool ( ) const
inline

Return whether the argument was set.

Returns
Whether the value is greater than the default (IE unset).
+ Here is the call graph for this function:

◆ operator<()

const bool arg::Arg::operator< ( const std::string_view & val) const
inline

Check if the current value is underneath the provided.

Parameters
valThe value to check.
Returns
Whether the current value is less than the provided.
+ Here is the call graph for this function:

◆ operator>=()

const bool arg::Arg::operator>= ( const std::string_view & val) const
inline

Check if the current value meets the provided.

Parameters
valThe value to check.
Returns
Whether the current value meets the provided.
+ Here is the call graph for this function:

◆ position()

const uint_fast8_t & arg::Arg::position ( ) const
inline

Return the position of the argument.

Returns
The mandatory level.
+ Here is the caller graph for this function:

◆ update()

void arg::Arg::update ( )
inline

Update configurations.

Note
This function is used for arguments that depend on the value of other arguments.

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