|
OpenTTD Source 20260531-master-g0e951f3528
|
Class to backup a specific variable and restore it upon destruction of this object to prevent stack values going out of scope before resetting the global to its original value. More...
#include <backup_type.hpp>
Public Member Functions | |
| AutoRestoreBackup (T &original, T new_value) | |
| Backup variable and switch to new value. | |
| AutoRestoreBackup (T &original) | |
| Backup variable without switching value. | |
| ~AutoRestoreBackup () | |
| Restore the variable upon object destruction. | |
| const T & | GetOriginalValue () const |
| Returns the backupped value. | |
Private Member Functions | |
| AutoRestoreBackup (const AutoRestoreBackup &)=delete | |
| AutoRestoreBackup & | operator= (AutoRestoreBackup &)=delete |
Static Private Member Functions | |
| static void * | operator new (std::size_t)=delete |
| static void * | operator new[] (std::size_t)=delete |
Private Attributes | |
| T & | original |
| Reference to the value we are backing up. | |
| T | original_value |
| The value at the moment of making a backup. | |
Class to backup a specific variable and restore it upon destruction of this object to prevent stack values going out of scope before resetting the global to its original value.
Contrary to Backup this restores the variable automatically and there is no manual option to restore.
Definition at line 149 of file backup_type.hpp.
|
inline |
Backup variable and switch to new value.
| original | Variable to backup. |
| new_value | New value for variable. |
Definition at line 161 of file backup_type.hpp.
References original, original_value, and T.
|
inline |
Backup variable without switching value.
| original | Variable to backup. |
Definition at line 170 of file backup_type.hpp.
References original, original_value, and T.
|
inline |
Restore the variable upon object destruction.
Definition at line 177 of file backup_type.hpp.
References original_value.
|
inline |
Returns the backupped value.
Definition at line 186 of file backup_type.hpp.
References original_value, and T.
Referenced by CmdBuildIndustry().
|
private |
Reference to the value we are backing up.
Definition at line 192 of file backup_type.hpp.
Referenced by AutoRestoreBackup(), and AutoRestoreBackup().
|
private |
The value at the moment of making a backup.
Definition at line 193 of file backup_type.hpp.
Referenced by AutoRestoreBackup(), AutoRestoreBackup(), GetOriginalValue(), and ~AutoRestoreBackup().