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 ()
 Function ~SCOPED_SET_RESET. 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 45 of file scoped_set_reset.h.

Constructor & Destructor Documentation

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

Definition at line 49 of file scoped_set_reset.h.

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

50  :
51  m_target( target )
52  {
53  m_original = target;
54  m_target = value;
55  }
template<typename VAL_TYPE >
SCOPED_SET_RESET< VAL_TYPE >::~SCOPED_SET_RESET ( )
inline

Function ~SCOPED_SET_RESET.

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

Definition at line 63 of file scoped_set_reset.h.

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

64  {
66  }

Member Data Documentation

template<typename VAL_TYPE >
VAL_TYPE SCOPED_SET_RESET< VAL_TYPE >::m_original
private
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: