17 #ifndef AWALI_DYN_OPTIONS_OPTION_HH
18 #define AWALI_DYN_OPTIONS_OPTION_HH
22 #include <unordered_map>
31 namespace awali {
namespace dyn {
namespace internal {
36 virtual bool is_valid(T
const&) {
return true; }
39 return (
"any value of type "
48 virtual bool is_valid(
bool const&) {
return true; }
56 virtual bool is_valid(std::string
const&) {
return true; }
80 const std::string option_name;
83 bool default_set_by_user =
false;
87 , option_name(other.option_name)
88 , acceptor(other.acceptor)
89 , default_value(other.default_set_by_user ? other.def : def)
90 , default_set_by_user(other.was_user_set)
93 template <
typename X,
typename P>
96 throw std::runtime_error(
"Wrong value type for option " + option_name
101 template <
typename X = T,
typename P>
107 template <
typename X = T,
typename P>
110 internal::option_value_pair_t>::type
112 if (
value ==
"default")
113 return {
id, default_value};
116 if (
value ==
"false")
118 throw std::runtime_error(
"Wrong value for option " + option_name
119 +
". Expected a bool, got an std::string, thus expected one of the following values: \"default\", \"true\", \"false\".");
122 template <
typename X = T,
typename P>
123 auto make(std::string
const&
value, priority::THREE<P>)
124 -> decltype(awali::internal::make_enum<X>(
value),
125 internal::option_value_pair_t(
id, default_value))
127 if (
value ==
"default")
128 return {
id, default_value};
129 return {
id, awali::internal::make_enum<X>(
value)};
133 template <
typename P>
134 internal::option_value_pair_t make(
const T&
value, priority::FOUR<P>)
145 , option_name(std::move(name))
150 [
this](std::string
const& val) {
return (*
this) = val; });
159 throw std::runtime_error(
160 "Using option without argument is only possible if they expect "
185 return option_t(*
this, new_default_value);
193 default_value = new_default_value;
194 default_set_by_user =
true;
200 template <
typename X>
value_t of_string(std::string const &str)
Create of value of the type expected by this option_t, from string str.
Definition: option.hh:210
const size_t id
Definition: option.hh:77
option_t(std::string name, T def, acceptor_t< T > acc=acceptor_t< T >())
Definition: option.hh:143
value_t get_default_value()
Definition: option.hh:197
T value_t
Definition: option.hh:76
internal::option_value_pair_t operator=(const X &value)
Definition: option.hh:201
void set_default_value(value_t new_default_value)
Definition: option.hh:191
bool acceptable(T value)
Definition: option.hh:153
option_t< value_t > with_default_value(value_t new_default_value)
Creates a phony option_t that overrides system default value (but not user defined default,...
Definition: option.hh:183
stov_t get_stov(std::string const &)
void register_stov(std::string, stov_t)
size_t next_id
Global variable that assign a unique identifier to each instance of option<T> independentely of type ...
std::function< option_value_pair_t(std::string const &)> stov_t
Definition: option.hh:66
std::string demangle(const char *name)
Definition: demangle.hxx:46
static constexpr TOP< void > value
Definition: priority.hh:93
static constexpr ONE< void > one
Definition: priority.hh:76
Definition: priority.hh:52
pair_automaton< Aut > pair(const Aut &aut, bool keep_initials=false)
Definition: synchronizing_word.hh:266
Main namespace of Awali.
Definition: ato.hh:22
std::string acceptable_values()
Definition: option.hh:49
virtual bool is_valid(bool const &)
Definition: option.hh:48
virtual ~acceptor_t()=default
virtual ~acceptor_t()=default
virtual std::string acceptable_values()
Definition: option.hh:57
virtual bool is_valid(std::string const &)
Definition: option.hh:56
virtual bool is_valid(T const &)
Definition: option.hh:36
virtual std::string acceptable_values()
Definition: option.hh:37
virtual ~acceptor_t()=default