The Battle for Wesnoth  1.17.10+dev
Public Types | Static Public Member Functions | List of all members
string_enums::enum_base< Definition > 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< Definition >:

Public Types

using enum_type = typename Definition::type
 
template<typename T >
using sized_array = std::array< T, size()>
 Provide a alias template for an array of matching size. More...
 

Static Public Member Functions

static std::string get_string (enum_type key)
 Converts a enum to its string equivalent. More...
 
static constexpr std::optional< enum_typeget_enum (const std::string_view value)
 Converts a string into its enum equivalent. More...
 
static constexpr std::optional< enum_typeget_enum (unsigned long value)
 Converts an int into its enum equivalent. More...
 
static constexpr std::size_t size ()
 

Detailed Description

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

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 32 of file enum_base.hpp.

Member Typedef Documentation

◆ enum_type

template<typename Definition >
using string_enums::enum_base< Definition >::enum_type = typename Definition::type

Definition at line 34 of file enum_base.hpp.

◆ sized_array

template<typename Definition >
template<typename T >
using string_enums::enum_base< Definition >::sized_array = std::array<T, size()>

Provide a alias template for an array of matching size.

Definition at line 92 of file enum_base.hpp.

Member Function Documentation

◆ get_enum() [1/2]

template<typename Definition >
static constexpr std::optional<enum_type> string_enums::enum_base< Definition >::get_enum ( const std::string_view  value)
inlinestatic

◆ get_enum() [2/2]

template<typename Definition >
static constexpr std::optional<enum_type> string_enums::enum_base< Definition >::get_enum ( unsigned long  value)
inlinestatic

Converts an int into its enum equivalent.

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

Definition at line 73 of file enum_base.hpp.

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

◆ get_string()

template<typename Definition >
static std::string string_enums::enum_base< Definition >::get_string ( enum_type  key)
inlinestatic

Converts a enum to its string equivalent.

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

Definition at line 46 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 Definition >
static constexpr std::size_t string_enums::enum_base< Definition >::size ( )
inlinestatic
Returns
The size of the implementing class's values array.

Definition at line 85 of file enum_base.hpp.

Referenced by string_enums::enum_base< Definition >::get_enum().


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