OpenTTD Source 20241224-master-gee860a5c8e
SettingDesc Struct Referenceabstract

Properties of config file settings. More...

#include <settings_internal.h>

Inheritance diagram for SettingDesc:
IntSettingDesc ListSettingDesc NullSettingDesc StringSettingDesc BoolSettingDesc OneOfManySettingDesc ManyOfManySettingDesc

Public Member Functions

 SettingDesc (const SaveLoad &save, SettingFlag flags, bool startup)
 
bool IsEditable (bool do_command=false) const
 Check whether the setting is editable in the current gamemode.
 
SettingType GetType () const
 Return the type of the setting.
 
constexpr const std::string & GetName () const
 Get the name of this setting.
 
virtual bool IsIntSetting () const
 Check whether this setting is an integer type setting.
 
virtual bool IsStringSetting () const
 Check whether this setting is an string type setting.
 
const struct IntSettingDescAsIntSetting () const
 Get the setting description of this setting as an integer setting.
 
const struct StringSettingDescAsStringSetting () const
 Get the setting description of this setting as a string setting.
 
virtual std::string FormatValue (const void *object) const =0
 Format the value of the setting associated with this object.
 
virtual void ParseValue (const IniItem *item, void *object) const =0
 Parse/read the value from the Ini item into the setting associated with this object.
 
virtual bool IsSameValue (const IniItem *item, void *object) const =0
 Check whether the value in the Ini item is the same as is saved in this setting in the object.
 
virtual bool IsDefaultValue (void *object) const =0
 Check whether the value is the same as the default value.
 
virtual void ResetToDefault (void *object) const =0
 Reset the setting to its default value.
 

Data Fields

SettingFlag flags
 Handles how a setting would show up in the GUI (text/currency, etc.).
 
bool startup
 Setting has to be loaded directly at startup?.
 
SaveLoad save
 Internal structure (going to savegame, parts to config).
 

Detailed Description

Properties of config file settings.

Definition at line 71 of file settings_internal.h.

Constructor & Destructor Documentation

◆ SettingDesc()

SettingDesc::SettingDesc ( const SaveLoad save,
SettingFlag  flags,
bool  startup 
)
inline

Definition at line 72 of file settings_internal.h.

Member Function Documentation

◆ AsIntSetting()

const IntSettingDesc * SettingDesc::AsIntSetting ( ) const

Get the setting description of this setting as an integer setting.

Returns
The integer setting description.

Definition at line 910 of file settings.cpp.

References IsIntSetting().

Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), NewsTypeData::GetDisplay(), HandleOldDiffCustom(), IConsoleGetSetting(), SettingEntry::Init(), LoadSettings(), SetDefaultCompanySettings(), SetSettingValue(), and SyncCompanySettings().

◆ AsStringSetting()

const StringSettingDesc * SettingDesc::AsStringSetting ( ) const

Get the setting description of this setting as a string setting.

Returns
The string setting description.

Definition at line 920 of file settings.cpp.

References IsStringSetting().

Referenced by IConsoleGetSetting(), and SetSettingValue().

◆ FormatValue()

virtual std::string SettingDesc::FormatValue ( const void *  object) const
pure virtual

Format the value of the setting associated with this object.

Parameters
bufThe before of the buffer to format into.
lastThe end of the buffer to format into.
objectThe object the setting is in.

Implemented in NullSettingDesc, IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, and ListSettingDesc.

Referenced by IConsoleGetSetting(), IniSaveSettings(), and SurveySettingsTable().

◆ GetName()

◆ GetType()

SettingType SettingDesc::GetType ( ) const

Return the type of the setting.

Returns
type of setting

Definition at line 900 of file settings.cpp.

References flags, SF_NOT_IN_SAVE, SF_PER_COMPANY, ST_CLIENT, ST_COMPANY, and ST_GAME.

Referenced by SettingEntry::UpdateFilterState().

◆ IsDefaultValue()

virtual bool SettingDesc::IsDefaultValue ( void *  object) const
pure virtual

Check whether the value is the same as the default value.

Parameters
objectThe object the setting is in.
Returns
true iff the value is the default value.

Implemented in NullSettingDesc, IntSettingDesc, StringSettingDesc, and ListSettingDesc.

Referenced by SurveySettingsTable().

◆ IsEditable()

bool SettingDesc::IsEditable ( bool  do_command = false) const

Check whether the setting is editable in the current gamemode.

Parameters
do_commandtrue if this is about checking a command from the server.
Returns
true if editable.

Definition at line 883 of file settings.cpp.

References _network_server, _networking, flags, SF_NETWORK_ONLY, SF_NEWGAME_ONLY, SF_NO_NETWORK, SF_NO_NETWORK_SYNC, SF_PER_COMPANY, SF_SCENEDIT_ONLY, and SF_SCENEDIT_TOO.

Referenced by CmdChangeSetting(), and SettingEntry::DrawSetting().

◆ IsIntSetting()

virtual bool SettingDesc::IsIntSetting ( ) const
inlinevirtual

Check whether this setting is an integer type setting.

Returns
True when the underlying type is an integer.

Reimplemented in IntSettingDesc.

Definition at line 96 of file settings_internal.h.

Referenced by AsIntSetting(), CmdChangeCompanySetting(), CmdChangeSetting(), NewsTypeData::GetDisplay(), IConsoleGetSetting(), and LoadSettings().

◆ IsSameValue()

virtual bool SettingDesc::IsSameValue ( const IniItem item,
void *  object 
) const
pure virtual

Check whether the value in the Ini item is the same as is saved in this setting in the object.

It might be that determining whether the value is the same is way more expensive than just writing the value. In those cases this function may unconditionally return false even though the value might be the same as in the Ini item.

Parameters
itemThe Ini item with the content of this setting.
objectThe object the setting is in.
Returns
True if the value is definitely the same (might be false when the same).

Implemented in NullSettingDesc, IntSettingDesc, StringSettingDesc, and ListSettingDesc.

Referenced by IniSaveSettings().

◆ IsStringSetting()

virtual bool SettingDesc::IsStringSetting ( ) const
inlinevirtual

Check whether this setting is an string type setting.

Returns
True when the underlying type is a string.

Reimplemented in StringSettingDesc.

Definition at line 102 of file settings_internal.h.

Referenced by AsStringSetting(), and IConsoleGetSetting().

◆ ParseValue()

virtual void SettingDesc::ParseValue ( const IniItem item,
void *  object 
) const
pure virtual

Parse/read the value from the Ini item into the setting associated with this object.

Parameters
itemThe Ini item with the content of this setting.
objectThe object the setting is in.

Implemented in NullSettingDesc, IntSettingDesc, StringSettingDesc, and ListSettingDesc.

Referenced by IniLoadSettings().

◆ ResetToDefault()

virtual void SettingDesc::ResetToDefault ( void *  object) const
pure virtual

Reset the setting to its default value.

Implemented in NullSettingDesc, IntSettingDesc, StringSettingDesc, and ListSettingDesc.

Referenced by PATSChunkHandler::Load().

Field Documentation

◆ flags

◆ save

◆ startup

bool SettingDesc::startup

Setting has to be loaded directly at startup?.

Definition at line 77 of file settings_internal.h.

Referenced by IniLoadSettings().


The documentation for this struct was generated from the following files: