|
Open Model Railroad Network (OpenMRN)
|
Overrides the value of a variable and restores it to the original value when destructed. More...
#include <test_main.hxx>
Classes | |
| class | Holder |
| Type-accurate class that holds the temporary variable with the old value, the pointer to the variable and restores the previous state upon destruction. More... | |
| class | HolderBase |
| Virtual base class for the destructible holders. More... | |
Public Member Functions | |
| template<class T , typename U > | |
| ScopedOverride (T *variable, U new_value) | |
| Constructor. | |
| void | restore () |
| Restores the original value. | |
Private Attributes | |
| std::unique_ptr< HolderBase > | holder_ |
| Smart ptr that will reset the variable to the previous value when going out of scope. | |
Overrides the value of a variable and restores it to the original value when destructed.
Useful for changing flags for a single test only.
Usage: { ScopedOverride ov(&DATAGRAM_RESPONSE_TIMEOUT_NSEC, 100000); ... test code assuming new value ... } ... now the original value is restored.
Definition at line 332 of file test_main.hxx.
|
inline |
Constructor.
| variable | what to set temporarily |
| new_value | what should be the new value of variable during this code block. |
Definition at line 342 of file test_main.hxx.
|
inline |
Restores the original value.
Definition at line 348 of file test_main.hxx.
|
private |
Smart ptr that will reset the variable to the previous value when going out of scope.
Definition at line 393 of file test_main.hxx.