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 & | 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= (std::string &&v) |
config_attribute_value & | operator= (const std::string &v) |
config_attribute_value & | operator= (const std::string_view &v) |
config_attribute_value & | operator= (const t_string &v) |
template<typename... Args> | |
config_attribute_value & | operator= (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 |
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 | |
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 |
template<typename T > | |
std::enable_if_t< std::is_constructible_v< std::string, T >, bool > friend | operator== (const config_attribute_value &attribute, const T &comp) |
template<typename T > | |
std::enable_if_t< std::is_constructible_v< std::string, T >, bool > friend | operator== (const T &comp, const config_attribute_value &val) |
template<typename T > | |
std::enable_if_t< std::is_constructible_v< std::string, T >, bool > friend | operator!= (const config_attribute_value &val, const T &comp) |
template<typename T > | |
std::enable_if_t< std::is_constructible_v< std::string, T >, bool > friend | operator!= (const T &comp, 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... | |
Static Public Member Functions | |
template<typename T > | |
static config_attribute_value | create (const T val) |
Private Types | |
typedef utils::variant< utils::monostate, 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 54 of file config_attribute_value.hpp.
|
private |
Definition at line 109 of file config_attribute_value.hpp.
|
inline |
Visitor support: Applies a visitor to the underlying variant.
(See the documentation for Boost.Variant.)
Definition at line 242 of file config_attribute_value.hpp.
References value_.
Referenced by unit_filter_impl::unit_filter_compound::create_attribute(), vconfig::expand(), luaW_pushscalar(), schema_validation::wml_type_simple::matches(), schema_validation::wml_type_tstring::matches(), operator==(), str(), to_double(), to_int(), to_long_long(), to_size_t(), to_unsigned(), and io::write_key_val().
bool config_attribute_value::blank | ( | ) | const |
Tests for an attribute that was never set.
Definition at line 344 of file config_attribute_value.cpp.
References value_.
Referenced by ability_active_adjacent_helper(), name_generator_factory::add_name_generator_from_config(), unit_filter_impl::unit_filter_compound::create_attribute(), empty(), config::get_or(), team::get_village(), team_builder::handle_leader(), unit_type::has_random_traits(), config::inherit_attributes(), side_filter::match_internal(), and game_events::WML_HANDLER_FUNCTION().
|
inlinestatic |
Definition at line 138 of file config_attribute_value.hpp.
Referenced by BOOST_AUTO_TEST_CASE(), operator==(), and actions::undo_event::undo().
bool config_attribute_value::empty | ( | ) | const |
Tests for an attribute that either was never set or was set to "".
Definition at line 352 of file config_attribute_value.cpp.
References blank(), p, and value_.
Referenced by add_simple_anim(), ng::connect_engine::connect_engine(), do_interpolation(), unit_abilities::filter_base_matches(), help::generate_era_topics(), help::generate_faction_topics(), savegame::save_index_class::get(), game_lua_kernel::get_sides_vector(), campaignd::server::handle_delete(), hotkey::load_from_config(), terrain_filter::match_internal(), 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().
|
inline |
Definition at line 172 of file config_attribute_value.hpp.
References str().
|
inline |
Definition at line 181 of file config_attribute_value.hpp.
References operator==().
|
inline |
Definition at line 220 of file config_attribute_value.hpp.
|
inline |
Definition at line 227 of file config_attribute_value.hpp.
config_attribute_value & config_attribute_value::operator= | ( | bool | v | ) |
Definition at line 41 of file config_attribute_value.cpp.
References value_.
Referenced by operator=().
|
inline |
Definition at line 130 of file config_attribute_value.hpp.
References operator=().
Referenced by operator=().
|
inline |
Definition at line 146 of file config_attribute_value.hpp.
References operator=().
config_attribute_value & config_attribute_value::operator= | ( | const std::string & | v | ) |
Definition at line 207 of file config_attribute_value.cpp.
References operator=().
config_attribute_value & config_attribute_value::operator= | ( | const std::string_view & | v | ) |
Definition at line 212 of file config_attribute_value.cpp.
References operator=().
config_attribute_value & config_attribute_value::operator= | ( | const t_string & | v | ) |
Definition at line 219 of file config_attribute_value.cpp.
References t_string::str(), t_string::translatable(), and value_.
config_attribute_value & config_attribute_value::operator= | ( | double | v | ) |
Definition at line 85 of file config_attribute_value.cpp.
config_attribute_value & config_attribute_value::operator= | ( | int | v | ) |
Definition at line 47 of file config_attribute_value.cpp.
References value_.
config_attribute_value & config_attribute_value::operator= | ( | long long | v | ) |
Definition at line 53 of file config_attribute_value.cpp.
References value_.
|
inline |
Definition at line 122 of file config_attribute_value.hpp.
References operator=().
Referenced by operator=().
config_attribute_value & config_attribute_value::operator= | ( | std::string && | v | ) |
Definition at line 144 of file config_attribute_value.cpp.
References d, utils::charconv::from_chars(), i, s_false, s_no, s_true, s_yes, and value_.
config_attribute_value & config_attribute_value::operator= | ( | unsigned long long | v | ) |
Definition at line 74 of file config_attribute_value.cpp.
References value_.
|
inline |
Definition at line 125 of file config_attribute_value.hpp.
References operator=().
Referenced by operator=().
|
inline |
Definition at line 124 of file config_attribute_value.hpp.
References operator=().
Referenced by operator=().
|
inline |
Definition at line 200 of file config_attribute_value.hpp.
References apply_visitor(), and create().
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 403 of file config_attribute_value.cpp.
References value_.
Referenced by operator!=().
|
inline |
Definition at line 213 of file config_attribute_value.hpp.
std::string config_attribute_value::str | ( | const std::string & | fallback = "" | ) | const |
Definition at line 327 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by ng::connect_engine::connect_engine(), unit_filter_impl::unit_filter_compound::create_attribute(), schema_validation::schema_self_validator::detect_schema_derivation_cycles(), gui2::dialogs::mp_options_helper::display_custom_options(), synced_context::generate_random_seed(), game_lua_kernel::get_sides_vector(), campaignd::server::handle_delete(), unit_type::has_random_traits(), luaW_toconfig(), config::matches(), schema_validation::wml_type_simple::matches(), schema_validation::wml_type_list::matches(), randomness::mt_rng::mt_rng(), operator std::string(), tod_manager::resolve_random(), attack_type::special_tooltips(), utils::split(), t_str(), to(), game_events::wml_menu_item::update(), schema_validation::schema_self_validator::validate_key(), verify_and_clear_global_variable(), verify_and_get_global_variable(), verify_and_set_global_variable(), attack_type::weapon_specials(), attack_type::weapon_specials_impl_adj(), and attack_type::weapon_specials_impl_self().
t_string config_attribute_value::t_str | ( | ) | const |
Definition at line 332 of file config_attribute_value.cpp.
References p, str(), and value_.
Referenced by ng::connect_engine::connect_engine(), gui2::dialogs::mp_options_helper::display_custom_options(), gui2::text_shape::draw(), help::generate_era_topics(), help::generate_faction_topics(), and unit::init().
|
inline |
Definition at line 165 of file config_attribute_value.hpp.
References to_bool().
|
inline |
Definition at line 169 of file config_attribute_value.hpp.
References str().
|
inline |
Definition at line 168 of file config_attribute_value.hpp.
References to_double().
|
inline |
Definition at line 166 of file config_attribute_value.hpp.
References to_int().
|
inline |
Definition at line 167 of file config_attribute_value.hpp.
References to_unsigned().
bool config_attribute_value::to_bool | ( | bool | def = false | ) | const |
Definition at line 243 of file config_attribute_value.cpp.
Referenced by gui2::dialogs::mp_options_helper::display_custom_options(), tod_manager::resolve_random(), to(), and game_events::wml_menu_item::update().
double config_attribute_value::to_double | ( | double | def = 0. | ) | const |
Definition at line 300 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by to().
int config_attribute_value::to_int | ( | int | def = 0 | ) | const |
Definition at line 280 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(), hotkey::load_from_config(), terrain_filter::match_internal(), movetype::resistances::merge(), movetype::terrain_info::data::merge(), terrain_label::read(), to(), verify_and_clear_global_variable(), verify_and_get_global_variable(), verify_and_set_global_variable(), and game_events::WML_HANDLER_FUNCTION().
long long config_attribute_value::to_long_long | ( | long long | def = 0 | ) | const |
Definition at line 285 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by chrono::parse_timestamp().
std::size_t config_attribute_value::to_size_t | ( | std::size_t | def = 0 | ) | const |
Definition at line 295 of file config_attribute_value.cpp.
References apply_visitor().
unsigned config_attribute_value::to_unsigned | ( | unsigned | def = 0 | ) | const |
Definition at line 290 of file config_attribute_value.cpp.
References apply_visitor().
Referenced by to().
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 229 of file config_attribute_value.cpp.
void config_attribute_value::write_if_not_empty | ( | const t_string & | v | ) |
Definition at line 236 of file config_attribute_value.cpp.
References t_string::empty().
|
friend |
Definition at line 408 of file config_attribute_value.cpp.
|
friend |
Definition at line 73 of file config_attribute_value.hpp.
|
friend |
Definition at line 91 of file config_attribute_value.hpp.
|
staticprivate |
Definition at line 250 of file config_attribute_value.hpp.
Referenced by operator=(), and config_attribute_value::true_false::str().
|
staticprivate |
Definition at line 249 of file config_attribute_value.hpp.
Referenced by operator=(), and config_attribute_value::yes_no::str().
|
staticprivate |
Definition at line 250 of file config_attribute_value.hpp.
Referenced by operator=(), and config_attribute_value::true_false::str().
|
staticprivate |
Definition at line 249 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 116 of file config_attribute_value.hpp.
Referenced by apply_visitor(), blank(), empty(), operator=(), operator==(), t_str(), and to_bool().