33 #define ERR_CF LOG_STREAM(err, log_config)
34 #define DBG_CF LOG_STREAM(debug, log_config)
58 return *
this =
static_cast<unsigned long long>(v);
61 if(v >= std::numeric_limits<int>::min()) {
63 return *
this =
static_cast<int>(v);
71 value_ =
static_cast<double>(v);
78 if(v <= std::numeric_limits<int>::max()) {
79 return *
this =
static_cast<int>(v);
91 unsigned long long ull =
static_cast<unsigned long long>(v);
92 if(
static_cast<double>(ull) == v) {
97 int i =
static_cast<int>(v);
98 if(
static_cast<double>(
i) == v) {
119 template<
typename TNum>
120 bool str_equals_number(std::string_view str, TNum num)
125 template<
typename To>
126 bool from_string_verify(std::string_view source, To& res)
130 if(ec != std::errc()) {
134 if(ptr != source.data() + source.size()) {
141 return str_equals_number(source, res);
176 if(eptr == v.data() + v.size() && ec == std::errc()) {
182 unsigned long long ull = 0;
183 if(from_string_verify<unsigned long long>(v, ull)) {
189 if(from_string_verify<int>(v,
i)) {
197 if(str_equals_number(v,
d)) {
223 return *
this = v.
str();
259 class attribute_numeric_visitor
260 #ifdef USING_BOOST_VARIANT
261 :
public boost::static_visitor<T>
266 attribute_numeric_visitor(T def) : def_(def) {}
268 T operator()(
const utils::monostate&)
const {
return def_; }
269 T operator()(
bool)
const {
return def_; }
270 T operator()(
int i)
const {
return static_cast<T
>(
i); }
271 T operator()(
unsigned long long u)
const {
return static_cast<T
>(u); }
272 T operator()(
double d)
const {
return static_cast<T
>(
d); }
273 T operator()(
const std::string&
s)
const {
return lexical_cast_default<T>(
s, def_); }
274 T operator()(
const t_string&)
const {
return def_; }
288 return apply_visitor(attribute_numeric_visitor<long long>(def));
293 return apply_visitor(attribute_numeric_visitor<unsigned>(def));
298 return apply_visitor(attribute_numeric_visitor<std::size_t>(def));
303 return apply_visitor(attribute_numeric_visitor<std::time_t>(def));
308 return apply_visitor(attribute_numeric_visitor<double>(def));
313 #ifdef USING_BOOST_VARIANT
314 :
public boost::static_visitor<std::string>
352 return utils::holds_alternative<utils::monostate>(
value_);
364 if(
const std::string*
p = utils::get_if<std::string>(&
value_)) {
373 #ifdef USING_BOOST_VARIANT
374 :
public boost::static_visitor<bool>
379 template<
typename T,
typename U>
395 return bool(lhs) == bool(rhs);
400 return bool(lhs) == bool(rhs);
Visitor handling equality checks.
bool operator()(const yes_no &lhs, const true_false &rhs) const
bool operator()(const T &, const U &) const
bool operator()(const true_false &lhs, const yes_no &rhs) const
bool operator()(const T &lhs, const T &rhs) const
Visitor for converting a variant to a string.
std::string operator()(unsigned long long u) const
std::string operator()(int i) const
const std::string default_
std::string operator()(const utils::monostate &) const
std::string operator()(const t_string &s) const
string_visitor(const std::string &fallback)
std::string operator()(const true_false &b) const
std::string operator()(const yes_no &b) const
std::string operator()(double d) const
std::string operator()(const std::string &s) const
A wrapper for bool to get the correct streaming ("true"/"false").
A wrapper for bool to get the correct streaming ("yes"/"no").
Variant for storing WML attributes.
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::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
bool blank() const
Tests for an attribute that was never set.
static const std::string s_no
bool to_bool(bool def=false) const
config_attribute_value & operator=(bool v)
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 "".
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
bool translatable() const
const std::string & str() const
std::ostream & operator<<(std::ostream &os, const config_attribute_value &v)
static lg::log_domain log_config("config")
Definitions for the interface to Wesnoth Markup Language (WML).
New lexcical_cast header.
Standard logging facilities (interface).
std::enable_if_t< std::is_integral_v< T >, from_chars_result > from_chars(const char *first, const char *last, T &value, int base=10)
std::vector< std::string > split(const config_attribute_value &val)
std::string_view get_view() const
std::string to_string() const
static map_location::direction s