mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::string_view for 'x-of-many' settings
parent
7805c1c189
commit
5c7b04a0c2
|
@ -184,7 +184,7 @@ const uint16_t INIFILE_VERSION = (IniFileVersion)(IFV_MAX_VERSION - 1); ///< Cur
|
|||
* @param many full domain of values the ONEofMANY setting can have
|
||||
* @return the integer index of the full-list, or std::nullopt if not found
|
||||
*/
|
||||
std::optional<uint32_t> OneOfManySettingDesc::ParseSingleValue(std::string_view str, const std::vector<std::string> &many)
|
||||
std::optional<uint32_t> OneOfManySettingDesc::ParseSingleValue(std::string_view str, std::span<const std::string_view> many)
|
||||
{
|
||||
StringConsumer consumer{str};
|
||||
auto digit = consumer.TryReadIntegerBase<uint32_t>(10);
|
||||
|
@ -217,7 +217,7 @@ std::optional<bool> BoolSettingDesc::ParseSingleValue(std::string_view str)
|
|||
* of separated by a whitespace, tab or | character
|
||||
* @return the 'fully' set integer, or std::nullopt if a set is not found
|
||||
*/
|
||||
static std::optional<uint32_t> LookupManyOfMany(const std::vector<std::string> &many, std::string_view str)
|
||||
static std::optional<uint32_t> LookupManyOfMany(std::span<const std::string_view> many, std::string_view str)
|
||||
{
|
||||
static const std::string_view separators{" \t|"};
|
||||
|
||||
|
@ -334,7 +334,7 @@ std::string OneOfManySettingDesc::FormatSingleValue(uint id) const
|
|||
if (id >= this->many.size()) {
|
||||
return fmt::format("{}", id);
|
||||
}
|
||||
return this->many[id];
|
||||
return std::string{this->many[id]};
|
||||
}
|
||||
|
||||
std::string OneOfManySettingDesc::FormatValue(const void *object) const
|
||||
|
@ -1425,7 +1425,7 @@ void LoadFromConfig(bool startup)
|
|||
}
|
||||
|
||||
if (generic_version < IFV_AUTOSAVE_RENAME && IsConversionNeeded(generic_ini, "gui", "autosave", "autosave_interval", &old_item)) {
|
||||
static std::vector<std::string> _old_autosave_interval{"off", "monthly", "quarterly", "half year", "yearly"};
|
||||
static std::vector<std::string_view> _old_autosave_interval{"off", "monthly", "quarterly", "half year", "yearly"};
|
||||
auto old_value = OneOfManySettingDesc::ParseSingleValue(*old_item->value, _old_autosave_interval).value_or(-1);
|
||||
|
||||
switch (old_value) {
|
||||
|
|
|
@ -274,17 +274,17 @@ struct OneOfManySettingDesc : IntSettingDesc {
|
|||
Tmax max, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
|
||||
PreChangeCheck pre_check, PostChangeCallback post_callback,
|
||||
GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
|
||||
GetDefaultValueCallback get_def_cb, std::initializer_list<const char *> many, OnConvert *many_cnvt) :
|
||||
GetDefaultValueCallback get_def_cb, std::initializer_list<std::string_view> many, OnConvert *many_cnvt) :
|
||||
IntSettingDesc(save, flags, startup, def, 0, max, 0, str, str_help, str_val, cat,
|
||||
pre_check, post_callback, get_title_cb, get_help_cb, get_value_params_cb, get_def_cb, nullptr), many_cnvt(many_cnvt)
|
||||
{
|
||||
for (auto one : many) this->many.push_back(one);
|
||||
}
|
||||
|
||||
std::vector<std::string> many; ///< possible values for this type
|
||||
std::vector<std::string_view> many; ///< possible values for this type
|
||||
OnConvert *many_cnvt; ///< callback procedure when loading value mechanism fails
|
||||
|
||||
static std::optional<uint32_t> ParseSingleValue(std::string_view str, const std::vector<std::string> &many);
|
||||
static std::optional<uint32_t> ParseSingleValue(std::string_view str, std::span<const std::string_view> many);
|
||||
std::string FormatSingleValue(uint id) const;
|
||||
|
||||
int32_t ParseValue(std::string_view str) const override;
|
||||
|
@ -298,7 +298,7 @@ struct ManyOfManySettingDesc : OneOfManySettingDesc {
|
|||
Tdef def, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
|
||||
PreChangeCheck pre_check, PostChangeCallback post_callback,
|
||||
GetTitleCallback get_title_cb, GetHelpCallback get_help_cb, GetValueParamsCallback get_value_params_cb,
|
||||
GetDefaultValueCallback get_def_cb, std::initializer_list<const char *> many, OnConvert *many_cnvt) :
|
||||
GetDefaultValueCallback get_def_cb, std::initializer_list<std::string_view> many, OnConvert *many_cnvt) :
|
||||
OneOfManySettingDesc(save, flags, startup, def, (1 << many.size()) - 1, str, str_help,
|
||||
str_val, cat, pre_check, post_callback, get_title_cb, get_help_cb, get_value_params_cb, get_def_cb, many, many_cnvt) {}
|
||||
|
||||
|
|
|
@ -448,7 +448,7 @@ static bool CheckRoadSide(int32_t &)
|
|||
static std::optional<uint32_t> ConvertLandscape(std::string_view value)
|
||||
{
|
||||
/* try with the old values */
|
||||
static std::vector<std::string> _old_landscape_values{"normal", "hilly", "desert", "candy"};
|
||||
static std::vector<std::string_view> _old_landscape_values{"normal", "hilly", "desert", "candy"};
|
||||
return OneOfManySettingDesc::ParseSingleValue(value, _old_landscape_values);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ static void TownFoundingChanged(int32_t new_value);
|
|||
static void ChangeTimekeepingUnits(int32_t new_value);
|
||||
static void ChangeMinutesPerYear(int32_t new_value);
|
||||
|
||||
static constexpr std::initializer_list<const char*> _place_houses{"forbidden", "allowed", "fully constructed"};
|
||||
static constexpr std::initializer_list<std::string_view> _place_houses{"forbidden"sv, "allowed"sv, "fully constructed"sv};
|
||||
|
||||
static const SettingVariant _economy_settings_table[] = {
|
||||
[post-amble]
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
; Game settings are everything related to vehicles, stations, orders, etc.
|
||||
|
||||
[pre-amble]
|
||||
static constexpr std::initializer_list<const char*> _roadsides{"left", "right"};
|
||||
static constexpr std::initializer_list<std::string_view> _roadsides{"left"sv, "right"sv};
|
||||
|
||||
static void StationSpreadChanged(int32_t new_value);
|
||||
static void UpdateConsists(int32_t new_value);
|
||||
|
|
|
@ -17,9 +17,9 @@ static void InvalidateNewGRFChangeWindows(int32_t new_value);
|
|||
static void ZoomMinMaxChanged(int32_t new_value);
|
||||
static void SpriteZoomMinChanged(int32_t new_value);
|
||||
|
||||
static constexpr std::initializer_list<const char*> _osk_activation{"disabled", "double", "single", "immediately"};
|
||||
static constexpr std::initializer_list<const char*> _savegame_date{"long", "short", "iso"};
|
||||
static constexpr std::initializer_list<const char*> _right_click_close{"no", "yes", "except sticky"};
|
||||
static constexpr std::initializer_list<std::string_view> _osk_activation{"disabled"sv, "double"sv, "single"sv, "immediately"sv};
|
||||
static constexpr std::initializer_list<std::string_view> _savegame_date{"long"sv, "short"sv, "iso"sv};
|
||||
static constexpr std::initializer_list<std::string_view> _right_click_close{"no"sv, "yes"sv, "except sticky"sv};
|
||||
|
||||
static const SettingVariant _gui_settings_table[] = {
|
||||
[post-amble]
|
||||
|
|
|
@ -12,8 +12,8 @@ static std::pair<StringParameter, StringParameter> SettingsValueVelocityUnit(con
|
|||
|
||||
uint8_t _old_units; ///< Old units from old savegames
|
||||
|
||||
static constexpr std::initializer_list<const char*> _locale_currencies{"GBP", "USD", "EUR", "JPY", "ATS", "BEF", "CHF", "CZK", "DEM", "DKK", "ESP", "FIM", "FRF", "GRD", "HUF", "ISK", "ITL", "NLG", "NOK", "PLN", "RON", "RUR", "SIT", "SEK", "TRY", "SKK", "BRL", "EEK", "LTL", "KRW", "ZAR", "custom", "GEL", "IRR", "RUB", "MXN", "NTD", "CNY", "HKD", "INR", "IDR", "MYR", "LVL", "PTE", "UAH"};
|
||||
static constexpr std::initializer_list<const char*> _locale_units{"imperial", "metric", "si", "gameunits", "knots"};
|
||||
static constexpr std::initializer_list<std::string_view> _locale_currencies{"GBP"sv, "USD"sv, "EUR"sv, "JPY"sv, "ATS"sv, "BEF"sv, "CHF"sv, "CZK"sv, "DEM"sv, "DKK"sv, "ESP"sv, "FIM"sv, "FRF"sv, "GRD"sv, "HUF"sv, "ISK"sv, "ITL"sv, "NLG"sv, "NOK"sv, "PLN"sv, "RON"sv, "RUR"sv, "SIT"sv, "SEK"sv, "TRY"sv, "SKK"sv, "BRL"sv, "EEK"sv, "LTL"sv, "KRW"sv, "ZAR"sv, "custom"sv, "GEL"sv, "IRR"sv, "RUB"sv, "MXN"sv, "NTD"sv, "CNY"sv, "HKD"sv, "INR"sv, "IDR"sv, "MYR"sv, "LVL"sv, "PTE"sv, "UAH"sv};
|
||||
static constexpr std::initializer_list<std::string_view> _locale_units{"imperial"sv, "metric"sv, "si"sv, "gameunits"sv, "knots"sv};
|
||||
|
||||
static_assert(_locale_currencies.size() == CURRENCY_END);
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
[pre-amble]
|
||||
extern std::string _config_language_file;
|
||||
|
||||
static constexpr std::initializer_list<const char*> _support8bppmodes{"no", "system", "hardware"};
|
||||
static constexpr std::initializer_list<const char*> _display_opt_modes{"SHOW_TOWN_NAMES", "SHOW_STATION_NAMES", "SHOW_SIGNS", "FULL_ANIMATION", "", "FULL_DETAIL", "WAYPOINTS", "SHOW_COMPETITOR_SIGNS"};
|
||||
static constexpr std::initializer_list<const char*> _facility_display_opt_modes{"TRAIN", "TRUCK_STOP", "BUS_STOP", "AIRPORT", "DOCK", "", "GHOST"};
|
||||
static constexpr std::initializer_list<std::string_view> _support8bppmodes{"no"sv, "system"sv, "hardware"sv};
|
||||
static constexpr std::initializer_list<std::string_view> _display_opt_modes{"SHOW_TOWN_NAMES"sv, "SHOW_STATION_NAMES"sv, "SHOW_SIGNS"sv, "FULL_ANIMATION"sv, ""sv, "FULL_DETAIL"sv, "WAYPOINTS"sv, "SHOW_COMPETITOR_SIGNS"sv};
|
||||
static constexpr std::initializer_list<std::string_view> _facility_display_opt_modes{"TRAIN"sv, "TRUCK_STOP"sv, "BUS_STOP"sv, "AIRPORT"sv, "DOCK"sv, ""sv, "GHOST"sv};
|
||||
|
||||
#ifdef WITH_COCOA
|
||||
extern bool _allow_hidpi_window;
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
; Network settings as stored in the private configuration file ("private.cfg").
|
||||
|
||||
[pre-amble]
|
||||
static constexpr std::initializer_list<const char*> _use_relay_service{"never", "ask", "allow"};
|
||||
static constexpr std::initializer_list<const char*> _participate_survey{"ask", "no", "yes"};
|
||||
static constexpr std::initializer_list<std::string_view> _use_relay_service{"never"sv, "ask"sv, "allow"sv};
|
||||
static constexpr std::initializer_list<std::string_view> _participate_survey{"ask"sv, "no"sv, "yes"sv};
|
||||
|
||||
static const SettingVariant _network_private_settings_table[] = {
|
||||
[post-amble]
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
static void UpdateClientConfigValues();
|
||||
void ChangeNetworkRestartTime(bool reset);
|
||||
|
||||
static constexpr std::initializer_list<const char*> _server_game_type{"local", "public", "invite-only"};
|
||||
static constexpr std::initializer_list<std::string_view> _server_game_type{"local"sv, "public"sv, "invite-only"sv};
|
||||
|
||||
static const SettingVariant _network_settings_table[] = {
|
||||
[post-amble]
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
; News display settings as stored in the main configuration file ("openttd.cfg").
|
||||
|
||||
[pre-amble]
|
||||
static constexpr std::initializer_list<const char*> _news_display{ "off", "summarized", "full"};
|
||||
static constexpr std::initializer_list<std::string_view> _news_display{"off"sv, "summarized"sv, "full"sv};
|
||||
|
||||
static const SettingVariant _news_display_settings_table[] = {
|
||||
[post-amble]
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
; be saved in their new place.
|
||||
|
||||
[pre-amble]
|
||||
static constexpr std::initializer_list<const char*> _town_names{"english", "french", "german", "american", "latin", "silly", "swedish", "dutch", "finnish", "polish", "slovak", "norwegian", "hungarian", "austrian", "romanian", "czech", "swiss", "danish", "turkish", "italian", "catalan"};
|
||||
static constexpr std::initializer_list<const char*> _climates{"temperate", "arctic", "tropic", "toyland"};
|
||||
static constexpr std::initializer_list<std::string_view> _town_names{"english"sv, "french"sv, "german"sv, "american"sv, "latin"sv, "silly"sv, "swedish"sv, "dutch"sv, "finnish"sv, "polish"sv, "slovak"sv, "norwegian"sv, "hungarian"sv, "austrian"sv, "romanian"sv, "czech"sv, "swiss"sv, "danish"sv, "turkish"sv, "italian"sv, "catalan"sv};
|
||||
static constexpr std::initializer_list<std::string_view> _climates{"temperate"sv, "arctic"sv, "tropic"sv, "toyland"sv};
|
||||
|
||||
static const SettingVariant _old_gameopt_settings_table[] = {
|
||||
/* In version 4 a new difficulty setting has been added to the difficulty settings,
|
||||
|
|
Loading…
Reference in New Issue