OpenTTD Source
20241108-master-g80f628063a
|
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. More... | |
typedef void | PostChangeCallback(const std::string &value) |
A callback to denote that a setting has been changed. More... | |
Public Member Functions | |
StringSettingDesc (const SaveLoad &save, SettingFlag 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. More... | |
void | ChangeValue (const void *object, std::string &newval) const |
Handle changing a string value. More... | |
std::string | FormatValue (const void *object) const override |
Format the value of the setting associated with this object. More... | |
void | ParseValue (const IniItem *item, void *object) const override |
Parse/read the value from the Ini item into the setting associated with this object. More... | |
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. More... | |
bool | IsDefaultValue (void *object) const override |
Check whether the value is the same as the default value. More... | |
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. More... | |
Public Member Functions inherited from SettingDesc | |
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... | |
const struct IntSettingDesc * | AsIntSetting () const |
Get the setting description of this setting as an integer setting. More... | |
const struct StringSettingDesc * | AsStringSetting () const |
Get the setting description of this setting as a string setting. More... | |
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 | |
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). | |
Private Member Functions | |
void | MakeValueValid (std::string &str) const |
Make the value valid given the limitations of this setting. More... | |
void | Write (const void *object, const std::string &str) const |
Write a string to the actual setting. More... | |
String settings.
Definition at line 318 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 332 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 327 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 1838 of file settings.cpp.
References MakeValueValid(), post_callback, pre_check, and Write().
|
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 760 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 786 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 776 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 344 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 574 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 661 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 600 of file settings.cpp.
References GetVariableAddress(), and SettingDesc::save.
Referenced by FormatValue(), IsDefaultValue(), and IsSameValue().
|
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 590 of file settings.cpp.
References GetVariableAddress(), and SettingDesc::save.
Referenced by ChangeValue(), ParseValue(), and ResetToDefault().