diff options
author | Patric Stout <truebrain@openttd.org> | 2020-12-25 19:38:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-25 19:38:18 +0100 |
commit | f66baa444ff5575b2b40e3bfd514cdb463f6f560 (patch) | |
tree | f0977f8443106be749dac7a84fb01c2eebaedd45 /src/script/script_info.cpp | |
parent | 9add62796c91c8eb7dd971cb21c8cdeba49cadfa (diff) | |
download | openttd-f66baa444ff5575b2b40e3bfd514cdb463f6f560.tar.xz |
Codechange: use C++11 constructs for for-each loops (#8432)
Diffstat (limited to 'src/script/script_info.cpp')
-rw-r--r-- | src/script/script_info.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/script/script_info.cpp b/src/script/script_info.cpp index 53a8fb30e..4eebd548d 100644 --- a/src/script/script_info.cpp +++ b/src/script/script_info.cpp @@ -20,14 +20,14 @@ ScriptInfo::~ScriptInfo() { /* Free all allocated strings */ - for (ScriptConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { - free((*it).name); - free((*it).description); - if (it->labels != nullptr) { - for (auto &lbl_map : *(*it).labels) { + for (const auto &item : this->config_list) { + free(item.name); + free(item.description); + if (item.labels != nullptr) { + for (auto &lbl_map : *item.labels) { free(lbl_map.second); } - delete it->labels; + delete item.labels; } } this->config_list.clear(); @@ -232,8 +232,8 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm) ValidateString(setting_name); ScriptConfigItem *config = nullptr; - for (ScriptConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { - if (strcmp((*it).name, setting_name) == 0) config = &(*it); + for (auto &item : this->config_list) { + if (strcmp(item.name, setting_name) == 0) config = &item; } if (config == nullptr) { @@ -284,22 +284,22 @@ const ScriptConfigItemList *ScriptInfo::GetConfigList() const const ScriptConfigItem *ScriptInfo::GetConfigItem(const char *name) const { - for (ScriptConfigItemList::const_iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { - if (strcmp((*it).name, name) == 0) return &(*it); + for (const auto &item : this->config_list) { + if (strcmp(item.name, name) == 0) return &item; } return nullptr; } int ScriptInfo::GetSettingDefaultValue(const char *name) const { - for (ScriptConfigItemList::const_iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { - if (strcmp((*it).name, name) != 0) continue; + for (const auto &item : this->config_list) { + if (strcmp(item.name, name) != 0) continue; /* The default value depends on the difficulty level */ switch (GetGameSettings().script.settings_profile) { - case SP_EASY: return (*it).easy_value; - case SP_MEDIUM: return (*it).medium_value; - case SP_HARD: return (*it).hard_value; - case SP_CUSTOM: return (*it).custom_value; + case SP_EASY: return item.easy_value; + case SP_MEDIUM: return item.medium_value; + case SP_HARD: return item.hard_value; + case SP_CUSTOM: return item.custom_value; default: NOT_REACHED(); } } |