The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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_value ()
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
 ~config_attribute_value ()
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
 config_attribute_value (const config_attribute_value &)
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
config_attribute_valueoperator= (const config_attribute_value &)
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
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= (const std::string &v)
 
config_attribute_valueoperator= (const t_string &v)
 
template<typename T >
utils::enable_if_t
< std::is_base_of< enum_tag, T >
::value,
config_attribute_value & > 
operator= (const T &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
 
size_t to_size_t (size_t def=0) const
 
time_t to_time_t (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
 
template<typename T >
utils::enable_if_t
< std::is_base_of< enum_tag, T >
::value, T > 
to_enum (const T &v) const
 
 operator int () 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 equals (const std::string &str) const
 Checks for equality of the attribute values when viewed as strings. More...
 
template<typename T >
utils::enable_if_t
< std::is_same< const
std::string,
utils::add_const_t< T >
>::value, bool > friend 
operator== (const config_attribute_value &val, const T &str)
 
template<typename T >
utils::enable_if_t
< std::is_same< const char
*, T >::value, bool > friend 
operator== (const config_attribute_value &val, T str)
 
template<typename T >
bool friend operator== (const T &str, const config_attribute_value &val)
 
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 >
V::result_type apply_visitor (const V &visitor) const
 Applies a visitor to the underlying variant. More...
 

Private Types

typedef boost::variant
< boost::blank, true_false,
yes_no, int, unsigned long
long, double, std::string,
t_string
value_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 93 of file config_attribute_value.hpp.

Member Typedef Documentation

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

Definition at line 131 of file config_attribute_value.hpp.

Constructor & Destructor Documentation

config_attribute_value::config_attribute_value ( )

Default implementation, but defined out-of-line for efficiency reasons.

Definition at line 49 of file config_attribute_value.cpp.

config_attribute_value::~config_attribute_value ( )

Default implementation, but defined out-of-line for efficiency reasons.

Definition at line 55 of file config_attribute_value.cpp.

config_attribute_value::config_attribute_value ( const config_attribute_value that)

Default implementation, but defined out-of-line for efficiency reasons.

Definition at line 60 of file config_attribute_value.cpp.

Member Function Documentation

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

Applies a visitor to the underlying variant.

(See the documentation for Boost.Variant.)

Definition at line 261 of file config_attribute_value.hpp.

References variable_info_implementation::apply_visitor().

Referenced by unit_filter_impl::unit_filter_compound::create_attribute(), vconfig::expand(), luaW_pushscalar(), str(), to_double(), to_int(), to_long_long(), to_size_t(), to_time_t(), to_unsigned(), and write_key_val().

bool config_attribute_value::blank ( ) const
bool config_attribute_value::empty ( ) const
bool config_attribute_value::equals ( const std::string &  str) 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). Also note that translatable string are never equal to non translatable strings.

Definition at line 404 of file config_attribute_value.cpp.

References str().

Referenced by operator==().

config_attribute_value::operator int ( ) const
inline

Definition at line 202 of file config_attribute_value.hpp.

References to_int().

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

Definition at line 203 of file config_attribute_value.hpp.

References str().

config_attribute_value::operator t_string ( ) const
inline

Definition at line 204 of file config_attribute_value.hpp.

References t_str().

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

Definition at line 214 of file config_attribute_value.hpp.

References operator==().

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

Definition at line 243 of file config_attribute_value.hpp.

References str().

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

Definition at line 249 of file config_attribute_value.hpp.

References str().

config_attribute_value & config_attribute_value::operator= ( const config_attribute_value that)

Default implementation, but defined out-of-line for efficiency reasons.

Definition at line 66 of file config_attribute_value.cpp.

References value_.

Referenced by operator=().

config_attribute_value & config_attribute_value::operator= ( bool  v)

Definition at line 72 of file config_attribute_value.cpp.

References value_.

config_attribute_value & config_attribute_value::operator= ( int  v)

Definition at line 78 of file config_attribute_value.cpp.

References value_.

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

Definition at line 164 of file config_attribute_value.hpp.

References operator=().

Referenced by operator=().

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

Definition at line 84 of file config_attribute_value.cpp.

References value_.

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

Definition at line 166 of file config_attribute_value.hpp.

References operator=().

Referenced by operator=().

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

Definition at line 167 of file config_attribute_value.hpp.

References operator=().

Referenced by operator=().

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

Definition at line 105 of file config_attribute_value.cpp.

References value_.

config_attribute_value & config_attribute_value::operator= ( double  v)

Definition at line 116 of file config_attribute_value.cpp.

References i, and value_.

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

Definition at line 172 of file config_attribute_value.hpp.

References operator=().

Referenced by operator=().

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

Definition at line 163 of file config_attribute_value.cpp.

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

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

Definition at line 228 of file config_attribute_value.cpp.

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

template<typename T >
utils::enable_if_t<std::is_base_of<enum_tag, T>::value, config_attribute_value&> config_attribute_value::operator= ( const T &  v)
inline

Definition at line 176 of file config_attribute_value.hpp.

References operator=().

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 393 of file config_attribute_value.cpp.

References variable_info_implementation::apply_visitor(), and value_.

Referenced by operator!=().

template<typename T >
utils::enable_if_t<std::is_same<const std::string, utils::add_const_t<T> >::value, bool> friend config_attribute_value::operator== ( const config_attribute_value val,
const T &  str 
)
inline

Definition at line 224 of file config_attribute_value.hpp.

References equals().

template<typename T >
utils::enable_if_t<std::is_same<const char*, T>::value, bool> friend config_attribute_value::operator== ( const config_attribute_value val,
str 
)
inline

Definition at line 231 of file config_attribute_value.hpp.

References equals().

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

Definition at line 237 of file config_attribute_value.hpp.

References str().

std::string config_attribute_value::str ( const std::string &  fallback = "") const
t_string config_attribute_value::t_str ( ) const
bool config_attribute_value::to_bool ( bool  def = false) const
double config_attribute_value::to_double ( double  def = 0.) const

Definition at line 297 of file config_attribute_value.cpp.

References apply_visitor().

template<typename T >
utils::enable_if_t<std::is_base_of<enum_tag, T>::value, T> config_attribute_value::to_enum ( const T &  v) const
inline
Template Parameters
Ta type created with MAKE_ENUM macro NOTE: since T::VALUE constants is not of type T but of the underlying enum type you must specify the template parameter explicitly TODO: Fix this in c++11 using constexpr types.

Definition at line 196 of file config_attribute_value.hpp.

References str().

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

Definition at line 277 of file config_attribute_value.cpp.

References apply_visitor().

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

Definition at line 287 of file config_attribute_value.cpp.

References apply_visitor().

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

Definition at line 292 of file config_attribute_value.cpp.

References apply_visitor().

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

Definition at line 282 of file config_attribute_value.cpp.

References apply_visitor().

Referenced by team::get_side_color_id_from_config().

Friends And Related Function Documentation

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

Definition at line 110 of file config_attribute_value.hpp.

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

Definition at line 126 of file config_attribute_value.hpp.

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

Definition at line 415 of file config_attribute_value.cpp.

Member Data Documentation

const std::string config_attribute_value::s_false
staticprivate
const std::string config_attribute_value::s_no
staticprivate

Definition at line 268 of file config_attribute_value.hpp.

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

const std::string config_attribute_value::s_true
staticprivate
const std::string config_attribute_value::s_yes
staticprivate

Definition at line 268 of file config_attribute_value.hpp.

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

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 149 of file config_attribute_value.hpp.

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


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