The Battle for Wesnoth  1.19.5+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 utils::optional< enum_typeget_enum (const std::string_view value)
 Converts a string into its enum equivalent. More...
 
static constexpr utils::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 utils::optional<enum_type> string_enums::enum_base< Definition >::get_enum ( const std::string_view  value)
inlinestaticconstexpr

◆ get_enum() [2/2]

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

Converts an int into its enum equivalent.

Parameters
valueThe string value to convert.
Returns
The equivalent enum or utils::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 attack_type::alignment_str(), attack_info(), BOOST_AUTO_TEST_CASE(), ai::cfun_ai_get_targets(), wesnothd::game::change_controller_type(), game_board::check_victory(), wesnothd::game::debug_sides_info(), events::console_handler::do_controller(), 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(), impl_mp_settings_get(), intf_describe_plugins(), game_launcher::load_game(), gui2::dialogs::editor_edit_unit::load_unit_type(), side_filter::match_internal(), 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(), playmp_controller::process_network_side_drop_impl(), team::team_info::read(), wesnothd::game::remove_player(), prefs::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(), SIDE_GETTER(), editor::map_context::to_config(), game_classification::to_config(), mp_game_settings::to_config(), wfl::variant::type_string(), unit_alignment(), UNIT_GETTER(), UNIT_TYPE_GETTER(), 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 ( )
inlinestaticconstexpr
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: