10 #ifndef BACKUP_TYPE_HPP
11 #define BACKUP_TYPE_HPP
27 Backup(T &original,
const std::source_location location = std::source_location::current()) : original(original), valid(true), original_value(original), location(location) {}
36 Backup(T &original,
const U &new_value,
const std::source_location location = std::source_location::current()) : original(original), valid(true), original_value(original), location(location)
52 Debug(misc, 0,
"{}:{}: Backed-up value was not restored!", this->location.file_name(), this->location.line());
73 return original_value;
95 this->original = this->original_value;
123 this->original_value = this->original;
133 return this->original_value == this->original;
141 const std::source_location location;
149 template <
typename T>
164 original = new_value;
172 this->original = this->original_value;
182 static void *
operator new(std::size_t) =
delete;
183 static void *
operator new[](std::size_t) =
delete;
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
~AutoRestoreBackup()
Restore the variable upon object destruction.
AutoRestoreBackup(T &original, T new_value)
Backup variable and switch to new value.
Class to backup a specific variable and restore it later.
void Revert()
Revert the variable to its original value, but do not mark it as restored.
const T & GetOriginalValue() const
Returns the backupped value.
bool IsValid() const
Checks whether the variable was already restored.
Backup(T &original, const std::source_location location=std::source_location::current())
Backup variable.
void Trash()
Trash the backup.
~Backup()
Check whether the variable was restored on object destruction.
bool Verify() const
Check whether the variable is currently equals the backup.
void Change(const U &new_value)
Change the value of the variable.
void Update()
Update the backup.
Backup(T &original, const U &new_value, const std::source_location location=std::source_location::current())
Backup variable and switch to new value.
void Restore()
Restore the variable.