31 #define ERR_CF LOG_STREAM(err, log_config)
32 #define DBG_CF LOG_STREAM(debug, log_config)
80 return *
this =
static_cast<unsigned long long>(v);
85 return *
this =
static_cast<int>(v);
93 value_ =
static_cast<double>(v);
101 return *
this =
static_cast<int>(v);
113 unsigned long long ull =
static_cast<unsigned long long>(v);
114 if(
static_cast<double>(ull) == v) {
119 int i =
static_cast<int>(v);
120 if(
static_cast<double>(
i) == v) {
140 template<
typename To>
141 bool from_string_verify(
const std::string& source, To& res)
144 std::istringstream in_str(source);
145 if(!(in_str >> res)) {
150 std::ostringstream out_str;
152 return out_str.str() == source;
186 double d = strtod(v.c_str(), &eptr);
193 unsigned long long ull = 0;
194 if(from_string_verify<unsigned long long>(v, ull)) {
200 if(from_string_verify<int>(v,
i)) {
208 std::ostringstream tester;
210 if(tester.str() == v) {
231 return *
this = v.
str();
267 class attribute_numeric_visitor
268 #ifdef USING_BOOST_VARIANT
269 :
public boost::static_visitor<T>
274 attribute_numeric_visitor(T def) : def_(def) {}
276 T operator()(
const utils::monostate&)
const {
return def_; }
277 T operator()(
bool)
const {
return def_; }
278 T operator()(
int i)
const {
return static_cast<T
>(
i); }
279 T operator()(
unsigned long long u)
const {
return static_cast<T
>(u); }
280 T operator()(
double d)
const {
return static_cast<T
>(
d); }
281 T operator()(
const std::string&
s)
const {
return lexical_cast_default<T>(
s, def_); }
282 T operator()(
const t_string&)
const {
return def_; }
296 return apply_visitor(attribute_numeric_visitor<long long>(def));
301 return apply_visitor(attribute_numeric_visitor<unsigned>(def));
306 return apply_visitor(attribute_numeric_visitor<std::size_t>(def));
311 return apply_visitor(attribute_numeric_visitor<std::time_t>(def));
316 return apply_visitor(attribute_numeric_visitor<double>(def));
321 #ifdef USING_BOOST_VARIANT
322 :
public boost::static_visitor<std::string>
334 std::string
operator()(
unsigned long long u)
const {
return std::to_string(u); }
335 std::string
operator()(
double d)
const {
return lexical_cast<std::string>(
d); }
359 return utils::holds_alternative<utils::monostate>(
value_);
371 if(
const std::string*
p = utils::get_if<std::string>(&
value_)) {
380 #ifdef USING_BOOST_VARIANT
381 :
public boost::static_visitor<bool>
386 template<
typename T,
typename U>
402 return bool(lhs) == bool(rhs);
407 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.
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.
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
config_attribute_value()
Default implementation, but defined out-of-line for efficiency reasons.
bool to_bool(bool def=false) const
~config_attribute_value()
Default implementation, but defined out-of-line for efficiency reasons.
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::vector< std::string > split(const config_attribute_value &val)
static map_location::DIRECTION s