|
OpenTTD Source 20260218-master-g2123fca5ea
|
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 |
| Reference to the value we are backing up. | |
| bool | valid |
| Whether the original value has been restored. | |
| T | original_value |
| The value at the moment of making a backup. | |
| const std::source_location | location |
| Call location where the backup was created. | |
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.
Definition at line 27 of file backup_type.hpp.
References location, original, original_value, and valid.
|
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.
References location, original, original_value, and valid.
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 81 of file backup_type.hpp.
References valid.
Referenced by CmdTerraformLand(), AI::GameLoop(), Game::GameLoop(), CommandHelperBase::InternalExecutePrepTest(), and Game::StartNew().
|
inline |
Returns the backupped value.
Definition at line 69 of file backup_type.hpp.
References original_value, and valid.
Referenced by CmdBuildIndustry().
|
inline |
Checks whether the variable was already restored.
Definition at line 60 of file backup_type.hpp.
References valid.
Referenced by _GenerateWorld().
|
inline |
Restore the variable.
Definition at line 109 of file backup_type.hpp.
References Revert(), and Trash().
Referenced by _GenerateWorld(), AfterLoadGame(), AircraftEventHandler_HeliTakeOff(), AircraftEventHandler_Landing(), CanBuildTramTrackOnTile(), ChangeOwnershipOfCompanyItems(), CheckClearTile(), CheckIfCanLevelIndustryPlatform(), CheckIfIndustryTilesAreFree(), CmdBuildIndustry(), CmdFoundTown(), CmdTerraformLand(), CreateRandomTown(), DoDryUp(), DoFloodTile(), DrawSpriteToRgbaBuffer(), FloodHalftile(), AI::GameLoop(), Game::GameLoop(), GenerateDesertArea(), GrowTown(), HandleStationRefit(), CommandHelperBase::InternalExecuteProcessResult(), AI::IsPaused(), NetworkClientsToSpectators(), AI::NewEvent(), Game::NewEvent(), FoundTownWindow::OnQueryTextFinished(), AI::Pause(), PlaceInitialIndustry(), ResetLandscapeConfirmationCallback(), AI::Save(), Game::Save(), AI::StartNew(), Game::StartNew(), StateGameLoop(), AI::Stop(), TileLoop_Town(), TownActionBuildStatue(), Game::Uninitialize(), AI::Unpause(), VehicleEnterDepot(), and ~Backup().
|
inline |
Revert the variable to its original value, but do not mark it as restored.
Definition at line 91 of file backup_type.hpp.
References original_value, and valid.
Referenced by Restore().
|
inline |
Trash the backup.
The variable shall not be restored anymore.
Definition at line 100 of file backup_type.hpp.
References valid.
Referenced by _GenerateWorld(), CommandHelperBase::InternalExecuteProcessResult(), and 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 119 of file backup_type.hpp.
References original_value, and valid.
|
inline |
Check whether the variable is currently equals the backup.
Definition at line 129 of file backup_type.hpp.
References original_value, and valid.
Referenced by CommandHelperBase::InternalExecuteProcessResult().
|
private |
Call location where the backup was created.
Definition at line 140 of file backup_type.hpp.
|
private |
Reference to the value we are backing up.
Definition at line 136 of file backup_type.hpp.
|
private |
The value at the moment of making a backup.
Definition at line 138 of file backup_type.hpp.
Referenced by Backup(), Backup(), GetOriginalValue(), Revert(), Update(), and Verify().
|
private |