MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetSettingFromName

Function GetSettingFromName

src/settings.cpp:1640–1658  ·  view source on GitHub ↗

* Given a name of setting, return a setting description from the table. * @param name Name of the setting to return a setting description of. * @param settings Table to look in for the setting. * @return Pointer to the setting description of setting \a name if it can be found, * \c nullptr indicates failure to obtain the description. */

Source from the content-addressed store, hash-verified

1638 * \c nullptr indicates failure to obtain the description.
1639 */
1640static const SettingDesc *GetSettingFromName(std::string_view name, const SettingTable &settings)
1641{
1642 /* First check all full names */
1643 for (auto &desc : settings) {
1644 const SettingDesc *sd = GetSettingDesc(desc);
1645 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1646 if (sd->GetName() == name) return sd;
1647 }
1648
1649 /* Then check the shortcut variant of the name. */
1650 std::string short_name_suffix = std::string{ "." }.append(name);
1651 for (auto &desc : settings) {
1652 const SettingDesc *sd = GetSettingDesc(desc);
1653 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
1654 if (sd->GetName().ends_with(short_name_suffix)) return sd;
1655 }
1656
1657 return nullptr;
1658}
1659
1660/**
1661 * Get the SaveLoad for all settings in the settings table.

Callers 12

InitMethod · 0.85
CmdChangeSettingFunction · 0.85
IConsoleSetSettingFunction · 0.85
IConsoleGetSettingFunction · 0.85
GetDisplayMethod · 0.85
IsValidMethod · 0.85
GetValueMethod · 0.85
SetValueMethod · 0.85
CheckServerNameMethod · 0.85
OnQueryTextFinishedMethod · 0.85
HandleOldDiffCustomFunction · 0.85

Calls 5

GetSettingDescFunction · 0.85
SlIsObjectCurrentlyValidFunction · 0.85
appendMethod · 0.80
GetNameMethod · 0.45

Tested by

no test coverage detected