The Battle for Wesnoth  1.17.4+dev
Static Public Member Functions | List of all members
string_enums::enum_base< T > Struct Template Reference

The base template for associating string values with enum values. More...

#include <enum_base.hpp>

Inheritance diagram for string_enums::enum_base< T >:

Static Public Member Functions

static std::string get_string (typename T::type key)
 Uses the int value of the provided enum to get the associated index of the values array in the implementing class. More...
 
static std::optional< typename T::type > get_enum (const std::string value)
 Convert a string into its enum equivalent. More...
 
static std::optional< typename T::type > get_enum (unsigned long value)
 Convert an int into its enum equivalent. More...
 
static constexpr std::size_t size ()
 

Detailed Description

template<typename T>
struct string_enums::enum_base< T >

The base template for associating string values with enum values.

Implementing classes should not set custom int values for their enum. The number of enum values must match the number of elements in the values array. The values the values array must be unique.

Definition at line 30 of file enum_base.hpp.

Member Function Documentation

◆ get_enum() [1/2]

template<typename T >
static std::optional<typename T::type> string_enums::enum_base< T >::get_enum ( const std::string  value)
inlinestatic

◆ get_enum() [2/2]

template<typename T >
static std::optional<typename T::type> string_enums::enum_base< T >::get_enum ( unsigned long  value)
inlinestatic

Convert an int into its enum equivalent.

Parameters
valueThe string value to convert.
Returns
The equivalent enum or std::nullopt.

Definition at line 68 of file enum_base.hpp.

References string_enums::enum_base< T >::size().

◆ get_string()

template<typename T >
static std::string string_enums::enum_base< T >::get_string ( typename T::type  key)
inlinestatic

Uses the int value of the provided enum to get the associated index of the values array in the implementing class.

Parameters
keyThe enum value to get the equivalent string for.
Returns
The string value associated to the enum value.

Definition at line 41 of file enum_base.hpp.

Referenced by BOOST_AUTO_TEST_CASE(), team::calculate_is_enemy(), ai::cfun_ai_get_targets(), wesnothd::game::change_controller_type(), game_board::check_victory(), wesnothd::game::debug_sides_info(), events::console_handler::do_controller(), unit_filter_impl::unit_filter_compound::fill(), game_classification::get_tagname(), wfl::unit_callable::get_value(), wfl::unit_type_callable::get_value(), wfl::team_callable::get_value(), wesnothd::game::handle_controller_choice(), game_lua_kernel::impl_game_config_get(), impl_mp_settings_get(), game_lua_kernel::impl_scenario_get(), impl_side_get(), impl_unit_type_get(), intf_describe_plugins(), game_launcher::load_game(), side_filter::match_internal(), operator<<(), game_launcher::play_render_image_mode(), playsingle_controller::play_side_impl(), gui2::dialogs::mp_create_game::post_show(), gui2::dialogs::mp_create_game::pre_show(), turn_info::process_network_data(), team::team_info::read(), wesnothd::game::remove_player(), preferences::set_addon_manager_saved_order_direction(), gui2::unit_preview_pane::set_displayed_type(), gui2::unit_preview_pane::set_displayed_unit(), game_board::side_drop_to(), mp_game_settings::to_config(), game_classification::to_config(), editor::map_context::to_config(), wfl::variant::type_string(), unit_alignment(), wfl::variant_type_to_string(), team::team_info::write(), and unit::write().

◆ size()

template<typename T >
static constexpr std::size_t string_enums::enum_base< T >::size ( )
inlinestatic
Returns
The size of the implementing class's values array.

Definition at line 79 of file enum_base.hpp.

Referenced by string_enums::enum_base< T >::get_enum(), and gui2::dialogs::mp_create_game::pre_show().


The documentation for this struct was generated from the following file: