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_value & | operator= (const attribute_value &) |
Default implementation, but defined out-of-line for efficiency reasons. More... | |
attribute_value & | operator= (bool v) |
attribute_value & | operator= (int v) |
attribute_value & | operator= (long v) |
attribute_value & | operator= (long long v) |
attribute_value & | operator= (unsigned v) |
attribute_value & | operator= (unsigned long v) |
attribute_value & | operator= (unsigned long long v) |
attribute_value & | operator= (double v) |
attribute_value & | operator= (const char *v) |
attribute_value & | operator= (const std::string &v) |
attribute_value & | operator= (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) |
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.
Definition at line 223 of file config.hpp.
|
private |
Definition at line 259 of file config.hpp.
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.
|
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 |
Tests for an attribute that was never set.
Definition at line 367 of file config.cpp.
Referenced by unit::ability_tooltips(), default_map_generator_job::default_generate_map(), do_interpolation(), team::get_village(), team_builder::handle_leader(), unit_type::has_random_traits(), basic_unit_filter_impl::internal_matches_filter(), game_lua_kernel::intf_heal_unit(), side_filter::match_internal(), unit_race::unit_race(), unit_display::wml_animation_internal(), and game_events::WML_HANDLER_FUNCTION().
bool config::attribute_value::empty | ( | ) | const |
Tests for an attribute that either was never set or was set to "".
Definition at line 375 of file config.cpp.
Referenced by add_simple_anim(), unit_type::build_full(), unit_type::build_help_index(), ng::connect_engine::connect_engine(), unit_abilities::filter_base_matches(), help::generate_era_topics(), help::generate_faction_topics(), savegame::save_index_class::get(), game_lua_kernel::get_sides_vector(), game_lua_kernel::intf_kill(), game_lua_kernel::intf_modify_side(), terrain_filter::match_internal(), unit::parse_upkeep(), terrain_label::read(), saved_game::set_defaults(), carryover_info::transfer_to(), game_events::wml_menu_item::update_command(), verify_and_clear_global_variable(), verify_and_get_global_variable(), verify_and_set_global_variable(), and game_events::WML_HANDLER_FUNCTION().
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==().
|
inline |
Definition at line 330 of file config.hpp.
References to_int().
|
inline |
Definition at line 331 of file config.hpp.
References str().
|
inline |
Definition at line 332 of file config.hpp.
References t_str().
|
inline |
Definition at line 342 of file config.hpp.
References operator==().
|
inline |
Definition at line 363 of file config.hpp.
References str().
|
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.
|
inline |
config::attribute_value & config::attribute_value::operator= | ( | long long | v | ) |
Definition at line 150 of file config.cpp.
|
inline |
|
inline |
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.
|
inline |
config::attribute_value & config::attribute_value::operator= | ( | const std::string & | v | ) |
Definition at line 222 of file config.cpp.
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().
|
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!=().
|
inline |
Definition at line 350 of file config.hpp.
References equals().
|
inline |
Definition at line 355 of file config.hpp.
References equals().
|
inline |
Definition at line 359 of file config.hpp.
References str().
std::string config::attribute_value::str | ( | ) | const |
Definition at line 353 of file config.cpp.
Referenced by ng::connect_engine::connect_engine(), synced_context::generate_random_seed(), game_lua_kernel::get_sides_vector(), unit_type::has_random_traits(), luaW_toconfig(), rand_rng::mt_rng::mt_rng(), operator std::string(), operator!=(), operator==(), tod_manager::resolve_random(), to_enum(), game_events::wml_menu_item::update(), verify_and_clear_global_variable(), verify_and_get_global_variable(), verify_and_set_global_variable(), and unit_display::wml_animation_internal().
t_string config::attribute_value::t_str | ( | ) | const |
Definition at line 358 of file config.cpp.
Referenced by unit::ability_tooltips(), unit_type::build_help_index(), ng::connect_engine::connect_engine(), help::generate_era_topics(), help::generate_faction_topics(), and operator t_string().
bool config::attribute_value::to_bool | ( | bool | def = false | ) | const |
Definition at line 275 of file config.cpp.
Referenced by game_lua_kernel::intf_modify_side(), tod_manager::resolve_random(), mp::options::checkbox_display::set_value(), and game_events::wml_menu_item::update().
double config::attribute_value::to_double | ( | double | def = 0. | ) | const |
Definition at line 333 of file config.cpp.
Referenced by unit_type::build_full().
|
inline |
T | a 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().
Definition at line 308 of file config.cpp.
Referenced by unit_abilities::filter_base_matches(), savegame::save_index_class::get(), get_global_variable(), game_lua_kernel::intf_modify_side(), terrain_filter::match_internal(), movetype::terrain_info::data::merge(), movetype::resistances::merge(), operator int(), unit::parse_upkeep(), terrain_label::read(), mp::options::slider_display::set_value(), verify_and_clear_global_variable(), verify_and_get_global_variable(), and game_events::WML_HANDLER_FUNCTION().
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.
|
friend |
Definition at line 783 of file config.hpp.
|
friend |
Definition at line 784 of file config.hpp.
|
friend |
Definition at line 428 of file config.cpp.
|
staticprivate |
Definition at line 383 of file config.hpp.
Referenced by config::attribute_value::true_false::str().
|
staticprivate |
Definition at line 382 of file config.hpp.
Referenced by config::attribute_value::yes_no::str().
|
staticprivate |
Definition at line 383 of file config.hpp.
Referenced by config::attribute_value::true_false::str().
|
staticprivate |
Definition at line 382 of file config.hpp.
Referenced by config::attribute_value::yes_no::str().
|
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==().