40 #include <type_traits>
61 operator bool()
const {
return value_; }
63 const std::string &
str()
const
79 operator bool()
const {
return value_; }
81 const std::string &
str()
const
89 class equality_visitor;
100 typedef utils::variant<utils::monostate,
102 int,
unsigned long long, double,
140 template<
typename... Args>
151 bool to_bool(
bool def =
false)
const;
152 int to_int(
int def = 0)
const;
155 std::size_t
to_size_t(std::size_t def = 0)
const;
156 std::time_t
to_time_t(std::time_t def = 0)
const;
158 std::string
str(
const std::string& fallback =
"")
const;
165 std::string
to(
const std::string& def)
const {
return str(def); }
168 operator std::string()
const {
return str(); }
185 const bool has_bool =
186 utils::holds_alternative<yes_no>(
value_) ||
187 utils::holds_alternative<true_false>(
value_);
188 return has_bool &&
to_bool() == comp;
194 if constexpr(std::is_convertible_v<T, std::string>) {
199 return utils::holds_alternative<T>(
value_) && this->
to(T{}) == comp;
206 return !val.operator==(
str);
212 return !val.operator==(
str);
223 template <
typename V>
226 return utils::visit(visitor,
value_);
235 #ifndef USING_BOOST_VARIANT
237 inline std::ostream&
operator<<(std::ostream& os,
const std::monostate&) {
return os; }
A wrapper for bool to get the correct streaming ("true"/"false").
true_false(bool value=false)
const std::string & str() const
A wrapper for bool to get the correct streaming ("yes"/"no").
const std::string & str() const
Variant for storing WML attributes.
friend std::ostream & operator<<(std::ostream &os, const true_false &v)
static const std::string s_false
value_type value_
The stored value will always use the first type from the variant definition that can represent it and...
bool operator==(bool comp) const
config_attribute_value & operator=(unsigned v)
std::string str(const std::string &fallback="") const
std::time_t to_time_t(std::time_t def=0) const
std::string to(const std::string &def) const
int to_int(int def=0) const
static const std::string s_true
auto apply_visitor(const V &visitor) const
Visitor support: Applies a visitor to the underlying variant.
unsigned to_unsigned(unsigned def=0) const
static const std::string s_yes
unsigned to(unsigned def) const
bool blank() const
Tests for an attribute that was never set.
static const std::string s_no
bool operator==(const T &comp) const
config_attribute_value & operator=(long v)
config_attribute_value & operator=(unsigned long v)
bool to(const bool def) const
bool friend operator!=(const config_attribute_value &val, const T &str)
bool operator!=(const config_attribute_value &other) const
bool to_bool(bool def=false) const
bool friend operator!=(const T &str, const config_attribute_value &val)
config_attribute_value & operator=(bool v)
static config_attribute_value create(const T val)
config_attribute_value & operator=(const char *v)
utils::variant< utils::monostate, true_false, yes_no, int, unsigned long long, double, std::string, t_string > value_type
double to(double def) const
bool operator==(const config_attribute_value &other) const
Checks for equality of the attribute values when viewed as strings.
void write_if_not_empty(const std::string &v)
Calls operator=(const std::string&) if v is not empty.
bool empty() const
Tests for an attribute that either was never set or was set to "".
config_attribute_value & operator=(const std::chrono::duration< Args... > &v)
friend std::ostream & operator<<(std::ostream &os, const yes_no &v)
long long to_long_long(long long def=0) const
std::size_t to_size_t(std::size_t def=0) const
double to_double(double def=0.) const
std::ostream & operator<<(std::ostream &os, const std::monostate &)
Specialize operator<< for monostate.
std::vector< std::string > split(const config_attribute_value &val)
MacOS doesn't support std::visit when targing MacOS < 10.14 (currently we target 10....