The Battle for Wesnoth  1.19.7+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 (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...
 
- 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 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 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 415 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 471 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 418 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 436 of file variant_value.hpp.

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

◆ contains()

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

Definition at line 457 of file variant_value.hpp.

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

◆ get_container() [1/2]

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

Definition at line 441 of file variant_value.hpp.

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

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

◆ get_container() [2/2]

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

Definition at line 446 of file variant_value.hpp.

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

◆ 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 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 426 of file variant_value.hpp.

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

Referenced by wfl::variant_container< T >::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 281 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 287 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 275 of file variant_value.cpp.

◆ 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 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 431 of file variant_value.hpp.

References wfl::variant_container< T >::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_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 218 of file variant_value.cpp.

Member Data Documentation

◆ container_

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

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