1 /*
2    Drawpile - a collaborative drawing program.
3 
4    Copyright (C) 2019 Calle Laakkonen
5 
6    Drawpile is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10 
11    Drawpile 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 Drawpile.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef CHANGEFLAGS_H
21 #define CHANGEFLAGS_H
22 
23 /**
24  * A set of changes to a bitfield
25  */
26 template<typename Flags>
27 class ChangeFlags {
28 public:
ChangeFlags()29 	ChangeFlags() : m_mask(0), m_changes(0) { }
30 
set(Flags flag,bool value)31 	ChangeFlags &set(Flags flag, bool value)
32 	{
33 		m_mask |= flag;
34 		if(value)
35 			m_changes |= flag;
36 		else
37 			m_changes &= ~flag;
38 
39 		return *this;
40 	}
41 
update(Flags oldFlags)42 	Flags update(Flags oldFlags) const
43 	{
44 		return (oldFlags & ~m_mask) | m_changes;
45 	}
46 
47 private:
48 	Flags m_mask;
49 	Flags m_changes;
50 };
51 
52 #endif
53 
54