KiCad PCB EDA Suite
Loading...
Searching...
No Matches
scoped_set_reset.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <utility>
23
34template <typename VAL_TYPE>
36{
37public:
45 SCOPED_SET_RESET( VAL_TYPE& target, VAL_TYPE value ) :
46 m_original( target ),
47 m_target( target )
48 {
49 m_target = std::move( value );
50 }
51
58 SCOPED_SET_RESET( VAL_TYPE& target ) :
59 m_original( target ),
60 m_target( target )
61 {
62 }
63
68
69 // No copy operations allowed or the destructor might reset
70 // the target to its original value multiple times.
71
74
75private:
76 VAL_TYPE m_original;
77 VAL_TYPE& m_target;
78};
79
80
86template <typename Func>
88{
89public:
90 SCOPED_EXECUTION( Func initFunc, Func destroyFunc ) :
91 m_initFunc( initFunc ), m_destroyFunc( destroyFunc )
92 {
93 m_initFunc();
94 }
95
96 // No copy operations allowed or the destructor might execute
97 // the destroy function multiple times.
98
101
103
104private:
107};
SCOPED_EXECUTION(Func initFunc, Func destroyFunc)
SCOPED_EXECUTION & operator=(SCOPED_EXECUTION const &)=delete
SCOPED_EXECUTION(SCOPED_EXECUTION const &)=delete
~SCOPED_SET_RESET()
Destruct the class, and return the target to its original value.
SCOPED_SET_RESET(VAL_TYPE &target)
Construct the class and remember the original value of the target, but without changing it immediatel...
SCOPED_SET_RESET & operator=(SCOPED_SET_RESET const &)=delete
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(SCOPED_SET_RESET const &)=delete