OpenTTD Source 20250205-master-gfd85ab1e2c
|
String settings. More...
#include <settings_internal.h>
Public Types | |
typedef bool | PreChangeCheck(std::string &value) |
A check to be performed before the setting gets changed. | |
typedef void | PostChangeCallback(const std::string &value) |
A callback to denote that a setting has been changed. | |
Public Member Functions | |
StringSettingDesc (const SaveLoad &save, SettingFlags flags, bool startup, const char *def, uint32_t max_length, PreChangeCheck pre_check, PostChangeCallback post_callback) | |
bool | IsStringSetting () const override |
Check whether this setting is an string type setting. | |
void | ChangeValue (const void *object, std::string &newval) const |
Handle changing a string value. | |
std::string | FormatValue (const void *object) const override |
Format the value of the setting associated with this object. | |
void | ParseValue (const IniItem *item, void *object) const override |
Parse/read the value from the Ini item into the setting associated with this object. | |
bool | IsSameValue (const IniItem *item, void *object) const override |
Check whether the value in the Ini item is the same as is saved in this setting in the object. | |
bool | IsDefaultValue (void *object) const override |
Check whether the value is the same as the default value. | |
void | ResetToDefault (void *object) const override |
Reset the setting to its default value. | |
const std::string & | Read (const void *object) const |
Read the string from the the actual setting. | |
Public Member Functions inherited from SettingDesc | |
SettingDesc (const SaveLoad &save, SettingFlags 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. | |
const struct IntSettingDesc * | AsIntSetting () const |
Get the setting description of this setting as an integer setting. | |
const struct StringSettingDesc * | AsStringSetting () const |
Get the setting description of this setting as a string setting. | |
Data Fields | |
std::string | def |
Default value given when none is present. | |
uint32_t | max_length |
Maximum length of the string, 0 means no maximum length. | |
PreChangeCheck * | pre_check |
Callback to check for the validity of the setting. | |
PostChangeCallback * | post_callback |
Callback when the setting has been changed. | |
Data Fields inherited from SettingDesc | |
SettingFlags | 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). | |
Private Member Functions | |
void | MakeValueValid (std::string &str) const |
Make the value valid given the limitations of this setting. | |
void | Write (const void *object, const std::string &str) const |
Write a string to the actual setting. | |
String settings.
Definition at line 308 of file settings_internal.h.
typedef void StringSettingDesc::PostChangeCallback(const std::string &value) |
A callback to denote that a setting has been changed.
The | new value for the setting. |
Definition at line 322 of file settings_internal.h.
typedef bool StringSettingDesc::PreChangeCheck(std::string &value) |
A check to be performed before the setting gets changed.
The passed string may be changed by the check if that is important, for example to remove unwanted white space. The return value denotes whether the value, potentially after the changes, is allowed to be used/set in the configuration.
value | The prospective new value for the setting. |
Definition at line 317 of file settings_internal.h.
|
inline |
Definition at line 324 of file settings_internal.h.
void StringSettingDesc::ChangeValue | ( | const void * | object, |
std::string & | newval | ||
) | const |
Handle changing a string value.
This performs validation of the input value and calls the appropriate callbacks, and saves it when the value is changed.
object | The object the setting is in. |
newval | The new value for the setting. |
Definition at line 1870 of file settings.cpp.
References MakeValueValid(), post_callback, pre_check, SaveToConfig(), and Write().
Referenced by SetSettingValue().
|
overridevirtual |
Format the value of the setting associated with this object.
buf | The before of the buffer to format into. |
last | The end of the buffer to format into. |
object | The object the setting is in. |
Implements SettingDesc.
Definition at line 780 of file settings.cpp.
References SaveLoad::conv, GetVarMemType(), Read(), SettingDesc::save, SLE_VAR_STR, and SLE_VAR_STRQ.
|
overridevirtual |
Check whether the value is the same as the default value.
object | The object the setting is in. |
Implements SettingDesc.
Definition at line 806 of file settings.cpp.
|
overridevirtual |
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.
item | The Ini item with the content of this setting. |
object | The object the setting is in. |
Implements SettingDesc.
Definition at line 796 of file settings.cpp.
References SaveLoad::conv, GetVarMemType(), Read(), SettingDesc::save, SLE_VAR_STRQ, and IniItem::value.
|
inlineoverridevirtual |
Check whether this setting is an string type setting.
Reimplemented from SettingDesc.
Definition at line 334 of file settings_internal.h.
|
private |
Make the value valid given the limitations of this setting.
In the case of string settings this is ensuring the string contains only accepted Utf8 characters and is at most the maximum length defined in this setting.
str | The string to make valid. |
Definition at line 594 of file settings.cpp.
References max_length, StrMakeValid(), and SVS_NONE.
Referenced by ChangeValue(), and ParseValue().
|
overridevirtual |
Parse/read the value from the Ini item into the setting associated with this object.
item | The Ini item with the content of this setting. |
object | The object the setting is in. |
Implements SettingDesc.
Definition at line 681 of file settings.cpp.
References def, MakeValueValid(), IniItem::value, and Write().
const std::string & StringSettingDesc::Read | ( | const void * | object | ) | const |
Read the string from the the actual setting.
object | The object the setting is to be saved in. |
Definition at line 620 of file settings.cpp.
References GetVariableAddress(), and SettingDesc::save.
Referenced by FormatValue(), IConsoleGetSetting(), IsDefaultValue(), and IsSameValue().
|
overridevirtual |
Reset the setting to its default value.
Implements SettingDesc.
Definition at line 812 of file settings.cpp.
|
private |
Write a string to the actual setting.
object | The object the setting is to be saved in. |
str | The string to save. |
Definition at line 610 of file settings.cpp.
References GetVariableAddress(), and SettingDesc::save.
Referenced by ChangeValue(), ParseValue(), and ResetToDefault().
std::string StringSettingDesc::def |
Default value given when none is present.
Definition at line 329 of file settings_internal.h.
Referenced by IsDefaultValue(), ParseValue(), and ResetToDefault().
uint32_t StringSettingDesc::max_length |
Maximum length of the string, 0 means no maximum length.
Definition at line 330 of file settings_internal.h.
Referenced by MakeValueValid().
PostChangeCallback* StringSettingDesc::post_callback |
Callback when the setting has been changed.
Definition at line 332 of file settings_internal.h.
Referenced by ChangeValue().
PreChangeCheck* StringSettingDesc::pre_check |
Callback to check for the validity of the setting.
Definition at line 331 of file settings_internal.h.
Referenced by ChangeValue().