The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
variant Class Reference

#include <variant.hpp>

Public Types

enum  TYPE {
  TYPE_NULL, TYPE_INT, TYPE_DECIMAL, TYPE_CALLABLE,
  TYPE_LIST, TYPE_STRING, TYPE_MAP
}
 
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 game_logic::formula_callable *callable)
 
 variant (std::vector< variant > *array)
 
 variant (const std::string &str)
 
 variant (std::map< variant, variant > *map)
 
 ~variant ()
 
 variant (const variant &v)
 
variantoperator= (const variant &v)
 
variant operator[] (size_t n) const
 
variant operator[] (const variant &v) const
 
size_t num_elements () const
 
bool is_empty () const
 
variant get_member (const std::string &str) const
 
bool is_string () const
 
bool is_null () const
 
bool is_int () const
 
bool is_decimal () const
 
bool is_map () const
 
int as_int () const
 
int as_decimal () const
 
bool as_bool () const
 
bool is_list () const
 
const std::vector< variant > & as_list () const
 
const std::map< variant,
variant > & 
as_map () const
 
const std::stringas_string () const
 
std::string type_string () const
 
bool is_callable () const
 
const
game_logic::formula_callable
as_callable () const
 
game_logic::formula_callablemutable_callable () const
 
template<typename T >
T * try_convert () const
 
template<typename T >
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
 
void serialize_to_string (std::string &str) const
 
void serialize_from_string (const std::string &str)
 
int refcount () const
 
std::string string_cast () const
 
std::string to_debug_string (std::vector< const game_logic::formula_callable * > *seen=nullptr, bool verbose=false) const
 

Private Member Functions

void must_be (TYPE t) const
 
void increment_refcount ()
 
void release ()
 

Private Attributes

TYPE type_
 
union {
   int   int_value_
 
   int   decimal_value_
 
   const
game_logic::formula_callable *   callable_
 
   game_logic::formula_callable *   mutable_callable_
 
   variant_list *   list_
 
   variant_string *   string_
 
   variant_map *   map_
 
}; 
 

Detailed Description

Definition at line 52 of file variant.hpp.

Member Enumeration Documentation

Enumerator
DECIMAL_VARIANT 

Definition at line 57 of file variant.hpp.

Enumerator
TYPE_NULL 
TYPE_INT 
TYPE_DECIMAL 
TYPE_CALLABLE 
TYPE_LIST 
TYPE_STRING 
TYPE_MAP 

Definition at line 55 of file variant.hpp.

Constructor & Destructor Documentation

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

Definition at line 346 of file variant.cpp.

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

Definition at line 349 of file variant.cpp.

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

Definition at line 352 of file variant.cpp.

References decimal_value_.

variant::variant ( const game_logic::formula_callable callable)
explicit

Definition at line 364 of file variant.cpp.

References callable_, and increment_refcount().

variant::variant ( std::vector< variant > *  array)
explicit

Definition at line 371 of file variant.cpp.

References variant_list::elements, increment_refcount(), and list_.

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

Definition at line 380 of file variant.cpp.

References increment_refcount(), variant_string::str, and string_.

variant::variant ( std::map< variant, variant > *  map)
explicit

Definition at line 388 of file variant.cpp.

References variant_map::elements, increment_refcount(), and map_.

variant::~variant ( )

Definition at line 404 of file variant.cpp.

References release().

variant::variant ( const variant v)

Definition at line 397 of file variant.cpp.

References increment_refcount().

Member Function Documentation

bool variant::as_bool ( ) const
const game_logic::formula_callable* variant::as_callable ( ) const
inline
int variant::as_decimal ( ) const
int variant::as_int ( ) const
const std::vector< variant > & variant::as_list ( ) const

Definition at line 610 of file variant.cpp.

References variant_list::elements, list_, must_be(), and TYPE_LIST.

Referenced by luaW_pushfaivariant().

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

Definition at line 617 of file variant.cpp.

References variant_map::elements, map_, must_be(), and TYPE_MAP.

Referenced by luaW_pushfaivariant().

const std::string & variant::as_string ( ) const
variant_iterator variant::begin ( ) const
variant variant::build_range ( const variant v) const

Definition at line 1001 of file variant.cpp.

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

variant variant::concatenate ( const variant v) const
bool variant::contains ( const variant other) const
template<typename T >
T* variant::convert_to ( ) const
inline

Definition at line 116 of file variant.hpp.

References mutable_callable().

variant_iterator variant::end ( ) const
variant variant::get_keys ( ) const

Definition at line 468 of file variant.cpp.

