diff options
author | Patric Stout <truebrain@openttd.org> | 2021-05-30 10:55:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-30 10:55:52 +0200 |
commit | 0c968847006ba7206265651ac45f8fa0ce6141ac (patch) | |
tree | 71159110d86179955fc747dbece3ef91f50b37a6 /src/settings.cpp | |
parent | e9e4588db105f5827c5356933023f6ce698fe6aa (diff) | |
download | openttd-0c968847006ba7206265651ac45f8fa0ce6141ac.tar.xz |
Codechange: add a wrapper function to find all settings based on prefix (#9312)
Diffstat (limited to 'src/settings.cpp')
-rw-r--r-- | src/settings.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index d39c04593..f7a4ff5de 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -94,17 +94,6 @@ typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList & static bool IsSignedVarMemType(VarType vt); /** - * Get the setting at the given index into the settings table. - * @param index The index to look for. - * @return The setting at the given index, or nullptr when the index is invalid. - */ -const SettingDesc *GetSettingDescription(uint index) -{ - if (index >= _settings.size()) return nullptr; - return _settings.begin()[index].get(); -} - -/** * Groups in openttd.cfg that are actually lists. */ static const char * const _list_group_names[] = { @@ -1740,6 +1729,21 @@ static const SettingDesc *GetSettingFromName(const char *name, const SettingTabl } /** + * Get the SaveLoad from all settings matching the prefix. + * @param prefix The prefix to look for. + * @param saveloads A vector to store the result in. + */ +void GetSettingSaveLoadByPrefix(const char *prefix, std::vector<SaveLoad> &saveloads) +{ + size_t prefixlen = strlen(prefix); + + for (auto &sd : _settings) { + if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; + if (strncmp(sd->name, prefix, prefixlen) == 0) saveloads.push_back(sd->save); + } +} + +/** * Given a name of setting, return a company setting description of it. * @param name Name of the company setting to return a setting description of. * @return Pointer to the setting description of setting \a name if it can be found, |