The Battle for Wesnoth  1.19.22+dev
Public Member Functions | Static Public Attributes | List of all members
wfl::variant_value_base Class Reference

Base class for all variant types. More...

#include <variant_value.hpp>

Inheritance diagram for wfl::variant_value_base:

Public Member Functions

virtual std::size_t num_elements () const
 Returns the number of elements in a type. More...
 
virtual bool is_empty () const
 Whether the stored value is considered empty or not. More...
 
virtual std::string string_cast () const
 Returns the stored variant value in plain string form. More...
 
virtual std::string get_serialized_string () const
 Returns the stored variant value in formula syntax. More...
 
virtual std::string get_debug_string (formula_seen_stack &, bool) const
 Returns debug info for the variant value. More...
 
virtual bool as_bool () const
 Returns a bool expression of the variant value. More...
 
virtual bool equals (const variant_value_base &) const
 Called to determine if this variant is equal to another of the same type. More...
 
virtual bool less_than (const variant_value_base &) const
 Called to determine if this variant is less than another of the same type. More...
 
virtual formula_variant::type get_type () const
 Returns the id of the variant type. More...
 
virtual boost::iterator_range< variant_iteratormake_iterator () const
 Creates an iterator pair that can be used for iteration. More...
 
virtual variant deref_iterator (const utils::any &iter) const
 Implements the dereference functionality of variant_iterator for a value of this type. More...
 
virtual void iterator_inc (utils::any &) const
 Implements the increment functionality of variant_iterator for a value of this type. More...
 
virtual void iterator_dec (utils::any &) const
 Implements the decrement functionality of variant_iterator for a value of this type. More...
 
virtual bool iterator_equals (const utils::any &, const utils::any &) const
 Implements the equality functionality of variant_iterator for a value of this type. More...
 
virtual ~variant_value_base ()
 

Static Public Attributes

static constexpr auto value_type = formula_variant::type::null
 Each 'final' derived class should define a static type flag. More...
 

Detailed Description

Base class for all variant types.

This provides a common interface for all type classes to implement, as well as giving variant a base pointer type for its value member. It also serves as the implementation of the 'null' variant value.

Do note this class should not implement any data members.

Definition at line 59 of file variant_value.hpp.

Constructor & Destructor Documentation

◆ ~variant_value_base()

virtual wfl::variant_value_base::~variant_value_base ( )
inlinevirtual

Definition at line 173 of file variant_value.hpp.

Member Function Documentation

◆ as_bool()

virtual bool wfl::variant_value_base::as_bool ( ) const
inlinevirtual

◆ deref_iterator()

variant wfl::variant_value_base::deref_iterator ( const utils::any &  iter) const
virtual

Implements the dereference functionality of variant_iterator for a value of this type.

Parameters
iterThe opaque reference that was passed to the variant_iterator by make_iterator.

Reimplemented in wfl::variant_callable, wfl::variant_map, and wfl::variant_list.

Definition at line 45 of file variant_value.cpp.

Referenced by wfl::variant_iterator::operator*().

◆ equals()

virtual bool wfl::variant_value_base::equals ( const variant_value_base ) const
inlinevirtual

Called to determine if this variant is equal to another of the same type.

This function is only called if get_type() returns the same result for both arguments.

Reimplemented in wfl::variant_container< Container >, wfl::variant_container< std::vector< variant > >, wfl::variant_container< std::map< variant, variant > >, wfl::variant_string, wfl::variant_callable, and wfl::variant_numeric.

Definition at line 102 of file variant_value.hpp.

◆ get_debug_string()

virtual std::string wfl::variant_value_base::get_debug_string ( formula_seen_stack ,
bool   
) const
inlinevirtual

◆ get_serialized_string()

virtual std::string wfl::variant_value_base::get_serialized_string ( ) const
inlinevirtual

◆ get_type()

virtual formula_variant::type wfl::variant_value_base::get_type ( ) const
inlinevirtual

Returns the id of the variant type.

