The Battle for Wesnoth  1.19.23+dev
Public Member Functions | Protected Types | Static Protected Member Functions | Private Attributes | List of all members
wfl::variant_container< Container > Class Template Reference

Generalized interface for container variants. More...

#include <variant_value.hpp>

Inheritance diagram for wfl::variant_container< Container >:

Public Member Functions

 variant_container (const Container &c)
 
 variant_container (Container &&c)
 
const Container & get_container () const
 
virtual bool is_empty () const override
 Whether the stored value is considered empty or not. More...
 
virtual std::size_t num_elements () const override
 Returns the number of elements in a type. More...
 
virtual bool as_bool () const override
 Returns a bool expression of the variant value. More...
 
virtual std::string string_cast () const override
 Returns the stored variant value in plain string form. More...
 
virtual std::string get_serialized_string () const override
 Returns the stored variant value in formula syntax. More...
 
virtual std::string get_debug_string (formula_seen_stack &seen, bool verbose) const override
 Returns debug info for the variant value. More...
 
virtual boost::iterator_range< variant_iteratormake_iterator () const override
 Creates an iterator pair that can be used for iteration. More...
 
virtual void iterator_inc (utils::any &) const override
 Implements the increment functionality of variant_iterator for a value of this type. More...
 
virtual void iterator_dec (utils::any &) const override
 Implements the decrement functionality of variant_iterator for a value of this type. More...
 
virtual bool iterator_equals (const utils::any &first, const utils::any &second) const override
 Implements the equality functionality of variant_iterator for a value of this type. More...
 
virtual bool equals (const variant_value_base &other) const override
 Inherited from variant_value_base. More...
 
virtual bool less_than (const variant_value_base &other) const override
 Inherited from variant_value_base. More...
 
- Public Member Functions inherited from wfl::variant_value_base
virtual formula_variant::type get_type () const
 Returns the id of the variant type. 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 ~variant_value_base ()
 

Protected Types

using iterator = typename Container::iterator
 
using const_iterator = typename Container::const_iterator
 

Static Protected Member Functions

static const_iteratoras_container_iterator (utils::any &iter)
 Casts opaque iter to a mutable const_iterator reference. More...
 
static const const_iteratoras_container_iterator (const utils::any &iter)
 Casts opaque iter to a constant const_iterator reference. More...
 

Private Attributes

Container container_
 

Additional Inherited Members

- Static Public Attributes inherited from wfl::variant_value_base
static constexpr auto value_type = formula_variant::type::null
 Each 'final' derived class should define a static type flag. More...
 

Detailed Description

template<typename Container>
class wfl::variant_container< Container >

Generalized interface for container variants.

Definition at line 387 of file variant_value.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename Container >
using wfl::variant_container< Container >::const_iterator = typename Container::const_iterator
protected

Definition at line 446 of file variant_value.hpp.

◆ iterator

template<typename Container >
using wfl::variant_container< Container >::iterator = typename Container::iterator
protected

Definition at line 445 of file variant_value.hpp.

Constructor & Destructor Documentation

◆ variant_container() [1/2]

template<typename Container >
wfl::variant_container< Container >::variant_container ( const Container &  c)
inlineexplicit

Definition at line 390 of file variant_value.hpp.

◆ variant_container() [2/2]

template<typename Container >
wfl::variant_container< Container >::variant_container ( Container &&  c)
inlineexplicit

Definition at line 395 of file variant_value.hpp.

Member Function Documentation

◆ as_bool()

template<typename Container >
virtual bool wfl::variant_container< Container >::as_bool ( ) const
inlineoverridevirtual

Returns a bool expression of the variant value.

Reimplemented from wfl::variant_value_base.

Definition at line 415 of file variant_value.hpp.

References wfl::variant_container< Container >::is_empty().

◆ as_container_iterator() [1/2]

template<typename Container >
static const const_iterator& wfl::variant_container< Container >::as_container_iterator ( const utils::any &  iter)
inlinestaticprotected

Casts opaque iter to a constant const_iterator reference.

