Public Types | Public Member Functions | Static Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | List of all members
util::details::MultipleChoiceSelectionOption_t< Choices > Class Template Reference

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::stringvalue_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::stringfLabels
 All the labels. More...
 

Detailed Description

template<typename Choices>
class util::details::MultipleChoiceSelectionOption_t< Choices >

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.

Member Typedef Documentation

template<typename Choices>
using util::details::MultipleChoiceSelectionOption_t< Choices >::Choices_t = Choices

Definition at line 78 of file MultipleChoiceSelection.h.

template<typename Choices>
using util::details::MultipleChoiceSelectionOption_t< Choices >::Comparer_t = CaseInsensitiveComparer
private

Definition at line 75 of file MultipleChoiceSelection.h.

Definition at line 79 of file MultipleChoiceSelection.h.

Constructor & Destructor Documentation

template<typename Choices >
template<typename... Aliases>
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.

637  : fValue(value)
638 {
639  fLabels.reserve(1U + sizeof...(aliases));
640  addAlias(std::move(name), std::move(aliases)...);
641 } // util::details::MultipleChoiceSelectionOption_t<>::MultipleChoiceSelectionOption_t
std::enable_if_t< AllConvertibleToStrings_v< Aliases... >, Option_t & > addAlias(std::string alias, Aliases...moreAliases)
Adds aliases.
Choices_t fValue
The value associated to the option.
std::vector< std::string > fLabels
All the labels.
def move(depos, offset)
Definition: depos.py:107
std::string name() const
Returns the name of the option (i.e. the main label).
Choices_t value() const
Returns a copy of the value of the option.

Member Function Documentation

template<typename Choices>
template<typename... Aliases>
std::enable_if_t<AllConvertibleToStrings_v<Aliases...>, Option_t&> util::details::MultipleChoiceSelectionOption_t< Choices >::addAlias ( std::string  alias,
Aliases...  moreAliases 
)

Adds aliases.

template<typename Choices>
template<typename... 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.

650 {
651  fLabels.push_back(std::move(alias));
652  if constexpr(sizeof...(moreAliases) > 0)
653  return addAlias(std::move(moreAliases)...);
654  else return *this;
655 } // util::details::MultipleChoiceSelectionOption_t<>::addAlias()
std::enable_if_t< AllConvertibleToStrings_v< Aliases... >, Option_t & > addAlias(std::string alias, Aliases...moreAliases)
Adds aliases.
STL namespace.
std::vector< std::string > fLabels
All the labels.
def move(depos, offset)
Definition: depos.py:107
template<typename Choices >
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.

709 {
710  auto iLabel = fLabels.begin();
711  auto const lend = fLabels.end();
712  std::string s { '"' };
713  s += *iLabel;
714  s += '"';
715  auto const valueStr = value_as_string();
716  if (valueStr != *iLabel) {
717  s += " [=";
718  s += valueStr;
719  s += "]";
720  }
721  if (++iLabel != lend) {
722  s += " (aliases: \"";
723  s += *iLabel;
724  s += '"';
725  while (++iLabel != lend) {
726  s += " \"";
727  s += *iLabel;
728  s += '"';
729  } // while
730  s += ')';
731  } // if aliases
732 
733  return s;
734 } // util::details::MultipleChoiceSelectionOption_t<>::dump()
std::string string
Definition: nybbler.cc:12
std::vector< std::string > fLabels
All the labels.
static QCString * s
Definition: config.cpp:1042
template<typename Choices>
static bool util::details::MultipleChoiceSelectionOption_t< Choices >::equal ( std::string const &  a,
std::string const &  b 
)
inlinestaticprivate

Definition at line 145 of file MultipleChoiceSelection.h.

146  { return Comparer_t::equal(a, b); }
const double a
static bool * b
Definition: config.cpp:1043
static bool equal(std::string const &a, std::string const &b)
Returns whether strings a and b are equal.
template<typename Choices>
std::vector<std::string> const& util::details::MultipleChoiceSelectionOption_t< Choices >::labels ( ) const
inline

Returns an iterable object with all the labels of the option.

Definition at line 102 of file MultipleChoiceSelection.h.

102 { return fLabels; }
std::vector< std::string > fLabels
All the labels.
template<typename Choices >
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.

