The Battle for Wesnoth  1.19.7+dev
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
wfl::variant Class Reference

#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)
 
variantoperator= (const variant &v)=default
 
variantoperator= (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...
 

Detailed Description

Definition at line 28 of file variant.hpp.

Member Enumeration Documentation

◆ DECIMAL_VARIANT_TYPE

Enumerator
DECIMAL_VARIANT 

Definition at line 31 of file variant.hpp.

Constructor & Destructor Documentation

◆ variant() [1/10]

wfl::variant::variant ( )

◆ variant() [2/10]

wfl::variant::variant ( int  n)
explicit

Definition at line 144 of file variant.cpp.

References value_.

◆ variant() [3/10]

wfl::variant::variant ( int  n,
variant::DECIMAL_VARIANT_TYPE   
)

Definition at line 150 of file variant.cpp.

References value_.

◆ variant() [4/10]

wfl::variant::variant ( double  n,
variant::DECIMAL_VARIANT_TYPE   
)

Definition at line 156 of file variant.cpp.

References value_.

◆ variant() [5/10]

wfl::variant::variant ( const std::vector< variant > &  array)
explicit

Definition at line 162 of file variant.cpp.

References value_.

◆ variant() [6/10]

wfl::variant::variant ( const std::string &  str)
explicit

Definition at line 168 of file variant.cpp.

References value_.

◆ variant() [7/10]

wfl::variant::variant ( const std::map< variant, variant > &  map)
explicit

Definition at line 174 of file variant.cpp.

References value_.

◆ variant() [8/10]

wfl::variant::variant ( const variant v)
default

◆ variant() [9/10]

wfl::variant::variant ( variant &&  v)
default

◆ variant() [10/10]

template<typename T >
wfl::variant::variant ( std::shared_ptr< T >  callable)
inline

Definition at line 44 of file variant.hpp.

References value_.

Member Function Documentation

◆ as_bool()

bool wfl::variant::as_bool ( ) const

◆ as_callable()

const_formula_callable_ptr wfl::variant::as_callable ( ) const
inline

◆ as_decimal()

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^().

◆ as_int()

int wfl::variant::as_int ( ) const

◆ as_list()

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().

◆ as_map()

const std::map< variant, variant > & wfl::variant::as_map ( ) const

Definition at line 330 of file variant.cpp.

References must_be().

Referenced by wfl::map_callable::get_value(), and luaW_pushfaivariant().

◆ as_string()

const std::string & wfl::variant::as_string ( ) const

◆ begin()

variant_iterator wfl::variant::begin ( ) const

◆ build_range()

variant wfl::variant::build_range ( const variant v) const

Definition at line 586 of file variant.cpp.

References as_int(), and must_both_be().

Referenced by wfl::operator_expression::execute().

◆ concatenate()

variant wfl::variant::concatenate ( const variant v) const

◆ contains()

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().

◆ convert_to()

template<typename T >
std::shared_ptr<T> wfl::variant::convert_to ( ) const
inline

◆ end()

variant_iterator wfl::variant::end ( ) const

◆ execute_variant()

variant wfl::variant::execute_variant ( const variant to_exec)

◆ get_keys()

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().

◆ get_member()

variant wfl::variant::get_member ( const std::string &  name) const

◆ get_values()

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().

◆ is_callable()

bool wfl::variant::is_callable ( ) const
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().

◆ is_decimal()

bool wfl::variant::is_decimal ( ) const
inline

◆ is_empty()

bool wfl::variant::is_empty ( ) const

◆ is_int()

bool wfl::variant::is_int ( ) const
inline

◆ is_list()

bool wfl::variant::is_list ( ) const
inline

◆ is_map()

bool wfl::variant::is_map ( ) const
inline

◆ is_null()

bool wfl::variant::is_null ( ) const
inline

◆ is_string()

bool wfl::variant::is_string ( ) const
inline

◆ list_elements_add()

variant wfl::variant::list_elements_add ( const variant v) const

Definition at line 536 of file variant.cpp.

References must_both_be(), and value_.

Referenced by wfl::operator_expression::execute().

◆ list_elements_div()

variant wfl::variant::list_elements_div ( const variant v) const

Definition at line 554 of file variant.cpp.

References must_both_be(), and value_.

Referenced by wfl::operator_expression::execute().

◆ list_elements_mul()

variant wfl::variant::list_elements_mul ( const variant v) const

Definition at line 548 of file variant.cpp.

References must_both_be(), and value_.

Referenced by wfl::operator_expression::execute().

◆ list_elements_sub()

variant wfl::variant::list_elements_sub ( const variant v) const

Definition at line 542 of file variant.cpp.

References must_both_be(), and value_.

Referenced by wfl::operator_expression::execute().

◆ must_be()

void wfl::variant::must_be ( formula_variant::type  t) const
private

◆ must_both_be()

void wfl::variant::must_both_be ( formula_variant::type  t,
const variant second 
) const
private

◆ num_elements()

std::size_t wfl::variant::num_elements ( ) const

◆ operator!=()

bool wfl::variant::operator!= ( const variant v) const

Definition at line 499 of file variant.cpp.

References operator==().

◆ operator%()

variant wfl::variant::operator% ( const variant v) const

Definition at line 440 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().

◆ operator*()

variant wfl::variant::operator* ( const variant v) const

Definition at line 382 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().

◆ operator+()

variant wfl::variant::operator+ ( const variant v) const

◆ operator-() [1/2]

variant wfl::variant::operator- ( ) const

Definition at line 477 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().

◆ operator-() [2/2]

variant wfl::variant::operator- ( const variant v) const

Definition at line 373 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().

◆ operator/()

variant wfl::variant::operator/ ( const variant v) const

Definition at line 405 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().

◆ operator<()

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_.

◆ operator<=()

bool wfl::variant::operator<= ( const variant v) const

Definition at line 526 of file variant.cpp.

◆ operator=() [1/2]

variant& wfl::variant::operator= ( const variant v)
default

◆ operator=() [2/2]

variant& wfl::variant::operator= ( variant &&  v)
default

◆ operator==()

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!=().

◆ operator>()

bool wfl::variant::operator> ( const variant v) const

Definition at line 531 of file variant.cpp.

◆ operator>=()

bool wfl::variant::operator>= ( const variant v) const

Definition at line 521 of file variant.cpp.

◆ operator[]() [1/2]

variant wfl::variant::operator[] ( const variant v) const

◆ operator[]() [2/2]

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[]().

◆ operator^()

variant wfl::variant::operator^ ( const variant v) const

Definition at line 461 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), and variant().

◆ serialize_from_string()

void wfl::variant::serialize_from_string ( const std::string &  str)

◆ serialize_to_string()

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().

◆ string_cast()

std::string wfl::variant::string_cast ( ) const

◆ to_debug_string()

std::string wfl::variant::to_debug_string ( bool  verbose = false,
formula_seen_stack seen = nullptr 
) const

◆ try_convert()

template<typename T >
std::shared_ptr<T> wfl::variant::try_convert ( ) const
inline

◆ type()

formula_variant::type wfl::variant::type ( ) const
inlineprivate

◆ type_string()

std::string wfl::variant::type_string ( ) const
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().

◆ value_cast()

template<typename T >
std::shared_ptr<T> wfl::variant::value_cast ( ) const
inlineprivate

Definition at line 157 of file variant.hpp.

References value_.

Referenced by operator+().

Member Data Documentation

◆ value_

value_base_ptr wfl::variant::value_
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().


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