The Battle for Wesnoth  1.17.0-dev
Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
wfl::variant_container< T > Class Template Referenceabstract

Generalized implementation handling container variants. More...

#include <variant_value.hpp>

Inheritance diagram for wfl::variant_container< T >:

Public Member Functions

 variant_container (const T &container)
 
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...
 
T & get_container ()
 
const T & get_container () const
 
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 (boost::any &) const override
 Implements the increment functionality of variant_iterator for a value of this type. More...
 
virtual void iterator_dec (boost::any &) const override
 Implements the decrement functionality of variant_iterator for a value of this type. More...
 
virtual bool iterator_equals (const boost::any &first, const boost::any &second) const override
 Implements the equality functionality of variant_iterator for a value of this type. More...
 
- Public Member Functions inherited from wfl::variant_value_base
virtual bool equals (variant_value_base &) const
 Called to determine if this variant is equal to another of the same type. More...
 
virtual bool less_than (variant_value_base &) const
 Called to determine if this variant is less than another of the same type. More...
 
virtual const VARIANT_TYPE & get_type () const
 Returns the id of the variant type. More...
 
virtual variant deref_iterator (const boost::any &iter) const
 Implements the dereference functionality of variant_iterator for a value of this type. More...
 
virtual ~variant_value_base ()
 

Protected Types

using mod_func_t = std::function< std::string(const variant &)>
 

Protected Member Functions

virtual std::string to_string_detail (const typename T::value_type &value, mod_func_t mod_func) const =0
 

Private Member Functions

std::string to_string_impl (bool annotate, bool annotate_empty, mod_func_t mod_func) const
 Implementation to handle string conversion for string_cast, get_serialized_string, and get_debug_string. More...
 

Private Attributes

container_
 

Detailed Description

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

Generalized implementation handling container variants.

This class shouldn't usually be used directly. Instead, it's better to create a new derived class specialized to a specific container type.

Definition at line 430 of file variant_value.hpp.

Member Typedef Documentation

◆ mod_func_t

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

Definition at line 486 of file variant_value.hpp.

Constructor & Destructor Documentation

◆ variant_container()

template<typename T>
wfl::variant_container< T >::variant_container ( const T &  container)
inlineexplicit

Definition at line 433 of file variant_value.hpp.

Member Function Documentation

◆ as_bool()

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

Returns a bool expression of the variant value.

Reimplemented from wfl::variant_value_base.

Definition at line 451 of file variant_value.hpp.

◆ contains()

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

Definition at line 472 of file variant_value.hpp.

◆ get_container() [1/2]

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

Definition at line 456 of file variant_value.hpp.

◆ get_container() [2/2]

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

Definition at line 461 of file variant_value.hpp.

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

◆ get_serialized_string()

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

Returns the stored variant value in formula syntax.

Reimplemented from wfl::variant_value_base.

Definition at line 255 of file variant_value.cpp.

◆ is_empty()

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

Whether the stored value is considered empty or not.

Reimplemented from wfl::variant_value_base.

Definition at line 441 of file variant_value.hpp.

◆ iterator_dec()

template<typename T >
void wfl::variant_container< T >::iterator_dec ( boost::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 279 of file variant_value.cpp.

◆ iterator_equals()

template<typename T >
bool wfl::variant_container< T >::iterator_equals ( const boost::any &  ,
const boost::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 285 of file variant_value.cpp.

◆ iterator_inc()

template<typename T >
void wfl::variant_container< T >::iterator_inc ( boost::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 273 of file variant_value.cpp.

◆ make_iterator()

template<typename T >
boost::iterator_range< variant_iterator > wfl::variant_container< T >::make_iterator ( ) const
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 boost::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 267 of file variant_value.cpp.

◆ num_elements()

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

◆ string_cast()

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

Returns the stored variant value in plain string form.

Reimplemented from wfl::variant_value_base.

Definition at line 249 of file variant_value.cpp.

◆ to_string_detail()

template<typename T>
virtual std::string wfl::variant_container< T >::to_string_detail ( const typename T::value_type &  value,
mod_func_t  mod_func 
) const
protectedpure virtual

◆ to_string_impl()

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

Implementation to handle string conversion for string_cast, get_serialized_string, and get_debug_string.

Derived classes should provide type-specific value handling by implementing to_string_detail.

Definition at line 216 of file variant_value.cpp.

Member Data Documentation

◆ container_

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

Definition at line 499 of file variant_value.hpp.


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