The Battle for Wesnoth  1.19.5+dev
Classes | Public Member Functions | Private Types | Private Attributes | Static Private Attributes | Friends | List of all members
config_attribute_value Class Reference

Variant for storing WML attributes. More...

#include <config_attribute_value.hpp>

Classes

class  equality_visitor
 Visitor handling equality checks. More...
 
class  string_visitor
 Visitor for converting a variant to a string. More...
 
class  true_false
 A wrapper for bool to get the correct streaming ("true"/"false"). More...
 
class  yes_no
 A wrapper for bool to get the correct streaming ("yes"/"no"). More...
 

Public Member Functions

config_attribute_valueoperator= (bool v)
 
config_attribute_valueoperator= (int v)
 
config_attribute_valueoperator= (long v)
 
config_attribute_valueoperator= (long long v)
 
config_attribute_valueoperator= (unsigned v)
 
config_attribute_valueoperator= (unsigned long v)
 
config_attribute_valueoperator= (unsigned long long v)
 
config_attribute_valueoperator= (double v)
 
config_attribute_valueoperator= (const char *v)
 
config_attribute_valueoperator= (std::string &&v)
 
config_attribute_valueoperator= (const std::string &v)
 
config_attribute_valueoperator= (const std::string_view &v)
 
config_attribute_valueoperator= (const t_string &v)
 
template<typename... Args>
config_attribute_valueoperator= (const std::chrono::duration< Args... > &v)
 
void write_if_not_empty (const std::string &v)
 Calls operator=(const std::string&) if v is not empty. More...
 
void write_if_not_empty (const t_string &v)
 
bool to_bool (bool def=false) const
 
int to_int (int def=0) const
 
long long to_long_long (long long def=0) const
 
unsigned to_unsigned (unsigned def=0) const
 
std::size_t to_size_t (std::size_t def=0) const
 
std::time_t to_time_t (std::time_t def=0) const
 
double to_double (double def=0.) const
 
std::string str (const std::string &fallback="") const
 
t_string t_str () const
 
bool to (const bool def) const
 
int to (int def) const
 
unsigned to (unsigned def) const
 
double to (double def) const
 
std::string to (const std::string &def) const
 
 operator std::string () const
 
 operator t_string () const
 
bool blank () const
 Tests for an attribute that was never set. More...
 
bool empty () const
 Tests for an attribute that either was never set or was set to "". More...
 
bool operator== (const config_attribute_value &other) const
 Checks for equality of the attribute values when viewed as strings. More...
 
bool operator!= (const config_attribute_value &other) const
 
bool operator== (bool comp) const
 
template<typename T >
bool operator== (const T &comp) const
 
template<typename T >
bool friend operator!= (const config_attribute_value &val, const T &str)
 
template<typename T >
bool friend operator!= (const T &str, const config_attribute_value &val)
 
template<typename V >
auto apply_visitor (const V &visitor) const
 Visitor support: Applies a visitor to the underlying variant. More...
 

Private Types

typedef utils::variant< utils::monostate, true_false, yes_no, int, unsigned long long, double, std::string, t_stringvalue_type
 

Private Attributes

value_type value_
 The stored value will always use the first type from the variant definition that can represent it and that can be streamed to the correct string representation (if applicable). More...
 

Static Private Attributes

static const std::string s_yes
 
static const std::string s_no
 
static const std::string s_true
 
static const std::string s_false
 

Friends

std::ostream & operator<< (std::ostream &os, const true_false &v)
 
std::ostream & operator<< (std::ostream &os, const yes_no &v)
 
std::ostream & operator<< (std::ostream &os, const config_attribute_value &v)
 

Detailed Description

Variant for storing WML attributes.

The most efficient type is used when assigning a value. For instance, strings "yes", "no", "true", "false" will be detected and stored as boolean.

Note
The blank variant is only used when querying missing attributes. It is not stored in config objects.

Definition at line 49 of file config_attribute_value.hpp.

Member Typedef Documentation

◆ value_type

typedef utils::variant<utils::monostate, true_false, yes_no, int, unsigned long long, double, std::string, t_string > config_attribute_value::value_type
private

Definition at line 104 of file config_attribute_value.hpp.

Member Function Documentation

◆ apply_visitor()

template<typename V >
auto config_attribute_value::apply_visitor ( const V &  visitor) const
inline

◆ blank()

