Codechange: introduce new type and functions for StringParameter backups

This commit is contained in:
Rubidium
2023-06-21 06:35:06 +02:00
committed by rubidium42
parent 26f3efb419
commit 2687704afc
3 changed files with 85 additions and 0 deletions

View File

@@ -88,4 +88,34 @@ enum SpecialStrings {
SPECSTR_PRESIDENT_NAME = 0x70E7,
};
/** Data that is to be stored when backing up StringParameters. */
struct StringParameterBackup {
uint64_t data; ///< The data field; valid *when* string has no value.
std::optional<std::string> string; ///< The string value.
/**
* Assign the numeric data with the given value, while clearing the stored string.
* @param data The new value of the data field.
* @return This object.
*/
StringParameterBackup &operator=(uint64_t data)
{
this->string.reset();
this->data = data;
return *this;
}
/**
* Assign a copy of the given string to the string field, while clearing the data field.
* @param string The new value of the string.
* @return This object.
*/
StringParameterBackup &operator=(const std::string_view string)
{
this->data = 0;
this->string.emplace(string);
return *this;
}
};
#endif /* STRINGS_TYPE_H */