The Battle for Wesnoth  1.13.4+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.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

 attribute_value ()
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
 ~attribute_value ()
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
 attribute_value (const attribute_value &)
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
attribute_valueoperator= (const attribute_value &)
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
attribute_valueoperator= (bool v)
 
attribute_valueoperator= (int v)
 
attribute_valueoperator= (long v)
 
attribute_valueoperator= (long long v)
 
attribute_valueoperator= (unsigned v)
 
attribute_valueoperator= (unsigned long v)
 
attribute_valueoperator= (unsigned long long v)
 
attribute_valueoperator= (double v)
 
attribute_valueoperator= (const char *v)
 
attribute_valueoperator= (const std::string &v)
 
attribute_valueoperator= (const t_string &v)
 
template<typename T >
boost::enable_if
< boost::is_base_of< enum_tag,
T >, attribute_value & >::type 
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
 
t_string t_str () const
 
template<typename T >
boost::enable_if
< boost::is_base_of< enum_tag,
T >, T >::type 
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 attribute_value &other) const
 Checks for equality of the attribute values when viewed as strings. More...
 
bool operator!= (const 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 >
boost::enable_if
< boost::is_same< const
std::string, typename
boost::add_const< T >::type >
, bool >::type friend 
operator== (const attribute_value &val, const T &str)
 
template<typename T >
boost::enable_if
< boost::is_same< const char
*, T >, bool >::type friend 
operator== (const attribute_value &val, T str)
 
template<typename T >
bool friend operator== (const T &str, const attribute_value &val)
 
template<typename T >
bool friend operator!= (const attribute_value &val, const T &str)
 
template<typename T >
bool friend operator!= (const T &str, const 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 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 223 of file config.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 259 of file config.hpp.

Constructor & Destructor Documentation

config::attribute_value::attribute_value ( )

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

Definition at line 115 of file config.cpp.

config::attribute_value::~attribute_value ( )

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

Definition at line 121 of file config.cpp.

config::attribute_value::attribute_value ( const attribute_value that)

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

Definition at line 126 of file config.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 377 of file config.hpp.

Referenced by vconfig::expand(), luaW_pushscalar(), 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 417 of file config.cpp.

Referenced by operator==().

config::attribute_value::operator int ( ) const
inline

Definition at line 330 of file config.hpp.

References to_int().

config::attribute_value::operator std::string ( ) const
inline

Definition at line 331 of file config.hpp.

References str().

config::attribute_value::operator t_string ( ) const
inline

Definition at line 332 of file config.hpp.

References t_str().

bool config::attribute_value::operator!= ( const attribute_value other) const
inline

Definition at line 342 of file config.hpp.

References operator==().

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

Definition at line 363 of file config.hpp.

References str().

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

Definition at line 367 of file config.hpp.

References str().

config::attribute_value & config::attribute_value::operator= ( const attribute_value that)

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

Definition at line 132 of file config.cpp.

References value_.

Referenced by operator=().

config::attribute_value & config::attribute_value::operator= ( bool  v)

Definition at line 138 of file config.cpp.

config::attribute_value & config::attribute_value::operator= ( int  v)

Definition at line 144 of file config.cpp.

attribute_value& config::attribute_value::operator= ( long  v)
inline

Definition at line 292 of file config.hpp.

References operator=().

Referenced by operator=().

config::attribute_value & config::attribute_value::operator= ( long long  v)

Definition at line 150 of file config.cpp.

attribute_value& config::attribute_value::operator= ( unsigned  v)
inline

Definition at line 294 of file config.hpp.

References operator=().

Referenced by operator=().

attribute_value& config::attribute_value::operator= ( unsigned long  v)
inline

Definition at line 295 of file config.hpp.

References operator=().

Referenced by operator=().

config::attribute_value & config::attribute_value::operator= ( unsigned long long  v)

Definition at line 169 of file config.cpp.

config::attribute_value & config::attribute_value::operator= ( double  v)

Definition at line 179 of file config.cpp.

References i.

attribute_value& config::attribute_value::operator= ( const char *  v)
inline

Definition at line 300 of file config.hpp.

References operator=().

Referenced by operator=().

config::attribute_value & config::attribute_value::operator= ( const std::string v)

Definition at line 222 of file config.cpp.

References d, and i.

config::attribute_value & config::attribute_value::operator= ( const t_string v)

Definition at line 267 of file config.cpp.

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

template<typename T >
boost::enable_if<boost::is_base_of<enum_tag, T>, attribute_value &>::type config::attribute_value::operator= ( const T &  v)
inline

Definition at line 304 of file config.hpp.

References operator=().

bool config::attribute_value::operator== ( const 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 406 of file config.cpp.

References value_.

Referenced by operator!=().

template<typename T >
boost::enable_if<boost::is_same<const std::string, typename boost::add_const<T>::type>, bool>::type friend config::attribute_value::operator== ( const attribute_value val,
const T &  str 
)
inline

Definition at line 350 of file config.hpp.

References equals().

template<typename T >
boost::enable_if<boost::is_same<const char*, T>, bool>::type friend config::attribute_value::operator== ( const attribute_value val,
str 
)
inline

Definition at line 355 of file config.hpp.

References equals().

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

Definition at line 359 of file config.hpp.

References str().

std::string config::attribute_value::str ( ) 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 333 of file config.cpp.

Referenced by unit_type::build_full().

template<typename T >
boost::enable_if<boost::is_base_of<enum_tag, T>, T>::type config::attribute_value::to_enum ( const T &  v) const
inline
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 324 of file config.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 313 of file config.cpp.

size_t config::attribute_value::to_size_t ( size_t  def = 0) const

Definition at line 323 of file config.cpp.

time_t config::attribute_value::to_time_t ( time_t  def = 0) const

Definition at line 328 of file config.cpp.

unsigned config::attribute_value::to_unsigned ( unsigned  def = 0) const

Definition at line 318 of file config.cpp.

Friends And Related Function Documentation

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

Definition at line 783 of file config.hpp.

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

Definition at line 784 of file config.hpp.

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

Definition at line 428 of file config.cpp.

Member Data Documentation

const std::string config::attribute_value::s_false
staticprivate

Definition at line 383 of file config.hpp.

Referenced by config::attribute_value::true_false::str().

const std::string config::attribute_value::s_no
staticprivate

Definition at line 382 of file config.hpp.

Referenced by config::attribute_value::yes_no::str().

const std::string config::attribute_value::s_true
staticprivate

Definition at line 383 of file config.hpp.

Referenced by config::attribute_value::true_false::str().

const std::string config::attribute_value::s_yes
staticprivate

Definition at line 382 of file config.hpp.

Referenced by 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 277 of file config.hpp.

Referenced by operator<<(), operator=(), and operator==().


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