Definition at line 455 of file variant_value.hpp.

◆ as_container_iterator() [2/2]

template<typename Container >
static const_iterator& wfl::variant_container< Container >::as_container_iterator ( utils::any &  iter)
inlinestaticprotected

Casts opaque iter to a mutable const_iterator reference.

Definition at line 449 of file variant_value.hpp.

◆ equals()

template<typename Container >
virtual bool wfl::variant_container< Container >::equals ( const variant_value_base other) const
inlineoverridevirtual

Inherited from variant_value_base.

Reimplemented from wfl::variant_value_base.

Definition at line 433 of file variant_value.hpp.

References utils::cast_as(), and wfl::variant_container< Container >::container_.

◆ get_container()

template<typename Container >
const Container& wfl::variant_container< Container >::get_container ( ) const
inline

◆ get_debug_string()

template<typename T >
std::string wfl::variant_container< T >::get_debug_string ( formula_seen_stack ,
bool   
) const
overridevirtual

Returns debug info for the variant value.

Reimplemented from wfl::variant_value_base.

Definition at line 305 of file variant_value.cpp.

References wfl::implementation::as_literal(), and wfl::variant::to_debug_string().

◆ get_serialized_string()

template<typename T >
std::string wfl::variant_container< T >::get_serialized_string
overridevirtual

Returns the stored variant value in formula syntax.

Reimplemented from wfl::variant_value_base.

Definition at line 299 of file variant_value.cpp.

References wfl::implementation::as_literal(), and wfl::variant::serialize_to_string().

◆ is_empty()

template<typename Container >
virtual bool wfl::variant_container< Container >::is_empty ( ) const
inlineoverridevirtual

Whether the stored value is considered empty or not.

Reimplemented from wfl::variant_value_base.

Definition at line 405 of file variant_value.hpp.

References wfl::variant_container< Container >::container_.

Referenced by wfl::variant_container< Container >::as_bool().

◆ iterator_dec()

template<typename T >
void wfl::variant_container< T >::iterator_dec ( utils::any &  ) const
overridevirtual

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 from wfl::variant_value_base.

Definition at line 324 of file variant_value.cpp.

◆ iterator_equals()

template<typename T >
bool wfl::variant_container< T >::iterator_equals ( const utils::any &  ,
const utils::any &   
) const
overridevirtual

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 from wfl::variant_value_base.

Definition at line 330 of file variant_value.cpp.

◆ iterator_inc()

template<typename T >
void wfl::variant_container< T >::iterator_inc ( utils::any &  ) const
overridevirtual

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 from wfl::variant_value_base.

Definition at line 318 of file variant_value.cpp.

◆ less_than()

template<typename Container >
virtual bool wfl::variant_container< Container >::less_than ( const variant_value_base other) const
inlineoverridevirtual

Inherited from variant_value_base.

Reimplemented from wfl::variant_value_base.

Definition at line 439 of file variant_value.hpp.

References utils::cast_as(), and wfl::variant_container< Container >::container_.

◆ make_iterator()

template<typename T >
boost::iterator_range< variant_iterator > wfl::variant_container< T >::make_iterator
overridevirtual

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 from wfl::variant_value_base.

Definition at line 312 of file variant_value.cpp.

References wfl::implementation::make_iterator_range().

◆ num_elements()

template<typename Container >
virtual std::size_t wfl::variant_container< Container >::num_elements ( ) const
inlineoverridevirtual

Returns the number of elements in a type.

Not relevant for every derivative.

Reimplemented from wfl::variant_value_base.

Definition at line 410 of file variant_value.hpp.

References wfl::variant_container< Container >::container_.

◆ string_cast()

template<typename T >
std::string wfl::variant_container< T >::string_cast
overridevirtual

Returns the stored variant value in plain string form.

Reimplemented from wfl::variant_value_base.

Definition at line 293 of file variant_value.cpp.

References wfl::variant::string_cast(), and wfl::implementation::to_string().

Member Data Documentation

◆ container_

template<typename Container >
Container wfl::variant_container< Container >::container_
private

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