From 860003458fc17f02e44b50f98ef570aff824142a Mon Sep 17 00:00:00 2001 From: rubidium42 Date: Sun, 23 May 2021 18:20:49 +0200 Subject: Codechange: make BoolSettingDesc its own sub class --- src/settings.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/settings.cpp') diff --git a/src/settings.cpp b/src/settings.cpp index 3a71c6d2e..f26e56686 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -423,23 +423,24 @@ size_t IntSettingDesc::ParseValue(const char *str) const break; } - case SDT_BOOLX: { - if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return true; - if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return false; - - ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE); - msg.SetDParamStr(0, str); - msg.SetDParamStr(1, this->name); - _settings_error_list.push_back(msg); - break; - } - default: NOT_REACHED(); } return this->def; } +size_t BoolSettingDesc::ParseValue(const char *str) const +{ + if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return true; + if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return false; + + ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE); + msg.SetDParamStr(0, str); + msg.SetDParamStr(1, this->name); + _settings_error_list.push_back(msg); + return this->def; +} + /** * Set the value of a setting and if needed clamp the value to the preset minimum and maximum. * @param object The object the setting is to be saved in. @@ -663,7 +664,6 @@ void IntSettingDesc::FormatValue(char *buf, const char *last, const void *object { uint32 i = (uint32)ReadValue(GetVariableAddress(object, &this->save), this->save.conv); switch (this->cmd) { - case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", last); break; case SDT_NUMX: seprintf(buf, last, IsSignedVarMemType(this->save.conv) ? "%d" : (this->save.conv & SLF_HEX) ? "%X" : "%u", i); break; case SDT_ONEOFMANY: MakeOneOfMany(buf, last, this->many, i); break; case SDT_MANYOFMANY: MakeManyOfMany(buf, last, this->many, i); break; @@ -671,6 +671,12 @@ void IntSettingDesc::FormatValue(char *buf, const char *last, const void *object } } +void BoolSettingDesc::FormatValue(char *buf, const char *last, const void *object) const +{ + bool val = ReadValue(GetVariableAddress(object, &this->save), this->save.conv) != 0; + strecpy(buf, val ? "true" : "false", last); +} + bool IntSettingDesc::IsSameValue(const IniItem *item, void *object) const { int64 item_value = this->ParseValue(item->value->c_str()); -- cgit v1.2.3-54-g00ecf