42 #include <type_traits>
46 concept StringLike = std::constructible_from<std::string, T>;
68 operator bool()
const {
return value_; }
70 const std::string &
str()
const
86 operator bool()
const {
return value_; }
88 const std::string &
str()
const
96 class equality_visitor;
107 typedef utils::variant<utils::monostate,
109 int,
unsigned long long, double,
147 template<
typename... Args>
158 bool to_bool(
bool def =
false)
const;
159 int to_int(
int def = 0)
const;
162 std::size_t
to_size_t(std::size_t def = 0)
const;
164 std::string
str(
const std::string& fallback =
"")
const;
171 std::string
to(
const std::string& def)
const {
return str(def); }
174 operator std::string()
const {
return str(); }
189 #ifdef __cpp_concepts
190 bool operator==(
const StringLike
auto& comp)
const
192 return apply_visitor([
this, &comp]<
typename V>(
const V& value) {
193 if constexpr(StringLike<V>) {
194 return value == comp;
196 return *
this ==
create(comp);
202 std::enable_if_t<std::is_constructible_v<std::string, T>,
bool>
206 if constexpr(std::is_constructible_v<std::string, std::decay_t<decltype(value)>>) {
207 return value == comp;
209 return *
this ==
create(comp);
215 std::enable_if_t<std::is_constructible_v<std::string, T>,
bool>
230 template <
typename V>
233 return utils::visit(visitor,
value_);
242 #ifndef USING_BOOST_VARIANT
244 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...
std::enable_if_t< std::is_constructible_v< std::string, T >, bool > operator!=(const T &comp) const
config_attribute_value & operator=(unsigned v)
std::string str(const std::string &fallback="") 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
config_attribute_value & operator=(long v)
config_attribute_value & operator=(unsigned long v)
bool to(const bool def) const
bool operator!=(const config_attribute_value &other) const
bool to_bool(bool def=false) const
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)
std::enable_if_t< std::is_constructible_v< std::string, T >, bool > operator==(const T &comp) const
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....