42 #include <type_traits>
64 operator bool()
const {
return value_; }
66 const std::string &
str()
const
82 operator bool()
const {
return value_; }
84 const std::string &
str()
const
92 class equality_visitor;
103 typedef utils::variant<utils::monostate,
105 int,
unsigned long long, double,
146 bool to_bool(
bool def =
false)
const;
147 int to_int(
int def = 0)
const;
150 std::size_t
to_size_t(std::size_t def = 0)
const;
151 std::time_t
to_time_t(std::time_t def = 0)
const;
153 std::string
str(
const std::string& fallback =
"")
const;
157 operator int()
const {
return to_int(); }
158 operator std::string()
const {
return str(); }
161 explicit operator bool()
const {
return to_bool(); }
176 bool equals(
const std::string&
str)
const;
180 std::enable_if_t<std::is_same_v<const std::string, std::add_const_t<T>>,
bool>
187 std::enable_if_t<std::is_same_v<const char*, T>,
bool>
202 return !(val ==
str);
208 return !(val ==
str);
219 template <
typename V>
222 return utils::visit(visitor,
value_);
231 #ifndef USING_BOOST_VARIANT
233 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.
config_attribute_value & operator=(const config_attribute_value &)
Default implementation, but defined out-of-line for efficiency reasons.
bool equals(const std::string &str) const
Checks for equality of the attribute values when viewed as strings.
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...
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
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
std::enable_if_t< std::is_same_v< const char *, T >, bool > friend operator==(const config_attribute_value &val, T str)
bool blank() const
Tests for an attribute that was never set.
static const std::string s_no
config_attribute_value & operator=(long v)
config_attribute_value & operator=(unsigned long v)
config_attribute_value()
Default implementation, but defined out-of-line for efficiency reasons.
std::enable_if_t< std::is_same_v< const std::string, std::add_const_t< T > >, bool > friend operator==(const config_attribute_value &val, const T &str)
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=(const char *v)
~config_attribute_value()
Default implementation, but defined out-of-line for efficiency reasons.
utils::variant< utils::monostate, true_false, yes_no, int, unsigned long long, double, std::string, t_string > value_type
bool friend operator==(const T &str, const config_attribute_value &val)
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 "".
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....