OpenTTD Source: StringSettingDesc Struct Reference

OpenTTD Source 14.0-beta3

Public Types | Public Member Functions | Data Fields | Private Member Functions
StringSettingDesc Struct Reference

String settings. More...

`#include <settings_internal.h>`

Inheritance diagram for StringSettingDesc:

## 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...
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...

## Detailed Description

String settings.

Definition at line 302 of file settings_internal.h.

## Member Typedef Documentation

## ◆ PostChangeCallback

typedef void StringSettingDesc::PostChangeCallback(const std::string &value)

A callback to denote that a setting has been changed.

Parameters

  The | new value for the setting.

Definition at line 316 of file settings_internal.h.

## ◆ PreChangeCheck

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.

Parameters

  value | The prospective new value for the setting.

Returns
  True when the setting is accepted.

Definition at line 311 of file settings_internal.h.

## Member Function Documentation

## ◆ ChangeValue()

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.

Parameters

  object | The object the setting is in.
  newval | The new value for the setting.

Definition at line 1836 of file settings.cpp.

References MakeValueValid(), post_callback, pre_check, and Write().

## ◆ FormatValue()

std::string StringSettingDesc::FormatValue | ( | const void * | object | ) | const
| overridevirtual

Format the value of the setting associated with this object.

Parameters

  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 771 of file settings.cpp.

References SaveLoad::conv, GetVarMemType(), Read(), SettingDesc::save, SLE_VAR_STR, and SLE_VAR_STRQ.

## ◆ IsDefaultValue()

bool StringSettingDesc::IsDefaultValue | ( | void * | object | ) | const
| overridevirtual

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

Parameters

  object | The object the setting is in.

Returns
  true iff the value is the default value.

Implements SettingDesc.

Definition at line 797 of file settings.cpp.

References def, and Read().

## ◆ IsSameValue()

bool StringSettingDesc::IsSameValue | ( | const IniItem * | item,
|  | void * | object
| ) |  | const
| 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.

Parameters

  item | The Ini item with the content of this setting.
  object | The object the setting is in.

Returns
  True if the value is definitely the same (might be false when the same).

Implements SettingDesc.

Definition at line 787 of file settings.cpp.

References SaveLoad::conv, GetVarMemType(), Read(), SettingDesc::save, SLE_VAR_STRQ, and IniItem::value.

## ◆ IsStringSetting()

bool StringSettingDesc::IsStringSetting | ( |  | ) | const
| inlineoverridevirtual

Check whether this setting is an string type setting.

Returns
  True when the underlying type is a string.

Reimplemented from SettingDesc.

Definition at line 328 of file settings_internal.h.

## ◆ MakeValueValid()

void StringSettingDesc::MakeValueValid | ( | std::string & | str | ) | const
| 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.

Parameters

  str | The string to make valid.

Definition at line 590 of file settings.cpp.

References max_length, StrMakeValid(), and SVS_NONE.

Referenced by ChangeValue(), and ParseValue().

## ◆ ParseValue()

void StringSettingDesc::ParseValue | ( | const IniItem * | item,
|  | void * | object
| ) |  | const
| overridevirtual

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

Parameters

  item | The Ini item with the content of this setting.
  object | The object the setting is in.

Implements SettingDesc.

Definition at line 677 of file settings.cpp.

References def, MakeValueValid(), IniItem::value, and Write().

## ◆ Read()

const std::string & StringSettingDesc::Read | ( | const void * | object | ) | const

Read the string from the the actual setting.

Parameters

  object | The object the setting is to be saved in.

Returns
  The value of the saved string.

Definition at line 616 of file settings.cpp.

References GetVariableAddress(), and SettingDesc::save.

Referenced by FormatValue(), IsDefaultValue(), and IsSameValue().

## ◆ Write()

void StringSettingDesc::Write | ( | const void * | object,
|  | const std::string & | str
| ) |  | const
| private

Write a string to the actual setting.

Parameters

  object | The object the setting is to be saved in.
  str | The string to save.

Definition at line 606 of file settings.cpp.

References GetVariableAddress(), and SettingDesc::save.

Referenced by ChangeValue(), and ParseValue().

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

- src/settings_internal.h
- src/settings.cpp