|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
10 #ifndef BACKUP_TYPE_HPP
11 #define BACKUP_TYPE_HPP
28 Backup(T &original,
const char *
const file,
const int line) : original(original), valid(true), original_value(original), file(file), line(line) {}
38 Backup(T &original,
const U &new_value,
const char *
const file,
const int line) : original(original), valid(true), original_value(original), file(file), line(line)
54 Debug(misc, 0,
"{}:{}: Backed-up value was not restored!", this->file, this->line);
75 return original_value;
97 this->original = this->original_value;
125 this->original_value = this->original;
135 return this->original_value == this->original;
143 const char *
const file;
152 template <
typename T>
167 original = new_value;
175 this->original = this->original_value;
185 static void *
operator new(std::size_t) =
delete;
186 static void *
operator new[](std::size_t) =
delete;
void Change(const U &new_value)
Change the value of the variable.
Class to backup a specific variable and restore it later.
bool Verify() const
Check whether the variable is currently equals the backup.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Backup(T &original, const char *const file, const int line)
Backup variable.
Backup(T &original, const U &new_value, const char *const file, const int line)
Backup variable and switch to new value.
~Backup()
Check whether the variable was restored on object destruction.
void Update()
Update the backup.
bool IsValid() const
Checks whether the variable was already restored.
AutoRestoreBackup(T &original, T new_value)
Backup variable and switch to new value.
void Trash()
Trash the backup.
void Restore()
Restore the variable.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
const T & GetOriginalValue() const
Returns the backupped value.
~AutoRestoreBackup()
Restore the variable upon object destruction.
void Revert()
Revert the variable to its original value, but do not mark it as restored.