The Battle for Wesnoth  1.15.1+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 (VARIANT_TYPE t) const
 
void must_both_be (VARIANT_TYPE t, const variant &second) const
 
VARIANT_TYPE type () const
 

Private Attributes

value_base_ptr value_
 Variant value. More...
 

Detailed Description

Definition at line 27 of file variant.hpp.

Member Enumeration Documentation

◆ DECIMAL_VARIANT_TYPE

Enumerator
DECIMAL_VARIANT 

Definition at line 30 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 147 of file variant.cpp.

References value_.

◆ variant() [3/10]

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

Definition at line 153 of file variant.cpp.

References value_.

◆ variant() [4/10]

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

Definition at line 159 of file variant.cpp.

References value_.

◆ variant() [5/10]

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

Definition at line 165 of file variant.cpp.

References value_.

◆ variant() [6/10]

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

Definition at line 171 of file variant.cpp.

References value_.

◆ variant() [7/10]

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

Definition at line 177 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 43 of file variant.hpp.

References get_member(), is_empty(), name(), num_elements(), operator=(), operator[](), and 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 301 of file variant.cpp.

References is_decimal(), is_int(), is_null(), value_cast(), and wfl::was_expecting().

Referenced by as_int(), wfl::builtins::DEFINE_WFL_FUNCTION(), unit_abilities::effect::effect(), is_map(), 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 325 of file variant.cpp.

References must_be(), and value_cast().

Referenced by gui2::typed_formula< bool >::execute(), is_map(), and luaW_pushfaivariant().

◆ as_map()

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

Definition at line 331 of file variant.cpp.

References must_be(), and value_cast().

Referenced by is_map(), 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 587 of file variant.cpp.

References as_int(), must_both_be(), and value_cast().

Referenced by convert_to(), and 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 594 of file variant.cpp.

References is_list(), is_map(), value_cast(), and wfl::was_expecting().

Referenced by convert_to().

◆ 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 231 of file variant.cpp.

References i, must_be(), and variant().

Referenced by convert_to(), and 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 243 of file variant.cpp.

References i, must_be(), and variant().

Referenced by convert_to(), and wfl::builtins::DEFINE_WFL_FUNCTION().

◆ is_callable()

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

Definition at line 64 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

Definition at line 62 of file variant.hpp.

References type().

Referenced by as_decimal(), execute_variant(), luaW_pushfaivariant(), and operator<().

◆ 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 537 of file variant.cpp.

References must_both_be(), value_, and value_cast().

Referenced by convert_to(), and wfl::operator_expression::execute().

◆ list_elements_div()

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

Definition at line 555 of file variant.cpp.

References must_both_be(), value_, and value_cast().

Referenced by convert_to(), and wfl::operator_expression::execute().

◆ list_elements_mul()

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

Definition at line 549 of file variant.cpp.

References must_both_be(), value_, and value_cast().

Referenced by convert_to(), and wfl::operator_expression::execute().

◆ list_elements_sub()

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

Definition at line 543 of file variant.cpp.

References must_both_be(), value_, and value_cast().

Referenced by convert_to(), and wfl::operator_expression::execute().

◆ must_be()

void wfl::variant::must_be ( VARIANT_TYPE  t) const
private

◆ must_both_be()

void wfl::variant::must_both_be ( 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 500 of file variant.cpp.

References operator==().

Referenced by convert_to().

◆ operator%()

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

Definition at line 441 of file variant.cpp.

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

Referenced by convert_to().

◆ operator*()

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

Definition at line 383 of file variant.cpp.

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

Referenced by convert_to().

◆ operator+()

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

Definition at line 337 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, is_decimal(), is_list(), is_map(), value_cast(), and variant().

Referenced by convert_to().

◆ operator-() [1/2]

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

Definition at line 374 of file variant.cpp.

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

◆ operator-() [2/2]

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

Definition at line 478 of file variant.cpp.

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

Referenced by convert_to().

◆ operator/()

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

Definition at line 406 of file variant.cpp.

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

Referenced by convert_to().

◆ operator<()

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

Definition at line 505 of file variant.cpp.

References as_decimal(), is_decimal(), is_int(), type(), and value_.

Referenced by convert_to().

◆ operator<=()

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

Definition at line 527 of file variant.cpp.

Referenced by convert_to().

◆ operator=() [1/2]

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

Referenced by variant().

◆ operator=() [2/2]

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

◆ operator==()

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

Definition at line 487 of file variant.cpp.

References as_decimal(), is_decimal(), type(), and value_.

Referenced by convert_to(), and operator!=().

◆ operator>()

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

Definition at line 532 of file variant.cpp.

Referenced by convert_to().

◆ operator>=()

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

Definition at line 522 of file variant.cpp.

Referenced by convert_to().

◆ operator[]() [1/2]

variant wfl::variant::operator[] ( std::size_t  n) const

Definition at line 183 of file variant.cpp.

References is_callable(), must_be(), n, and value_cast().

Referenced by operator[](), and variant().

◆ operator[]() [2/2]

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

◆ operator^()

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

Definition at line 462 of file variant.cpp.

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

Referenced by convert_to().

◆ 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 624 of file variant.cpp.

References value_.

Referenced by convert_to(), and wfl::variant_container< variant_vector >::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()

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 147 of file variant.hpp.

References execute_variant(), 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

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 174 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: