OpenTTD Source  20240917-master-g9ab0a47812
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. More...
 
SettingType GetType () const
 Return the type of the setting. More...
 
constexpr const std::string & GetName () const
 Get the name of this setting. More...
 
virtual bool IsIntSetting () const
 Check whether this setting is an integer type setting. More...
 
virtual bool IsStringSetting () const
 Check whether this setting is an string type setting. More...
 
const struct IntSettingDescAsIntSetting () const
 Get the setting description of this setting as an integer setting. More...
 
const struct StringSettingDescAsStringSetting () const
 Get the setting description of this setting as a string setting. More...
 
virtual std::string FormatValue (const void *object) const =0
 Format the value of the setting associated with this object. More...
 
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. More...
 
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. More...
 
virtual bool IsDefaultValue (void *object) const =0
 Check whether the value is the same as the default value. More...
 
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.

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(), SettingEntry::Init(), LoadSettings(), and SetSettingValue().

◆ 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().

◆ 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 ListSettingDesc, StringSettingDesc, ManyOfManySettingDesc, OneOfManySettingDesc, BoolSettingDesc, IntSettingDesc, and NullSettingDesc.

Referenced by IniSaveSettings(), and SurveySettingsTable().

◆ GetName()

constexpr const std::string& SettingDesc::GetName ( ) const
inlineconstexpr

◆ 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 ListSettingDesc, StringSettingDesc, IntSettingDesc, and NullSettingDesc.

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_NO_NETWORK_SYNC, and SF_PER_COMPANY.

Referenced by CmdChangeSetting().

◆ 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(), 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 ListSettingDesc, StringSettingDesc, IntSettingDesc, and NullSettingDesc.

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().

◆ 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 ListSettingDesc, StringSettingDesc, IntSettingDesc, and NullSettingDesc.

Referenced by IniLoadSettings().


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