OpenTTD Source 20241224-master-gf74b0cf984
AutoRestoreBackup< T > Struct Template Reference

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 ()
 Restore the variable upon object destruction.
 

Private Member Functions

 AutoRestoreBackup (const AutoRestoreBackup &)=delete
 
AutoRestoreBackupoperator= (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
 
original_value
 

Detailed Description

template<typename T>
struct AutoRestoreBackup< T >

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 150 of file backup_type.hpp.

Constructor & Destructor Documentation

◆ AutoRestoreBackup()

template<typename T >
AutoRestoreBackup< T >::AutoRestoreBackup ( T &  original,
new_value 
)
inline

Backup variable and switch to new value.

Parameters
originalVariable to backup.
new_valueNew value for variable.

Definition at line 162 of file backup_type.hpp.

◆ ~AutoRestoreBackup()

template<typename T >
AutoRestoreBackup< T >::~AutoRestoreBackup ( )
inline

Restore the variable upon object destruction.

Definition at line 170 of file backup_type.hpp.

Field Documentation

◆ original

template<typename T >
T& AutoRestoreBackup< T >::original
private

Definition at line 176 of file backup_type.hpp.

◆ original_value

template<typename T >
T AutoRestoreBackup< T >::original_value
private

Definition at line 177 of file backup_type.hpp.


The documentation for this struct was generated from the following file: