mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::string_view to set string settings
parent
fdb8defa64
commit
b279bc37e7
|
@ -1877,16 +1877,16 @@ void SyncCompanySettings()
|
||||||
* @param force_newgame force the newgame settings
|
* @param force_newgame force the newgame settings
|
||||||
* @note Strings WILL NOT be synced over the network
|
* @note Strings WILL NOT be synced over the network
|
||||||
*/
|
*/
|
||||||
bool SetSettingValue(const StringSettingDesc *sd, std::string value, bool force_newgame)
|
bool SetSettingValue(const StringSettingDesc *sd, std::string_view value, bool force_newgame)
|
||||||
{
|
{
|
||||||
assert(sd->flags.Test(SettingFlag::NoNetworkSync));
|
assert(sd->flags.Test(SettingFlag::NoNetworkSync));
|
||||||
|
|
||||||
if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ && value.compare("(null)") == 0) {
|
if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ && value == "(null)") {
|
||||||
value.clear();
|
value = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
|
const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
|
||||||
sd->AsStringSetting()->ChangeValue(object, value);
|
sd->AsStringSetting()->ChangeValue(object, std::string{value});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1896,7 +1896,7 @@ bool SetSettingValue(const StringSettingDesc *sd, std::string value, bool force_
|
||||||
* @param object The object the setting is in.
|
* @param object The object the setting is in.
|
||||||
* @param newval The new value for the setting.
|
* @param newval The new value for the setting.
|
||||||
*/
|
*/
|
||||||
void StringSettingDesc::ChangeValue(const void *object, std::string &newval) const
|
void StringSettingDesc::ChangeValue(const void *object, std::string &&newval) const
|
||||||
{
|
{
|
||||||
this->MakeValueValid(newval);
|
this->MakeValueValid(newval);
|
||||||
if (this->pre_check != nullptr && !this->pre_check(newval)) return;
|
if (this->pre_check != nullptr && !this->pre_check(newval)) return;
|
||||||
|
|
|
@ -334,7 +334,7 @@ struct StringSettingDesc : SettingDesc {
|
||||||
PostChangeCallback *post_callback; ///< Callback when the setting has been changed.
|
PostChangeCallback *post_callback; ///< Callback when the setting has been changed.
|
||||||
|
|
||||||
bool IsStringSetting() const override { return true; }
|
bool IsStringSetting() const override { return true; }
|
||||||
void ChangeValue(const void *object, std::string &newval) const;
|
void ChangeValue(const void *object, std::string &&newval) const;
|
||||||
|
|
||||||
std::string FormatValue(const void *object) const override;
|
std::string FormatValue(const void *object) const override;
|
||||||
void ParseValue(const IniItem *item, void *object) const override;
|
void ParseValue(const IniItem *item, void *object) const override;
|
||||||
|
@ -392,7 +392,7 @@ const SettingDesc *GetSettingFromName(const std::string_view name);
|
||||||
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector<SaveLoad> &saveloads);
|
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector<SaveLoad> &saveloads);
|
||||||
SettingTable GetSaveLoadSettingTable();
|
SettingTable GetSaveLoadSettingTable();
|
||||||
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame = false);
|
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame = false);
|
||||||
bool SetSettingValue(const StringSettingDesc *sd, const std::string value, bool force_newgame = false);
|
bool SetSettingValue(const StringSettingDesc *sd, std::string_view value, bool force_newgame = false);
|
||||||
|
|
||||||
std::vector<const SettingDesc *> GetFilteredSettingCollection(std::function<bool(const SettingDesc &desc)> func);
|
std::vector<const SettingDesc *> GetFilteredSettingCollection(std::function<bool(const SettingDesc &desc)> func);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue