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

Generalized interface for container variants. More...

#include <variant_value.hpp>

Inheritance diagram for wfl::variant_container< Derived >:

Public Member Functions

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...
 
bool contains (const variant &member) const
 
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 to_string_op = std::function< std::string(const variant &)>
 

Protected Member Functions

 variant_container ()=default
 Only derived classes can instantiate this class. More...
 

Private Member Functions

std::string to_string_impl (bool annotate, bool annotate_empty, const to_string_op &mod_func) const
 String conversion helper for string_cast, get_serialized_string, and get_debug_string. More...
 
const auto & container () const
 Read-only access to the underlying container. More...
 

Static Private Member Functions

static const auto & container_for (const variant_value_base &value)
 Helper to call get_container for the derived class. More...
 

Detailed Description

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

Generalized interface for container variants.

Definition at line 408 of file variant_value.hpp.

Member Typedef Documentation

◆ to_string_op

template<typename Derived >
using wfl::variant_container< Derived >::to_string_op = std::function<std::string(const variant&)>
protected

Definition at line 462 of file variant_value.hpp.

Constructor & Destructor Documentation

◆ variant_container()

template<typename Derived >
wfl::variant_container< Derived >::variant_container ( )
protecteddefault

Only derived classes can instantiate this class.

Member Function Documentation

◆ as_bool()

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

Returns a bool expression of the variant value.

Reimplemented from wfl::variant_value_base.

Definition at line 425 of file variant_value.hpp.

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

◆ container()

template<typename Derived >
const auto& wfl::variant_container< Derived >::container ( ) const
inlineprivate

◆ container_for()

template<typename Derived >
static const auto& wfl::variant_container< Derived >::container_for ( const variant_value_base value)
inlinestaticprivate

Helper to call get_container for the derived class.

Definition at line 482 of file variant_value.hpp.

Referenced by wfl::variant_container< Derived >::container(), wfl::variant_container< Derived >::equals(), and wfl::variant_container< Derived >::less_than().

◆ contains()

template<typename Derived >
bool wfl::variant_container< Derived >::contains ( const variant member) const
inline

◆ equals()

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

Inherited from variant_value_base.

Reimplemented from wfl::variant_value_base.

Definition at line 450 of file variant_value.hpp.

References wfl::variant_container< Derived >::container_for().

◆ 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 263 of file variant_value.cpp.

References 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 257 of file variant_value.cpp.

References wfl::variant::serialize_to_string().

◆ is_empty()

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

Whether the stored value is considered empty or not.

Reimplemented from wfl::variant_value_base.

Definition at line 415 of file variant_value.hpp.

References wfl::variant_container< Derived >::container().

Referenced by wfl::variant_container< Derived >::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 284 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 290 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 278 of file variant_value.cpp.

◆ less_than()

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

Inherited from variant_value_base.

Reimplemented from wfl::variant_value_base.

Definition at line 456 of file variant_value.hpp.

References wfl::variant_container< Derived >::container_for().

◆ 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 269 of file variant_value.cpp.

◆ num_elements()

template<typename Derived >
virtual std::size_t wfl::variant_container< Derived >::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 420 of file variant_value.hpp.

References wfl::variant_container< Derived >::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 251 of file variant_value.cpp.

References wfl::variant::string_cast().

◆ to_string_impl()

template<typename T >
std::string wfl::variant_container< T >::to_string_impl ( bool  annotate,
bool  annotate_empty,
const to_string_op mod_func 
) const
private

String conversion helper for string_cast, get_serialized_string, and get_debug_string.

Derived classes should implement container-specific handling by defining a static to_string_detail function which takes the container's value_type as its first parameter and a to_string_op functor as its second.

Definition at line 218 of file variant_value.cpp.


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