bool config_attribute_value::blank ( ) const

◆ empty()

bool config_attribute_value::empty ( ) const

◆ operator std::string()

config_attribute_value::operator std::string ( ) const
inline

Definition at line 159 of file config_attribute_value.hpp.

References str().

◆ operator t_string()

config_attribute_value::operator t_string ( ) const
inline

Definition at line 160 of file config_attribute_value.hpp.

References t_str().

◆ operator!=() [1/3]

bool config_attribute_value::operator!= ( const config_attribute_value other) const
inline

Definition at line 169 of file config_attribute_value.hpp.

References operator==().

◆ operator!=() [2/3]

template<typename T >
bool friend config_attribute_value::operator!= ( const config_attribute_value val,
const T &  str 
)
inline

Definition at line 195 of file config_attribute_value.hpp.

References str().

◆ operator!=() [3/3]

template<typename T >
bool friend config_attribute_value::operator!= ( const T &  str,
const config_attribute_value val 
)
inline

Definition at line 201 of file config_attribute_value.hpp.

References str().

◆ operator=() [1/14]

config_attribute_value & config_attribute_value::operator= ( bool  v)

Definition at line 40 of file config_attribute_value.cpp.

References value_.

Referenced by operator=().

◆ operator=() [2/14]

config_attribute_value& config_attribute_value::operator= ( const char *  v)
inline

Definition at line 125 of file config_attribute_value.hpp.

References operator=().

Referenced by operator=().

◆ operator=() [3/14]

template<typename... Args>
config_attribute_value& config_attribute_value::operator= ( const std::chrono::duration< Args... > &  v)
inline

Definition at line 132 of file config_attribute_value.hpp.

References operator=().

◆ operator=() [4/14]

config_attribute_value & config_attribute_value::operator= ( const std::string &  v)

Definition at line 197 of file config_attribute_value.cpp.

References operator=().

◆ operator=() [5/14]

config_attribute_value & config_attribute_value::operator= ( const std::string_view &  v)

Definition at line 202 of file config_attribute_value.cpp.

References operator=().

◆ operator=() [6/14]

config_attribute_value & config_attribute_value::operator= ( const t_string v)

Definition at line 209 of file config_attribute_value.cpp.

References t_string::str(), t_string::translatable(), and value_.

◆ operator=() [7/14]

config_attribute_value & config_attribute_value::operator= ( double  v)

Definition at line 84 of file config_attribute_value.cpp.

References i, and value_.

◆ operator=() [8/14]

config_attribute_value & config_attribute_value::operator= ( int  v)

Definition at line 46 of file config_attribute_value.cpp.

References value_.

◆ operator=() [9/14]

config_attribute_value & config_attribute_value::operator= ( long long  v)

Definition at line 52 of file config_attribute_value.cpp.

References value_.

◆ operator=() [10/14]

config_attribute_value& config_attribute_value::operator= ( long  v)
inline

Definition at line 117 of file config_attribute_value.hpp.

References operator=().

Referenced by operator=().

◆ operator=() [11/14]

config_attribute_value & config_attribute_value::operator= ( std::string &&  v)

Definition at line 132 of file config_attribute_value.cpp.

References d, i, s_false, s_no, s_true, s_yes, and value_.

◆ operator=() [12/14]

config_attribute_value & config_attribute_value::operator= ( unsigned long long  v)

Definition at line 73 of file config_attribute_value.cpp.

References value_.

◆ operator=() [13/14]

config_attribute_value& config_attribute_value::operator= ( unsigned long  v)
inline

Definition at line 120 of file config_attribute_value.hpp.

References operator=().

Referenced by operator=().

◆ operator=() [14/14]

config_attribute_value& config_attribute_value::operator= ( unsigned  v)
inline

Definition at line 119 of file config_attribute_value.hpp.

References operator=().

Referenced by operator=().

◆ operator==() [1/3]

bool config_attribute_value::operator== ( bool  comp) const
inline

Definition at line 174 of file config_attribute_value.hpp.

References to_bool(), and value_.

◆ operator==() [2/3]

bool config_attribute_value::operator== ( const config_attribute_value other) const

Checks for equality of the attribute values when viewed as strings.

Exception: Boolean synonyms can be equal ("yes" == "true"). Note: Blanks have no string representation, so do not equal "" (an empty string).

Definition at line 397 of file config_attribute_value.cpp.

References value_.

