E-MailRelay
Public Member Functions | Static Public Member Functions | List of all members
G::OptionValue Class Reference

A simple structure encapsulating the value of a command-line option. More...

#include <goptionvalue.h>

Public Member Functions

 OptionValue ()
 Default constructor for a valueless value. More...
 
 OptionValue (const std::string &s, std::size_t count=1U)
 Constructor for a valued value. More...
 
bool isOn () const noexcept
 Returns true if on(). More...
 
bool isOff () const noexcept
 Returns true if off(). More...
 
std::string value () const
 Returns the value as a string. More...
 
std::string_view valueref () const noexcept
 Exposes the value as a string view. More...
 
bool operator== (std::string_view) const noexcept
 Returns true if the given string matches value(). More...
 
bool numeric () const noexcept
 Returns true if value() is an unsigned integer. More...
 
unsigned int number (unsigned int default_=0U) const
 Returns value() as an unsigned integer. More...
 
size_t count () const noexcept
 Returns an instance count that is one by default. More...
 
void increment () noexcept
 Increments the instance count(). More...
 

Static Public Member Functions

static OptionValue on ()
 A factory function for an unvalued option-enabled option. More...
 
static OptionValue off ()
 A factory function for an unvalued option-disabled option. More...
 

Detailed Description

A simple structure encapsulating the value of a command-line option.

Unvalued options (eg. "--debug") can be be explicitly on (eg. "--debug=yes") or off ("--debug=no"); the latter are typically ignored.

Definition at line 39 of file goptionvalue.h.

Constructor & Destructor Documentation

◆ OptionValue() [1/2]

G::OptionValue::OptionValue ( )
inline

Default constructor for a valueless value.

Definition at line 90 of file goptionvalue.h.

◆ OptionValue() [2/2]

G::OptionValue::OptionValue ( const std::string &  s,
std::size_t  count = 1U 
)
inlineexplicit

Constructor for a valued value.

Precondition: !s.empty()

Definition at line 97 of file goptionvalue.h.

Member Function Documentation

◆ count()

std::size_t G::OptionValue::count ( ) const
inlinenoexcept

Returns an instance count that is one by default.

Definition at line 160 of file goptionvalue.h.

◆ increment()

void G::OptionValue::increment ( )
inlinenoexcept

Increments the instance count().

Definition at line 166 of file goptionvalue.h.

◆ isOff()

bool G::OptionValue::isOff ( ) const
inlinenoexcept

Returns true if off().

Definition at line 124 of file goptionvalue.h.

◆ isOn()

bool G::OptionValue::isOn ( ) const
inlinenoexcept

Returns true if on().

Definition at line 118 of file goptionvalue.h.

◆ number()

unsigned int G::OptionValue::number ( unsigned int  default_ = 0U) const
inline

Returns value() as an unsigned integer.

Returns the default if not numeric().

Definition at line 154 of file goptionvalue.h.

◆ numeric()

bool G::OptionValue::numeric ( ) const
inlinenoexcept

Returns true if value() is an unsigned integer.

Definition at line 148 of file goptionvalue.h.

◆ off()

G::OptionValue G::OptionValue::off ( )
inlinestatic

A factory function for an unvalued option-disabled option.

Definition at line 110 of file goptionvalue.h.

◆ on()

G::OptionValue G::OptionValue::on ( )
inlinestatic

A factory function for an unvalued option-enabled option.

Definition at line 104 of file goptionvalue.h.

◆ operator==()

bool G::OptionValue::operator== ( std::string_view  s) const
inlinenoexcept

Returns true if the given string matches value().

Definition at line 142 of file goptionvalue.h.

◆ value()

std::string G::OptionValue::value ( ) const
inline

Returns the value as a string.

Definition at line 130 of file goptionvalue.h.

◆ valueref()

std::string_view G::OptionValue::valueref ( ) const
inlinenoexcept

Exposes the value as a string view.

Definition at line 136 of file goptionvalue.h.


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