References variant_map::elements, i, map_, must_be(), TYPE_MAP, and variant().

variant variant::get_member ( const std::string str) const
variant variant::get_values ( ) const

Definition at line 479 of file variant.cpp.

References variant_map::elements, i, map_, must_be(), TYPE_MAP, and variant().

void variant::increment_refcount ( )
private
bool variant::is_callable ( ) const
inline

Definition at line 100 of file variant.hpp.

References type_, and TYPE_CALLABLE.

Referenced by get_member(), luaW_pushfaivariant(), try_convert(), and try_convert_variant().

bool variant::is_decimal ( ) const
inline

Definition at line 82 of file variant.hpp.

References type_, and TYPE_DECIMAL.

Referenced by luaW_pushfaivariant().

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

Definition at line 81 of file variant.hpp.

References type_, and TYPE_INT.

Referenced by luaW_pushfaivariant().

bool variant::is_list ( ) const
inline

Definition at line 92 of file variant.hpp.

References type_, and TYPE_LIST.

Referenced by ai::formula_ai::execute_variant(), luaW_pushfaivariant(), and operator[]().

bool variant::is_map ( ) const
inline

Definition at line 83 of file variant.hpp.

References type_, and TYPE_MAP.

Referenced by luaW_pushfaivariant().

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

Definition at line 79 of file variant.hpp.

References type_, and TYPE_STRING.

Referenced by ai::formula_ai::execute_variant(), and luaW_pushfaivariant().

variant variant::list_elements_add ( const variant v) const

Definition at line 899 of file variant.cpp.

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

variant variant::list_elements_div ( const variant v) const

Definition at line 953 of file variant.cpp.

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

variant variant::list_elements_mul ( const variant v) const

Definition at line 935 of file variant.cpp.

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

variant variant::list_elements_sub ( const variant v) const

Definition at line 917 of file variant.cpp.

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

void variant::must_be ( variant::TYPE  t) const
private
game_logic::formula_callable* variant::mutable_callable ( ) const
inline

Definition at line 103 of file variant.hpp.

References must_be(), mutable_callable_, and TYPE_CALLABLE.

Referenced by convert_to(), convert_variant(), try_convert(), and try_convert_variant().

size_t variant::num_elements ( ) const
bool variant::operator!= ( const variant v) const

Definition at line 824 of file variant.cpp.

References operator==().

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

Definition at line 726 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, type_, TYPE_DECIMAL, and variant().

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

Definition at line 670 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, type_, TYPE_DECIMAL, and variant().

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

Definition at line 661 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, type_, TYPE_DECIMAL, and variant().

variant variant::operator- ( ) const

Definition at line 763 of file variant.cpp.

References as_int(), decimal_value_, DECIMAL_VARIANT, type_, TYPE_DECIMAL, and variant().

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

Definition at line 692 of file variant.cpp.

References as_decimal(), as_int(), DECIMAL_VARIANT, type_, TYPE_DECIMAL, and variant().

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

Definition at line 889 of file variant.cpp.

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

Definition at line 409 of file variant.cpp.

References increment_refcount(), and release().

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

Definition at line 894 of file variant.cpp.

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

Definition at line 884 of file variant.cpp.

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

Definition at line 419 of file variant.cpp.

References variant_list::elements, list_, must_be(), type_, TYPE_CALLABLE, and TYPE_LIST.

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

variant variant::operator[] ( const variant v) const
variant variant::operator^ ( const variant v) const
int variant::refcount ( ) const
void variant::release ( )
private
void variant::serialize_from_string ( const std::string str)
void variant::serialize_to_string ( std::string str) const
std::string variant::string_cast ( ) const
std::string variant::to_debug_string ( std::vector< const game_logic::formula_callable * > *  seen = nullptr,
bool  verbose = false 
) const
template<typename T >
T* variant::try_convert ( ) const
inline

Definition at line 107 of file variant.hpp.

References is_callable(), and mutable_callable().

Referenced by luaW_pushfaivariant().

std::string variant::type_string ( ) const

Definition at line 339 of file variant.cpp.

References type_.

Referenced by as_decimal(), concatenate(), must_be(), num_elements(), and operator[]().

Member Data Documentation

union { ... }
const game_logic::formula_callable* variant::callable_
int variant::decimal_value_
int variant::int_value_
variant_list* variant::list_
variant_map* variant::map_
game_logic::formula_callable* variant::mutable_callable_

Definition at line 170 of file variant.hpp.

Referenced by mutable_callable().

variant_string* variant::string_
TYPE variant::type_
private

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