Definition at line 120 of file variant_value.hpp.

References value_type.

◆ is_empty()

virtual bool wfl::variant_value_base::is_empty ( ) const
inlinevirtual

◆ iterator_dec()

virtual void wfl::variant_value_base::iterator_dec ( utils::any &  ) const
inlinevirtual

Implements the decrement functionality of variant_iterator for a value of this type.

The parameter is an opaque reference that was passed to the variant_iterator by make_iterator.

Reimplemented in wfl::variant_callable, wfl::variant_container< Container >, wfl::variant_container< std::vector< variant > >, and wfl::variant_container< std::map< variant, variant > >.

Definition at line 157 of file variant_value.hpp.

Referenced by wfl::variant_iterator::operator--().

◆ iterator_equals()

virtual bool wfl::variant_value_base::iterator_equals ( const utils::any &  ,
const utils::any &   
) const
inlinevirtual

Implements the equality functionality of variant_iterator for a value of this type.

Note that this is only called if the two iterators are already known to be of the same type.

The first parameter is an opaque reference that was passed to the variant_iterator by make_iterator. The second parameter is an opaque reference that was passed to the variant_iterator by make_iterator.

Reimplemented in wfl::variant_container< Container >, wfl::variant_container< std::vector< variant > >, wfl::variant_container< std::map< variant, variant > >, and wfl::variant_callable.

Definition at line 168 of file variant_value.hpp.

Referenced by wfl::variant_iterator::operator==().

◆ iterator_inc()

virtual void wfl::variant_value_base::iterator_inc ( utils::any &  ) const
inlinevirtual

Implements the increment functionality of variant_iterator for a value of this type.

The parameter is an opaque reference that was passed to the variant_iterator by make_iterator.

Reimplemented in wfl::variant_callable, wfl::variant_container< Container >, wfl::variant_container< std::vector< variant > >, and wfl::variant_container< std::map< variant, variant > >.

Definition at line 149 of file variant_value.hpp.

Referenced by wfl::variant_iterator::operator++().

◆ less_than()

virtual bool wfl::variant_value_base::less_than ( const variant_value_base ) const
inlinevirtual

Called to determine if this variant is less than another of the same type.

This function is only called if get_type() returns the same result for both arguments.

Reimplemented in wfl::variant_container< Container >, wfl::variant_container< std::vector< variant > >, wfl::variant_container< std::map< variant, variant > >, wfl::variant_string, wfl::variant_callable, and wfl::variant_numeric.

Definition at line 111 of file variant_value.hpp.

◆ make_iterator()

boost::iterator_range< variant_iterator > wfl::variant_value_base::make_iterator ( ) const
virtual

Creates an iterator pair that can be used for iteration.

For an iterable type, it should use the two-argument constructor of variant-iterator, passing the underlying iterator as the utils::any parameter.

This creates both the begin and end iterator, but the variant implementation discards one of the two.

Reimplemented in wfl::variant_container< Container >, wfl::variant_container< std::vector< variant > >, wfl::variant_container< std::map< variant, variant > >, and wfl::variant_callable.

Definition at line 40 of file variant_value.cpp.

Referenced by wfl::variant_callable::make_iterator().

◆ num_elements()

virtual std::size_t wfl::variant_value_base::num_elements ( ) const
inlinevirtual

Returns the number of elements in a type.

Not relevant for every derivative.

Reimplemented in wfl::variant_container< Container >, wfl::variant_container< std::vector< variant > >, wfl::variant_container< std::map< variant, variant > >, and wfl::variant_callable.

Definition at line 63 of file variant_value.hpp.

◆ string_cast()

virtual std::string wfl::variant_value_base::string_cast ( ) const
inlinevirtual

Member Data Documentation

◆ value_type

constexpr auto wfl::variant_value_base::value_type = formula_variant::type::null
staticconstexpr

Each 'final' derived class should define a static type flag.

Definition at line 117 of file variant_value.hpp.

Referenced by get_type().


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