662 {
663  return std::find_if(
664  fLabels.begin(), fLabels.end(),
665  [&label](std::string const& alias){ return equal(label, alias); }
666  ) != fLabels.end();
667 } // util::details::MultipleChoiceSelectionOption_t<>::match()
std::string string
Definition: nybbler.cc:12
std::vector< std::string > fLabels
All the labels.
static bool equal(std::string const &a, std::string const &b)
template<typename Choices>
std::string util::details::MultipleChoiceSelectionOption_t< Choices >::name ( ) const
inline

Returns the name of the option (i.e. the main label).

Definition at line 99 of file MultipleChoiceSelection.h.

99 { return labels().front(); }
std::vector< std::string > const & labels() const
Returns an iterable object with all the labels of the option.
template<typename Choices>
util::details::MultipleChoiceSelectionOption_t< Choices >::operator Choices_t ( ) const
inline

Returns the value of this option.

Definition at line 109 of file MultipleChoiceSelection.h.

109 { return value(); }
Choices_t value() const
Returns a copy of the value of the option.
template<typename Choices>
util::details::MultipleChoiceSelectionOption_t< Choices >::operator std::string ( ) const
inline

Returns a string representing this option.

Definition at line 106 of file MultipleChoiceSelection.h.

106 { return name(); }
std::string name() const
Returns the name of the option (i.e. the main label).
template<typename Choices>
bool util::details::MultipleChoiceSelectionOption_t< Choices >::operator!= ( Option_t const &  option) const
inline

Returns whether the two options are not the same.

Definition at line 128 of file MultipleChoiceSelection.h.

129  { return (value() != option.value()) || !equal(name(), option.name()); }
std::string name() const
Returns the name of the option (i.e. the main label).
static bool equal(std::string const &a, std::string const &b)
Choices_t value() const
Returns a copy of the value of the option.
template<typename Choices>
bool util::details::MultipleChoiceSelectionOption_t< Choices >::operator== ( Option_t const &  option) const
inline

Returns whether the two options are the same (same value and name).

Definition at line 124 of file MultipleChoiceSelection.h.

125  { return (value() == option.value()) && equal(name(), option.name()); }
std::string name() const
Returns the name of the option (i.e. the main label).
static bool equal(std::string const &a, std::string const &b)
Choices_t value() const
Returns a copy of the value of the option.
template<typename Choices>
Choices_t util::details::MultipleChoiceSelectionOption_t< Choices >::value ( ) const
inline

Returns a copy of the value of the option.

Definition at line 96 of file MultipleChoiceSelection.h.

96 { return fValue; }
Choices_t fValue
The value associated to the option.
template<typename Choices >
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.

682  { return value_as_string(name()); }
std::string name() const
Returns the name of the option (i.e. the main label).
template<typename Choices >
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.

675  { return value_as_string(value(), defValue); }
Choices_t value() const
Returns a copy of the value of the option.
template<typename Choices >
std::optional< std::string > util::details::MultipleChoiceSelectionOption_t< Choices >::value_as_string ( Choices_t  value)
static

Converts a value of type Choices_t into a string, if possible.

Definition at line 689 of file MultipleChoiceSelection.h.

690 {
691  return details::ValueToString<std::decay_t<Choices_t>>::convert(value);
692 } // util::details::MultipleChoiceSelectionOption_t<>::value_as_string()
def convert(inputfile, outputfile="wire-cell-garfield-fine-response.json.bz2", average=False, shaped=False)
Definition: garfield.py:262
Choices_t value() const
Returns a copy of the value of the option.
template<typename Choices >
std::string util::details::MultipleChoiceSelectionOption_t< Choices >::value_as_string ( Choices_t  value,
std::string const &  defValue 
)
static

Converts a value of type Choices_t into a string, if possible.

Definition at line 699 of file MultipleChoiceSelection.h.

700 {
701  return value_as_string(value).value_or(defValue);
702 } // util::details::MultipleChoiceSelectionOption_t<>::value_as_string()
Choices_t value() const
Returns a copy of the value of the option.

Member Data Documentation

template<typename Choices>
std::vector<std::string> util::details::MultipleChoiceSelectionOption_t< Choices >::fLabels
private

All the labels.

Definition at line 143 of file MultipleChoiceSelection.h.

template<typename Choices>
Choices_t util::details::MultipleChoiceSelectionOption_t< Choices >::fValue
private

The value associated to the option.

Definition at line 142 of file MultipleChoiceSelection.h.


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