KiCad PCB EDA Suite
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)
 
 ~SCOPED_SET_RESET ()
 Destruct the class, and return the target to its original value. More...
 

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 no type deduction for template classes until C++17, \ so you can't do this:
int target = 0;
SCOPED_SET_RESET( target, 42 );

Instead, you can use a type alias, for example:

using SCOPED_INT_SET_RESET = SCOPED_SET_RESET<int>;
int target = 0;
SCOPED_INT_SET_RESET( target , 42 );

Definition at line 44 of file scoped_set_reset.h.

Constructor & Destructor Documentation

◆ SCOPED_SET_RESET()

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

Definition at line 48 of file scoped_set_reset.h.

48  :
49  m_target( target )
50  {
51  m_original = target;
52  m_target = value;
53  }

References SCOPED_SET_RESET< VAL_TYPE >::m_original, and SCOPED_SET_RESET< VAL_TYPE >::m_target.

◆ ~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 58 of file scoped_set_reset.h.

59  {
61  }

References SCOPED_SET_RESET< VAL_TYPE >::m_original, and SCOPED_SET_RESET< VAL_TYPE >::m_target.

Member Data Documentation

◆ m_original

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

◆ m_target

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

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