Class representing one of the available options to be selected. More...
#include <MultipleChoiceSelection.h>
Public Types | |
using | Choices_t = Choices |
using | Option_t = MultipleChoiceSelectionOption_t< Choices_t > |
Public Member Functions | |
template<typename... Aliases> | |
MultipleChoiceSelectionOption_t (Choices_t value, std::string name, Aliases...aliases) | |
Constructor: assigns value, name and aliases. More... | |
template<typename... Aliases> | |
std::enable_if_t< AllConvertibleToStrings_v< Aliases... >, Option_t & > | addAlias (std::string alias, Aliases...moreAliases) |
Adds aliases. More... | |
bool | match (std::string const &label) const |
Returns whether this option matches the specified label (name or alias). More... | |
Choices_t | value () const |
Returns a copy of the value of the option. More... | |
std::string | name () const |
Returns the name of the option (i.e. the main label). More... | |
std::vector< std::string > const & | labels () const |
Returns an iterable object with all the labels of the option. More... | |
operator std::string () const | |
Returns a string representing this option. More... | |
operator Choices_t () const | |
Returns the value of this option. More... | |
std::string | value_as_string () const |
std::string | value_as_string (std::string const &defValue) const |
Returns a string represent the value of the option, or defValue . More... | |
std::string | dump () const |
Returns in a string the name and all the aliases. More... | |
bool | operator== (Option_t const &option) const |
Returns whether the two options are the same (same value and name). More... | |
bool | operator!= (Option_t const &option) const |
Returns whether the two options are not the same. More... | |
template<typename... Aliases> | |
auto | addAlias (std::string alias, Aliases...moreAliases) -> std::enable_if_t< AllConvertibleToStrings_v< Aliases... >, Option_t & > |
Static Public Member Functions | |
static std::optional< std::string > | value_as_string (Choices_t value) |
Converts a value of type Choices_t into a string, if possible. More... | |
static std::string | value_as_string (Choices_t value, std::string const &defValue) |
Converts a value of type Choices_t into a string, if possible. More... | |
Private Types | |
using | Comparer_t = CaseInsensitiveComparer |
Static Private Member Functions | |
static bool | equal (std::string const &a, std::string const &b) |
Private Attributes | |
Choices_t | fValue |
The value associated to the option. More... | |
std::vector< std::string > | fLabels |
All the labels. More... | |
Class representing one of the available options to be selected.
An option has a value (of type Choices_t
) and a name as a string. It may also have aliases. The identity of the option is defined by the value: two option objects with the same value represent the same option.
Matching a label is encoded in this class: the option matches a label if its name or any of its aliases matches the proposed label in a case-insensitive comparison.
Definition at line 73 of file MultipleChoiceSelection.h.
using util::details::MultipleChoiceSelectionOption_t< Choices >::Choices_t = Choices |
Definition at line 78 of file MultipleChoiceSelection.h.
|
private |
Definition at line 75 of file MultipleChoiceSelection.h.
using util::details::MultipleChoiceSelectionOption_t< Choices >::Option_t = MultipleChoiceSelectionOption_t<Choices_t> |
Definition at line 79 of file MultipleChoiceSelection.h.
util::details::MultipleChoiceSelectionOption_t< Choices >::MultipleChoiceSelectionOption_t | ( | Choices_t | value, |
std::string | name, | ||
Aliases... | aliases | ||
) |
Constructor: assigns value, name and aliases.
Definition at line 636 of file MultipleChoiceSelection.h.
std::enable_if_t<AllConvertibleToStrings_v<Aliases...>, Option_t&> util::details::MultipleChoiceSelectionOption_t< Choices >::addAlias | ( | std::string | alias, |
Aliases... | moreAliases | ||
) |
Adds aliases.
auto util::details::MultipleChoiceSelectionOption_t< Choices >::addAlias | ( | std::string | alias, |
Aliases... | moreAliases | ||
) | -> std::enable_if_t<AllConvertibleToStrings_v<Aliases...>, Option_t&> |
Definition at line 648 of file MultipleChoiceSelection.h.
std::string util::details::MultipleChoiceSelectionOption_t< Choices >::dump | ( | ) | const |
Returns in a string the name and all the aliases.
Definition at line 707 of file MultipleChoiceSelection.h.
|
inlinestaticprivate |
Definition at line 145 of file MultipleChoiceSelection.h.
|
inline |
Returns an iterable object with all the labels of the option.
Definition at line 102 of file MultipleChoiceSelection.h.
bool util::details::MultipleChoiceSelectionOption_t< Choices >::match | ( | std::string const & | label | ) | const |
Returns whether this option matches the specified label (name or alias).
Definition at line 661 of file MultipleChoiceSelection.h.
|
inline |
Returns the name of the option (i.e. the main label).
Definition at line 99 of file MultipleChoiceSelection.h.
|
inline |
Returns the value of this option.
Definition at line 109 of file MultipleChoiceSelection.h.
|
inline |
Returns a string representing this option.
Definition at line 106 of file MultipleChoiceSelection.h.
|
inline |
Returns whether the two options are not the same.
Definition at line 128 of file MultipleChoiceSelection.h.
|
inline |
Returns whether the two options are the same (same value and name).
Definition at line 124 of file MultipleChoiceSelection.h.
|
inline |
Returns a copy of the value of the option.
Definition at line 96 of file MultipleChoiceSelection.h.
std::string util::details::MultipleChoiceSelectionOption_t< Choices >::value_as_string | ( | ) | const |
Returns a string representing the value of the option.
That will be the name()
of the option if the value is not convertible to a string.
Definition at line 681 of file MultipleChoiceSelection.h.
std::string util::details::MultipleChoiceSelectionOption_t< Choices >::value_as_string | ( | std::string const & | defValue | ) | const |
Returns a string represent the value of the option, or defValue
.
Definition at line 674 of file MultipleChoiceSelection.h.
|
static |
Converts a value of type Choices_t
into a string, if possible.
Definition at line 689 of file MultipleChoiceSelection.h.
|
static |
Converts a value of type Choices_t
into a string, if possible.
Definition at line 699 of file MultipleChoiceSelection.h.
|
private |
All the labels.
Definition at line 143 of file MultipleChoiceSelection.h.
|
private |
The value associated to the option.
Definition at line 142 of file MultipleChoiceSelection.h.