#include <variant.hpp>
Public Types | |
enum | DECIMAL_VARIANT_TYPE { DECIMAL_VARIANT } |
Public Member Functions | |
variant () | |
variant (int n) | |
variant (int n, DECIMAL_VARIANT_TYPE) | |
variant (double n, DECIMAL_VARIANT_TYPE) | |
variant (const std::vector< variant > &array) | |
variant (const std::string &str) | |
variant (const std::map< variant, variant > &map) | |
variant (const variant &v)=default | |
variant (variant &&v)=default | |
template<typename T > | |
variant (std::shared_ptr< T > callable) | |
variant & | operator= (const variant &v)=default |
variant & | operator= (variant &&v)=default |
variant | operator[] (std::size_t n) const |
variant | operator[] (const variant &v) const |
std::size_t | num_elements () const |
bool | is_empty () const |
variant | get_member (const std::string &name) const |
bool | is_null () const |
Functions to test the type of the internal value. More... | |
bool | is_int () const |
bool | is_decimal () const |
bool | is_callable () const |
bool | is_list () const |
bool | is_string () const |
bool | is_map () const |
int | as_int () const |
int | as_decimal () const |
Returns variant's internal representation of decimal number: ie, 1.234 is represented as 1234. More... | |
bool | as_bool () const |
Returns a boolean state of the variant value. More... | |
const std::vector< variant > & | as_list () const |
const std::map< variant, variant > & | as_map () const |
const std::string & | as_string () const |
const_formula_callable_ptr | as_callable () const |
template<typename T > | |
std::shared_ptr< T > | try_convert () const |
template<typename T > | |
std::shared_ptr< T > | convert_to () const |
variant | operator+ (const variant &) const |
variant | operator- (const variant &) const |
variant | operator* (const variant &) const |
variant | operator/ (const variant &) const |
variant | operator^ (const variant &) const |
variant | operator% (const variant &) const |
variant | operator- () const |
bool | operator== (const variant &) const |
bool | operator!= (const variant &) const |
bool | operator< (const variant &) const |
bool | operator> (const variant &) const |
bool | operator<= (const variant &) const |
bool | operator>= (const variant &) const |
variant | list_elements_add (const variant &v) const |
variant | list_elements_sub (const variant &v) const |
variant | list_elements_mul (const variant &v) const |
variant | list_elements_div (const variant &v) const |
variant | concatenate (const variant &v) const |
variant | build_range (const variant &v) const |
bool | contains (const variant &other) const |
variant | get_keys () const |
variant | get_values () const |
variant_iterator | begin () const |
variant_iterator | end () const |
std::string | serialize_to_string () const |
void | serialize_from_string (const std::string &str) |
std::string | string_cast () const |
std::string | to_debug_string (bool verbose=false, formula_seen_stack *seen=nullptr) const |
std::string | type_string () const |
Gets string name of the current value type. More... | |
variant | execute_variant (const variant &to_exec) |
Private Member Functions | |
template<typename T > | |
std::shared_ptr< T > | value_cast () const |
void | must_be (formula_variant::type t) const |
void | must_both_be (formula_variant::type t, const variant &second) const |
formula_variant::type | type () const |
Private Attributes | |
value_base_ptr | value_ |
Variant value. More... | |
Definition at line 28 of file variant.hpp.
Enumerator | |
---|---|
DECIMAL_VARIANT |
Definition at line 31 of file variant.hpp.
wfl::variant::variant | ( | ) |
Definition at line 140 of file variant.cpp.
Referenced by concatenate(), execute_variant(), get_keys(), get_member(), get_values(), operator%(), operator*(), operator+(), operator-(), operator/(), operator[](), operator^(), and serialize_from_string().
|
explicit |
Definition at line 144 of file variant.cpp.
References value_.
wfl::variant::variant | ( | int | n, |
variant::DECIMAL_VARIANT_TYPE | |||
) |
Definition at line 150 of file variant.cpp.
References value_.
wfl::variant::variant | ( | double | n, |
variant::DECIMAL_VARIANT_TYPE | |||
) |
Definition at line 156 of file variant.cpp.
References value_.
|
explicit |
Definition at line 162 of file variant.cpp.
References value_.
|
explicit |
Definition at line 168 of file variant.cpp.
References value_.
Definition at line 174 of file variant.cpp.
References value_.
|
default |
|
default |
|
inline |
Definition at line 44 of file variant.hpp.
References value_.
bool wfl::variant::as_bool | ( | ) | const |
Returns a boolean state of the variant value.
The implementation is type-dependent.
Definition at line 313 of file variant.cpp.
References value_.
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), gui2::image_shape::draw(), gui2::text_shape::draw(), wfl::unary_operator_expression::execute(), wfl::operator_expression::execute(), gui2::typed_formula< T >::execute(), execute_variant(), terrain_filter::match_internal(), side_filter::match_internal(), matches_simple_filter(), game_events::filter_formula::operator()(), and ai::variant_value_translator< bool >::variant_to_value().
|
inline |
Definition at line 83 of file variant.hpp.
References must_be().
Referenced by convert_to(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::dot_expression::execute(), wfl::formula_function_expression::execute(), wfl::attack_callable::execute_self(), wfl::move_callable::execute_self(), wfl::move_partial_callable::execute_self(), wfl::recall_callable::execute_self(), wfl::recruit_callable::execute_self(), wfl::set_unit_var_callable::execute_self(), wfl::safe_call_callable::execute_self(), ai::attack_analysis::execute_self(), luaW_pushfaivariant(), and try_convert().
int wfl::variant::as_decimal | ( | ) | const |
Returns variant's internal representation of decimal number: ie, 1.234 is represented as 1234.
Definition at line 300 of file variant.cpp.
References is_decimal(), is_int(), is_null(), and wfl::was_expecting().
Referenced by as_int(), wfl::builtins::DEFINE_WFL_FUNCTION(), luaW_pushfaivariant(), operator%(), operator*(), operator+(), operator-(), operator/(), operator<(), operator==(), and operator^().
int wfl::variant::as_int | ( | ) | const |
Definition at line 291 of file variant.cpp.
References as_decimal(), is_decimal(), is_null(), and must_be().
Referenced by BOOST_AUTO_TEST_CASE(), build_range(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::gamestate::DEFINE_WFL_FUNCTION(), gui2::text_shape::draw(), wfl::operator_expression::execute(), gui2::typed_formula< T >::execute(), gui2::rich_label::get_image_size(), gui2::rich_label::get_text_size(), luaW_pushfaivariant(), operator%(), image::adjust_alpha_modification::operator()(), image::adjust_channels_modification::operator()(), operator*(), operator+(), operator-(), operator/(), operator[](), operator^(), and ai::variant_value_translator< int >::variant_to_value().
const std::vector< variant > & wfl::variant::as_list | ( | ) | const |
Definition at line 324 of file variant.cpp.
References must_be().
Referenced by gui2::typed_formula< T >::execute(), and luaW_pushfaivariant().
Definition at line 330 of file variant.cpp.
References must_be().
Referenced by wfl::map_callable::get_value(), and luaW_pushfaivariant().
const std::string & wfl::variant::as_string | ( | ) | const |
Definition at line 318 of file variant.cpp.
References must_be().
Referenced by concatenate(), wfl::gamestate::DEFINE_WFL_FUNCTION(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::string_expression::execute(), gui2::typed_formula< T >::execute(), wfl::map_callable::get_inputs(), wfl::string_callable::get_value(), luaW_pushfaivariant(), wfl::string_expression::str(), and ai::variant_value_translator< std::string >::variant_to_value().
variant_iterator wfl::variant::begin | ( | ) | const |
Definition at line 252 of file variant.cpp.
References value_.
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::move_candidate_action::evaluate(), and wfl::attack_candidate_action::evaluate().
Definition at line 586 of file variant.cpp.
References as_int(), and must_both_be().
Referenced by wfl::operator_expression::execute().
Definition at line 560 of file variant.cpp.
References as_string(), i, is_list(), is_string(), must_be(), num_elements(), variant(), and wfl::was_expecting().
Referenced by wfl::operator_expression::execute().
bool wfl::variant::contains | ( | const variant & | other | ) | const |
Definition at line 593 of file variant.cpp.
References is_list(), is_map(), and wfl::was_expecting().
|
inline |
Definition at line 100 of file variant.hpp.
References as_callable().
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), and wfl::gamestate::DEFINE_WFL_FUNCTION().
variant_iterator wfl::variant::end | ( | ) | const |
Definition at line 257 of file variant.cpp.
References value_.
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::move_candidate_action::evaluate(), and wfl::attack_candidate_action::evaluate().
Definition at line 653 of file variant.cpp.
References as_bool(), ERR_SF, is_int(), is_list(), n, num_elements(), and variant().
Referenced by gui2::image_shape::draw(), gui2::text_shape::draw(), ai::formula_ai::evaluate(), wfl::safe_call_callable::execute_self(), and ai::formula_ai::make_action().
variant wfl::variant::get_keys | ( | ) | const |
Definition at line 228 of file variant.cpp.
References i, must_be(), and variant().
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION().
variant wfl::variant::get_member | ( | const std::string & | name | ) | const |
Definition at line 276 of file variant.cpp.
References is_callable(), and variant().
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::map_callable::get_inputs(), and wfl::formula_variant_callable_with_backup::get_value().
variant wfl::variant::get_values | ( | ) | const |
Definition at line 240 of file variant.cpp.
References i, must_be(), and variant().
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION().
|
inline |
Definition at line 65 of file variant.hpp.
References type().
Referenced by wfl::dot_expression::execute(), get_member(), luaW_pushfaivariant(), operator[](), and try_convert().
|
inline |
Definition at line 64 of file variant.hpp.
References type().
Referenced by as_decimal(), as_int(), wfl::builtins::DEFINE_WFL_FUNCTION(), luaW_pushfaivariant(), operator%(), operator*(), operator+(), operator-(), operator/(), operator<(), operator==(), and operator^().
bool wfl::variant::is_empty | ( | ) | const |
Definition at line 262 of file variant.cpp.
References value_.
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), ai::stage_side_formulas::do_play_stage(), ai::stage_unit_formulas::do_play_stage(), ai::formula_ai::evaluate(), and ai::formula_ai::execute_candidate_action().
|
inline |
Definition at line 63 of file variant.hpp.
References type().
Referenced by as_decimal(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::gamestate::DEFINE_WFL_FUNCTION(), execute_variant(), luaW_pushfaivariant(), and operator<().
|
inline |
Definition at line 66 of file variant.hpp.
References type().
Referenced by concatenate(), contains(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::dot_expression::execute(), wfl::square_bracket_expression::execute(), execute_variant(), luaW_pushfaivariant(), num_elements(), operator+(), and operator[]().
|
inline |
Definition at line 68 of file variant.hpp.
References type().
Referenced by contains(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::dot_expression::execute(), wfl::square_bracket_expression::execute(), luaW_pushfaivariant(), num_elements(), operator+(), and operator[]().
|
inline |
Functions to test the type of the internal value.
Definition at line 62 of file variant.hpp.
References type().
Referenced by as_decimal(), as_int(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::gamestate::DEFINE_WFL_FUNCTION(), ai::formula_ai::get_keeps(), wfl::formula_callable_with_backup::get_value(), wfl::formula_variant_callable_with_backup::get_value(), wfl::formula_callable::has_key(), and luaW_pushfaivariant().
|
inline |
Definition at line 67 of file variant.hpp.
References type().
Referenced by concatenate(), wfl::gamestate::DEFINE_WFL_FUNCTION(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::dot_expression::execute(), wfl::map_callable::get_inputs(), and luaW_pushfaivariant().
Definition at line 536 of file variant.cpp.
References must_both_be(), and value_.
Referenced by wfl::operator_expression::execute().
Definition at line 554 of file variant.cpp.
References must_both_be(), and value_.
Referenced by wfl::operator_expression::execute().
Definition at line 548 of file variant.cpp.
References must_both_be(), and value_.
Referenced by wfl::operator_expression::execute().
Definition at line 542 of file variant.cpp.
References must_both_be(), and value_.
Referenced by wfl::operator_expression::execute().
|
private |
Definition at line 606 of file variant.cpp.
References t, type(), wfl::variant_type_to_string(), and wfl::was_expecting().
Referenced by as_callable(), as_int(), as_list(), as_map(), as_string(), concatenate(), get_keys(), get_values(), and operator[]().
|
private |
Definition at line 613 of file variant.cpp.
References t, to_debug_string(), type(), type_string(), and wfl::variant_type_to_string().
Referenced by build_range(), list_elements_add(), list_elements_div(), list_elements_mul(), and list_elements_sub().
std::size_t wfl::variant::num_elements | ( | ) | const |
Definition at line 267 of file variant.cpp.
References is_list(), is_map(), value_, and wfl::was_expecting().
Referenced by BOOST_AUTO_TEST_CASE(), concatenate(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::attack_candidate_action::evaluate(), execute_variant(), wfl::list_callable::get_value(), wfl::map_callable::get_value(), and operator[]().
bool wfl::variant::operator!= | ( | const variant & | v | ) | const |
Definition at line 499 of file variant.cpp.
References operator==().
Definition at line 440 of file variant.cpp.
References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().
Definition at line 382 of file variant.cpp.
References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().
Definition at line 336 of file variant.cpp.
References as_decimal(), as_int(), DECIMAL_VARIANT, wfl::variant_container< T >::get_container(), is_decimal(), is_list(), is_map(), value_cast(), and variant().
variant wfl::variant::operator- | ( | ) | const |
Definition at line 477 of file variant.cpp.
References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().
Definition at line 373 of file variant.cpp.
References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().
Definition at line 405 of file variant.cpp.
References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().
bool wfl::variant::operator< | ( | const variant & | v | ) | const |
Definition at line 504 of file variant.cpp.
References as_decimal(), is_decimal(), is_int(), type(), and value_.
bool wfl::variant::operator<= | ( | const variant & | v | ) | const |
Definition at line 526 of file variant.cpp.
bool wfl::variant::operator== | ( | const variant & | v | ) | const |
Definition at line 486 of file variant.cpp.
References as_decimal(), is_decimal(), type(), and value_.
Referenced by operator!=().
bool wfl::variant::operator> | ( | const variant & | v | ) | const |
Definition at line 531 of file variant.cpp.
bool wfl::variant::operator>= | ( | const variant & | v | ) | const |
Definition at line 521 of file variant.cpp.
Definition at line 195 of file variant.cpp.
References as_int(), i, is_callable(), is_list(), is_map(), num_elements(), operator[](), variant(), and wfl::was_expecting().
variant wfl::variant::operator[] | ( | std::size_t | n | ) | const |
Definition at line 180 of file variant.cpp.
References is_callable(), must_be(), and n.
Referenced by operator[]().
Definition at line 461 of file variant.cpp.
References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().
void wfl::variant::serialize_from_string | ( | const std::string & | str | ) |
Definition at line 628 of file variant.cpp.
References DBG_SF, wfl::formula::evaluate(), utils::get_unknown_exception_type(), and variant().
Referenced by ai::formula_ai::on_create(), and unit_formula_manager::read().
std::string wfl::variant::serialize_to_string | ( | ) | const |
Definition at line 623 of file variant.cpp.
References value_.
Referenced by wfl::variant_container< T >::get_serialized_string().
std::string wfl::variant::string_cast | ( | ) | const |
Definition at line 638 of file variant.cpp.
References value_.
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), utils::detail::evaluate_formula_impl(), and wfl::variant_container< T >::string_cast().
std::string wfl::variant::to_debug_string | ( | bool | verbose = false , |
formula_seen_stack * | seen = nullptr |
||
) | const |
Definition at line 643 of file variant.cpp.
References value_.
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), ai::formula_ai::evaluate(), wfl::formula_debugger::evaluate_arg_callback(), wfl::formula_debugger::evaluate_formula_callback(), wfl::set_unit_var_callable::execute_self(), wfl::set_var_callable::execute_self(), wfl::variant_container< T >::get_debug_string(), must_both_be(), and wfl::was_expecting().
|
inline |
Definition at line 90 of file variant.hpp.
References as_callable(), and is_callable().
Referenced by wfl::gamestate::DEFINE_WFL_FUNCTION(), wfl::set_var_callable::execute_self(), wfl::safe_call_callable::execute_self(), and luaW_pushfaivariant().
|
inlineprivate |
Definition at line 166 of file variant.hpp.
References value_.
Referenced by is_callable(), is_decimal(), is_int(), is_list(), is_map(), is_null(), is_string(), must_be(), must_both_be(), operator<(), operator==(), and type_string().
|
inline |
Gets string name of the current value type.
Definition at line 148 of file variant.hpp.
References string_enums::enum_base< Definition >::get_string(), and type().
Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), must_both_be(), and wfl::was_expecting().
|
inlineprivate |
|
private |
Variant value.
Each of the constructors initialized this with the appropriate helper class.
Definition at line 175 of file variant.hpp.
Referenced by as_bool(), begin(), end(), is_empty(), list_elements_add(), list_elements_div(), list_elements_mul(), list_elements_sub(), num_elements(), operator<(), operator==(), serialize_to_string(), string_cast(), to_debug_string(), type(), value_cast(), and variant().