35 #define ERR_CF LOG_STREAM(err, log_config)
36 #define DBG_CF LOG_STREAM(debug, log_config)
84 return *
this =
static_cast<unsigned long long>(v);
89 return *
this =
static_cast<int>(v);
97 value_ =
static_cast<double>(v);
105 return *
this =
static_cast<int>(v);
117 unsigned long long ull =
static_cast<unsigned long long>(v);
118 if(
static_cast<double>(ull) == v) {
123 int i =
static_cast<int>(v);
124 if(
static_cast<double>(
i) == v) {
144 template<
typename To>
145 bool from_string_verify(
const std::string& source, To& res)
148 std::istringstream in_str(source);
149 if(!(in_str >> res)) {
154 std::ostringstream out_str;
156 return out_str.str() == source;
190 double d = strtod(v.c_str(), &eptr);
197 unsigned long long ull = 0;
198 if(from_string_verify<unsigned long long>(v, ull)) {
204 if(from_string_verify<int>(v,
i)) {
212 std::ostringstream tester;
214 if(tester.str() == v) {
235 return *
this = v.
str();
264 class attribute_numeric_visitor
265 #ifdef USING_BOOST_VARIANT
266 :
public boost::static_visitor<T>
271 attribute_numeric_visitor(T def) : def_(def) {}
273 T operator()(
const utils::monostate&)
const {
return def_; }
274 T operator()(
bool)
const {
return def_; }
275 T operator()(
int i)
const {
return static_cast<T
>(
i); }
276 T operator()(
unsigned long long u)
const {
return static_cast<T
>(u); }
277 T operator()(
double d)
const {
return static_cast<T
>(
d); }
278 T operator()(
const std::string&
s)
const {
return lexical_cast_default<T>(
s, def_); }
279 T operator()(
const t_string&)
const {
return def_; }
293 return apply_visitor(attribute_numeric_visitor<long long>(def));
298 return apply_visitor(attribute_numeric_visitor<unsigned>(def));
303 return apply_visitor(attribute_numeric_visitor<std::size_t>(def));
308 return apply_visitor(attribute_numeric_visitor<std::time_t>(def));
313 return apply_visitor(attribute_numeric_visitor<double>(def));
318 #ifdef USING_BOOST_VARIANT
319 :
public boost::static_visitor<std::string>
331 std::string
operator()(
unsigned long long u)
const {
return std::to_string(u); }
332 std::string
operator()(
double d)
const {
return lexical_cast<std::string>(
d); }
356 return utils::holds_alternative<utils::monostate>(
value_);
368 if(
const std::string*
p = utils::get_if<std::string>(&
value_)) {
377 #ifdef USING_BOOST_VARIANT
378 :
public boost::static_visitor<bool>
383 template<
typename T,
typename U>
399 return bool(lhs) == bool(rhs);
404 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