KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SCOPED_SET_RESET< VAL_TYPE > Class Template Reference

RAII class that sets an value at construction and resets it to the original value at destruction. More...

#include <scoped_set_reset.h>

Public Member Functions

 SCOPED_SET_RESET (VAL_TYPE &target, VAL_TYPE value)
 Construct the class, set the target to the specified value, and remember the original value.
 
 SCOPED_SET_RESET (VAL_TYPE &target)
 Construct the class and remember the original value of the target, but without changing it immediately.
 
 ~SCOPED_SET_RESET ()
 Destruct the class, and return the target to its original value.
 
 SCOPED_SET_RESET (SCOPED_SET_RESET const &)=delete
 
SCOPED_SET_RESET & operator= (SCOPED_SET_RESET const &)=delete
 

Private Attributes

VAL_TYPE m_original
 
VAL_TYPE & m_target
 

Detailed Description

template<typename VAL_TYPE>
class SCOPED_SET_RESET< VAL_TYPE >

RAII class that sets an value at construction and resets it to the original value at destruction.

Note
There is type deduction for template classes from C++17, so you can do this without <int>:
int target = 0;
SCOPED_SET_RESET targetResetter( target, 42 );

Definition at line 35 of file scoped_set_reset.h.

Constructor & Destructor Documentation

◆ SCOPED_SET_RESET() [1/3]

template<typename VAL_TYPE>
SCOPED_SET_RESET< VAL_TYPE >::SCOPED_SET_RESET ( VAL_TYPE & target,
VAL_TYPE value )
inline

Construct the class, set the target to the specified value, and remember the original value.

Whatever the caller does with the target, it will be restored to its original value upon destruction.

Definition at line 45 of file scoped_set_reset.h.

◆ SCOPED_SET_RESET() [2/3]

template<typename VAL_TYPE>
SCOPED_SET_RESET< VAL_TYPE >::SCOPED_SET_RESET ( VAL_TYPE & target)
inline

Construct the class and remember the original value of the target, but without changing it immediately.

In any case, the original value will be restored upon destruction.

Definition at line 58 of file scoped_set_reset.h.

◆ ~SCOPED_SET_RESET()

template<typename VAL_TYPE>
SCOPED_SET_RESET< VAL_TYPE >::~SCOPED_SET_RESET ( )
inline

Destruct the class, and return the target to its original value.

Definition at line 67 of file scoped_set_reset.h.

◆ SCOPED_SET_RESET() [3/3]

template<typename VAL_TYPE>
SCOPED_SET_RESET< VAL_TYPE >::SCOPED_SET_RESET ( SCOPED_SET_RESET< VAL_TYPE > const & )
delete

Member Function Documentation

◆ operator=()

template<typename VAL_TYPE>
SCOPED_SET_RESET & SCOPED_SET_RESET< VAL_TYPE >::operator= ( SCOPED_SET_RESET< VAL_TYPE > const & )
delete

Member Data Documentation

◆ m_original

template<typename VAL_TYPE>
VAL_TYPE SCOPED_SET_RESET< VAL_TYPE >::m_original
private

Definition at line 76 of file scoped_set_reset.h.

◆ m_target

template<typename VAL_TYPE>
VAL_TYPE& SCOPED_SET_RESET< VAL_TYPE >::m_target
private

Definition at line 77 of file scoped_set_reset.h.


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