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_value & | operator= (const config_attribute_value &) |
Default implementation, but defined out-of-line for efficiency reasons. More... | |
config_attribute_value & | operator= (bool v) |
config_attribute_value & | operator= (int v) |
config_attribute_value & | operator= (long v) |
config_attribute_value & | operator= (long long v) |
config_attribute_value & | operator= (unsigned v) |
config_attribute_value & | operator= (unsigned long v) |
config_attribute_value & | operator= (unsigned long long v) |
config_attribute_value & | operator= (double v) |
config_attribute_value & | operator= (const char *v) |
config_attribute_value & | operator= (const std::string &v) |
config_attribute_value & | operator= (const t_string &v) |
template<typename T > | |
std::enable_if_t< std::is_base_of_v< enum_tag, T >, config_attribute_value & > | operator= (const T &v) |
void | write_if_not_empty (const std::string &v) |
Calls operator=(const std::string&) if v is not empty. More... | |
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 |
template<typename T > | |
std::enable_if_t< std::is_base_of_v< enum_tag, T >, T > | to_enum (const T &v) const |
operator int () const | |
operator std::string () const | |
operator t_string () const | |
operator bool () 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 > | |
std::enable_if_t< std::is_same_v< const std::string, std::add_const_t< T > >, bool > friend | operator== (const config_attribute_value &val, const T &str) |
template<typename T > | |
std::enable_if_t< std::is_same_v< const char *, T >, 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 |
Visitor support: 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) |
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 59 of file config_attribute_value.hpp.
|
private |
Definition at line 101 of file config_attribute_value.hpp.
config_attribute_value::config_attribute_value | ( | ) |
Default implementation, but defined out-of-line for efficiency reasons.
Definition at line 48 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 54 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 59 of file config_attribute_value.cpp.
|
inline |
Visitor support: Applies a visitor to the underlying variant.
(See the documentation for Boost.Variant.)
Definition at line 241 of file config_attribute_value.hpp.
References variable_info_implementation::apply_visitor().
Referenced by attack_type::add_formula_context(), unit_filter_impl::unit_filter_compound::create_attribute(), vconfig::expand(), unit_filter_impl::unit_filter_compound::fill(), luaW_pushscalar(), unit::parse_upkeep(), 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 |
Tests for an attribute that was never set.
Definition at line 343 of file config_attribute_value.cpp.
References value_.
Referenced by name_generator_factory::add_name_generator_from_config(), unit_filter_impl::unit_filter_compound::create_attribute(), unit_filter::first_match_on_map(), unit::get_ability_list(), team::get_side_color_id_from_config(), team::get_village(), team_builder::handle_leader(), unit_type::has_random_traits(), config::inherit_attributes(), side_filter::match_internal(), operator bool(), 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 351 of file config_attribute_value.cpp.
Referenced by add_simple_anim(), ng::connect_engine::connect_engine(), do_interpolation(), unit_abilities::filter_base_matches(), unit_filter::first_match_on_map(), help::generate_era_topics(), help::generate_faction_topics(), savegame::save_index_class::get(), team::get_side_color_id_from_config(), game_lua_kernel::get_sides_vector(), campaignd::server::handle_delete(), game_lua_kernel::impl_current_get(), terrain_filter::match_internal(), operator bool(), 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 410 of file config_attribute_value.cpp.
References str().
Referenced by operator!=(), and operator==().
|
inlineexplicit |
Definition at line 182 of file config_attribute_value.hpp.
References blank(), empty(), operator==(), and to_bool().
|
inline |
Definition at line 178 of file config_attribute_value.hpp.
References to_int().
|
inline |
Definition at line 179 of file config_attribute_value.hpp.
References config_attribute_value::true_false::str().
|
inline |
Definition at line 180 of file config_attribute_value.hpp.
References t_str().
|
inline |
Definition at line 192 of file config_attribute_value.hpp.
References equals(), and operator==().
|
inline |
Definition at line 221 of file config_attribute_value.hpp.
References config_attribute_value::true_false::str().
|
inline |
Definition at line 227 of file config_attribute_value.hpp.
References operator<<, and config_attribute_value::true_false::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 65 of file config_attribute_value.cpp.
References value_.
Referenced by operator=().
config_attribute_value & config_attribute_value::operator= | ( | bool | v | ) |
Definition at line 71 of file config_attribute_value.cpp.
References value_.
config_attribute_value & config_attribute_value::operator= | ( | int | v | ) |
Definition at line 77 of file config_attribute_value.cpp.
References value_.
|
inline |
Definition at line 136 of file config_attribute_value.hpp.
References operator=().
Referenced by operator=().
config_attribute_value & config_attribute_value::operator= | ( | long long | v | ) |
Definition at line 83 of file config_attribute_value.cpp.
References value_.
|
inline |
Definition at line 138 of file config_attribute_value.hpp.
References operator=().
Referenced by operator=().
|
inline |
Definition at line 139 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 104 of file config_attribute_value.cpp.
References value_.
config_attribute_value & config_attribute_value::operator= | ( | double | v | ) |
Definition at line 115 of file config_attribute_value.cpp.
|
inline |
Definition at line 144 of file config_attribute_value.hpp.
References operator=().
Referenced by operator=().
config_attribute_value & config_attribute_value::operator= | ( | const std::string & | v | ) |
config_attribute_value & config_attribute_value::operator= | ( | const t_string & | v | ) |
Definition at line 227 of file config_attribute_value.cpp.
References t_string::str(), t_string::translatable(), and value_.
|
inline |
Definition at line 148 of file config_attribute_value.hpp.
References operator=(), config_attribute_value::true_false::str(), t_str(), to_bool(), to_double(), to_int(), to_long_long(), to_size_t(), to_time_t(), to_unsigned(), and write_if_not_empty().
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 399 of file config_attribute_value.cpp.
References variable_info_implementation::apply_visitor(), and value_.
Referenced by operator bool(), and operator!=().
|
inline |
Definition at line 202 of file config_attribute_value.hpp.
References equals().
|
inline |
Definition at line 209 of file config_attribute_value.hpp.
References equals().
|
inline |
Definition at line 215 of file config_attribute_value.hpp.
References config_attribute_value::true_false::str().
std::string config_attribute_value::str | ( | const std::string & | fallback = "" | ) | const |
Definition at line 326 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by addon_filename_legal(), ng::connect_engine::connect_engine(), unit_filter_impl::unit_filter_compound::create_attribute(), gui2::dialogs::mp_options_helper::display_custom_options(), equals(), unit_filter_impl::unit_filter_compound::fill(), synced_context::generate_random_seed(), team::get_side_color_id_from_config(), game_lua_kernel::get_sides_vector(), unit_type::has_random_traits(), luaW_toconfig(), config::matches(), randomness::mt_rng::mt_rng(), tod_manager::resolve_random(), utils::split(), t_str(), game_events::wml_menu_item::update(), verify_and_clear_global_variable(), verify_and_get_global_variable(), and verify_and_set_global_variable().
t_string config_attribute_value::t_str | ( | ) | const |
Definition at line 331 of file config_attribute_value.cpp.
References p, str(), and value_.
Referenced by ng::connect_engine::connect_engine(), unit_filter_impl::unit_filter_compound::fill(), help::generate_era_topics(), help::generate_faction_topics(), unit::get_ability_list(), operator t_string(), and operator=().
bool config_attribute_value::to_bool | ( | bool | def = false | ) | const |
Definition at line 244 of file config_attribute_value.cpp.
References d, i, p, s, and value_.
Referenced by gui2::dialogs::mp_options_helper::display_custom_options(), unit_filter_impl::unit_filter_compound::fill(), operator bool(), operator=(), tod_manager::resolve_random(), and game_events::wml_menu_item::update().
double config_attribute_value::to_double | ( | double | def = 0. | ) | const |
Definition at line 303 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by operator=().
|
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 172 of file config_attribute_value.hpp.
References config_attribute_value::true_false::str().
int config_attribute_value::to_int | ( | int | def = 0 | ) | const |
Definition at line 278 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by gui2::dialogs::mp_options_helper::display_custom_options(), unit_abilities::filter_base_matches(), get_global_variable(), terrain_filter::match_internal(), movetype::terrain_info::data::merge(), movetype::resistances::merge(), operator int(), operator=(), terrain_label::read(), 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 283 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by operator=().
std::size_t config_attribute_value::to_size_t | ( | std::size_t | def = 0 | ) | const |
Definition at line 293 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by operator=().
std::time_t config_attribute_value::to_time_t | ( | std::time_t | def = 0 | ) | const |
Definition at line 298 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by savegame::save_index_class::get(), and operator=().
unsigned config_attribute_value::to_unsigned | ( | unsigned | def = 0 | ) | const |
Definition at line 288 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by team::get_side_color_id_from_config(), and operator=().
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 237 of file config_attribute_value.cpp.
Referenced by operator=().
|
friend |
Definition at line 78 of file config_attribute_value.hpp.
Referenced by operator!=().
|
friend |
Definition at line 96 of file config_attribute_value.hpp.
|
friend |
Definition at line 421 of file config_attribute_value.cpp.
|
staticprivate |
Definition at line 249 of file config_attribute_value.hpp.
Referenced by operator=(), and config_attribute_value::true_false::str().
|
staticprivate |
Definition at line 248 of file config_attribute_value.hpp.
Referenced by operator=(), and config_attribute_value::yes_no::str().
|
staticprivate |
Definition at line 249 of file config_attribute_value.hpp.
Referenced by operator=(), and config_attribute_value::true_false::str().
|
staticprivate |
Definition at line 248 of file config_attribute_value.hpp.
Referenced by operator=(), and 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 121 of file config_attribute_value.hpp.
Referenced by blank(), empty(), operator<<(), operator=(), operator==(), t_str(), and to_bool().