OpenTTD Source 20241224-master-gee860a5c8e
|
Class to backup a specific variable and restore it later. More...
#include <backup_type.hpp>
Public Member Functions | |
Backup (T &original, const std::source_location location=std::source_location::current()) | |
Backup variable. | |
template<typename U > | |
Backup (T &original, const U &new_value, const std::source_location location=std::source_location::current()) | |
Backup variable and switch to new value. | |
~Backup () | |
Check whether the variable was restored on object destruction. | |
bool | IsValid () const |
Checks whether the variable was already restored. | |
const T & | GetOriginalValue () const |
Returns the backupped value. | |
template<typename U > | |
void | Change (const U &new_value) |
Change the value of the variable. | |
void | Revert () |
Revert the variable to its original value, but do not mark it as restored. | |
void | Trash () |
Trash the backup. | |
void | Restore () |
Restore the variable. | |
void | Update () |
Update the backup. | |
bool | Verify () const |
Check whether the variable is currently equals the backup. | |
Private Attributes | |
T & | original |
bool | valid |
T | original_value |
const std::source_location | location |
Class to backup a specific variable and restore it later.
The variable is not restored automatically, but assertions make sure it is restored. You have to call either Trash() or Restore() exactly once.
Definition at line 21 of file backup_type.hpp.
|
inline |
Backup variable.
original | Variable to backup. |
location | Source location for debug output. |
Definition at line 27 of file backup_type.hpp.
|
inline |
Backup variable and switch to new value.
original | Variable to backup. |
new_value | New value for variable. |
location | Source location for debug output. |
Definition at line 36 of file backup_type.hpp.
Check whether the variable was restored on object destruction.
Definition at line 45 of file backup_type.hpp.
References Debug, and Backup< T >::Restore().
Change the value of the variable.
While this does not touch the backup at all, it ensures that the variable is only modified while backupped.
new_value | New value for variable. |
Definition at line 82 of file backup_type.hpp.
Referenced by CmdTerraformLand(), CompaniesGenStatistics(), CompaniesPayInterest(), AI::GameLoop(), Game::GameLoop(), CommandHelperBase::InternalExecutePrepTest(), and Game::StartNew().
|
inline |
Returns the backupped value.
Definition at line 70 of file backup_type.hpp.
Referenced by CmdBuildIndustry().
|
inline |
Checks whether the variable was already restored.
Definition at line 61 of file backup_type.hpp.
Referenced by _GenerateWorld().
|
inline |
Restore the variable.
Definition at line 110 of file backup_type.hpp.
References Backup< T >::Revert(), and Backup< T >::Trash().
Referenced by _GenerateWorld(), AfterLoadGame(), CanBuildTramTrackOnTile(), ChangeOwnershipOfCompanyItems(), CheckClearTile(), CheckIfCanLevelIndustryPlatform(), CheckIfIndustryTilesAreFree(), CmdBuildIndustry(), CmdChangeBankBalance(), CmdFoundTown(), CmdGiveMoney(), CmdTerraformLand(), CompaniesGenStatistics(), CompaniesPayInterest(), CreateRandomTown(), DoDryUp(), DoFloodTile(), DrawSpriteToRgbaBuffer(), FloodHalftile(), AI::GameLoop(), Game::GameLoop(), GenerateDesertArea(), GrowTown(), HandleStationRefit(), CommandHelperBase::InternalExecuteProcessResult(), AI::IsPaused(), NetworkClientsToSpectators(), Game::NewEvent(), AI::NewEvent(), AI::Pause(), PlaceInitialIndustry(), ResetLandscapeConfirmationCallback(), Game::Save(), AI::Save(), SearchLumberMillTrees(), Game::StartNew(), AI::StartNew(), StateGameLoop(), AI::Stop(), TileLoop_Town(), TownActionBuildStatue(), Game::Uninitialize(), AI::Unpause(), VehicleEnterDepot(), and Backup< T >::~Backup().
|
inline |
Revert the variable to its original value, but do not mark it as restored.
Definition at line 92 of file backup_type.hpp.
Referenced by Backup< T >::Restore().
|
inline |
Trash the backup.
The variable shall not be restored anymore.
Definition at line 101 of file backup_type.hpp.
Referenced by _GenerateWorld(), CommandHelperBase::InternalExecuteProcessResult(), and Backup< T >::Restore().
|
inline |
Update the backup.
That is trash the old value and make the current value of the variable the value to be restored later.
Definition at line 120 of file backup_type.hpp.
|
inline |
Check whether the variable is currently equals the backup.
Definition at line 130 of file backup_type.hpp.
Referenced by CommandHelperBase::InternalExecuteProcessResult().
|
private |
Definition at line 141 of file backup_type.hpp.
|
private |
Definition at line 137 of file backup_type.hpp.
|
private |
Definition at line 139 of file backup_type.hpp.
|
private |
Definition at line 138 of file backup_type.hpp.