Referenced by operator!=().

◆ operator==() [3/3]

template<typename T >
bool config_attribute_value::operator== ( const T &  comp) const
inline

Definition at line 183 of file config_attribute_value.hpp.

References to(), and value_.

◆ str()

std::string config_attribute_value::str ( const std::string &  fallback = "") const

◆ t_str()

t_string config_attribute_value::t_str ( ) const

◆ to() [1/5]

bool config_attribute_value::to ( const bool  def) const
inline

Definition at line 152 of file config_attribute_value.hpp.

References to_bool().

Referenced by operator==().

◆ to() [2/5]

std::string config_attribute_value::to ( const std::string &  def) const
inline

Definition at line 156 of file config_attribute_value.hpp.

References str().

◆ to() [3/5]

double config_attribute_value::to ( double  def) const
inline

Definition at line 155 of file config_attribute_value.hpp.

References to_double().

◆ to() [4/5]

int config_attribute_value::to ( int  def) const
inline

Definition at line 153 of file config_attribute_value.hpp.

References to_int().

◆ to() [5/5]

unsigned config_attribute_value::to ( unsigned  def) const
inline

Definition at line 154 of file config_attribute_value.hpp.

References to_unsigned().

◆ to_bool()

bool config_attribute_value::to_bool ( bool  def = false) const

◆ to_double()

double config_attribute_value::to_double ( double  def = 0.) const

Definition at line 295 of file config_attribute_value.cpp.

References apply_visitor().

Referenced by to().

◆ to_int()

int config_attribute_value::to_int ( int  def = 0) const

◆ to_long_long()

long long config_attribute_value::to_long_long ( long long  def = 0) const

Definition at line 275 of file config_attribute_value.cpp.

References apply_visitor().

Referenced by chrono::parse_timestamp().

◆ to_size_t()

std::size_t config_attribute_value::to_size_t ( std::size_t  def = 0) const

Definition at line 285 of file config_attribute_value.cpp.

References apply_visitor().

◆ to_time_t()

std::time_t config_attribute_value::to_time_t ( std::time_t  def = 0) const

Definition at line 290 of file config_attribute_value.cpp.

References apply_visitor().

Referenced by savegame::save_index_class::get().

◆ to_unsigned()

unsigned config_attribute_value::to_unsigned ( unsigned  def = 0) const

Definition at line 280 of file config_attribute_value.cpp.

References apply_visitor().

Referenced by to().

◆ write_if_not_empty() [1/2]

void config_attribute_value::write_if_not_empty ( const std::string &  v)

Calls operator=(const std::string&) if v is not empty.

Definition at line 219 of file config_attribute_value.cpp.

◆ write_if_not_empty() [2/2]

void config_attribute_value::write_if_not_empty ( const t_string v)

Definition at line 226 of file config_attribute_value.cpp.

References t_string::empty().

Friends And Related Function Documentation

◆ operator<< [1/3]

std::ostream& operator<< ( std::ostream &  os,
const config_attribute_value v 
)
friend

Definition at line 402 of file config_attribute_value.cpp.

◆ operator<< [2/3]

std::ostream& operator<< ( std::ostream &  os,
const true_false v 
)
friend

Definition at line 68 of file config_attribute_value.hpp.

◆ operator<< [3/3]

std::ostream& operator<< ( std::ostream &  os,
const yes_no v 
)
friend

Definition at line 86 of file config_attribute_value.hpp.

Member Data Documentation

◆ s_false

const std::string config_attribute_value::s_false
staticprivate

◆ s_no

const std::string config_attribute_value::s_no
staticprivate

Definition at line 222 of file config_attribute_value.hpp.

Referenced by operator=(), and config_attribute_value::yes_no::str().

◆ s_true

const std::string config_attribute_value::s_true
staticprivate

◆ s_yes

const std::string config_attribute_value::s_yes
staticprivate

Definition at line 222 of file config_attribute_value.hpp.

Referenced by operator=(), and config_attribute_value::yes_no::str().

◆ value_

value_type config_attribute_value::value_
private

The stored value will always use the first type from the variant definition that can represent it and that can be streamed to the correct string representation (if applicable).

This is enforced upon assignment.

Definition at line 111 of file config_attribute_value.hpp.

Referenced by apply_visitor(), blank(), empty(), operator=(), operator==(), t_str(), and to_bool().


The documentation for this class was generated from the following files: