BitFlag.h
Go to the documentation of this file.
1 
2 // This source file is part of the ZipArchive Library Open Source distribution
3 // and is Copyrighted 2000 - 2022 by Artpol Software - Tadeusz Dracz
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // For the licensing details refer to the License.txt file.
11 //
12 // Web Site: https://www.artpol-software.com
14 
20 #if !defined(ZIPARCHIVE_BITFLAG_DOT_H)
21 #define ZIPARCHIVE_BITFLAG_DOT_H
22 
23 #if _MSC_VER > 1000
24  #pragma once
25 #endif
26 
27 namespace ZipArchiveLib
28 {
32  struct ZIP_API CBitFlag
33  {
34  public:
35 
39  int m_value;
40 
45  :m_value(0)
46  {
47  }
48 
55  CBitFlag(int value)
56  :m_value(value)
57  {
58  }
59 
66  void Set(int flags)
67  {
68  m_value |= flags;
69  }
70 
77  void Clear(int flags)
78  {
79  m_value &= ~flags;
80  }
81 
91  bool IsSetAny(int flags) const
92  {
93  return (m_value & flags) != 0;
94  }
95 
96 
106  bool IsSetAll(int flags) const
107  {
108  return (m_value & flags) == flags;
109  }
110 
111 
121  bool SetWithCheck(int flags)
122  {
123  if (!IsSetAll(flags))
124  {
125  Set(flags);
126  return true;
127  }
128  else
129  return false;
130  }
131 
141  bool ClearWithCheck(int flags)
142  {
143  if (IsSetAny(flags))
144  {
145  Clear(flags);
146  return true;
147  }
148  else
149  return false;
150  }
151 
163  bool ChangeWithCheck(int flags, bool set)
164  {
165  return set ? SetWithCheck(flags) : ClearWithCheck(flags);
166  }
167 
177  void Change(int flags, bool set)
178  {
179  set ? Set(flags) : Clear(flags);
180  }
181 
185  operator int() const
186  {
187  return m_value;
188  }
189 
190  CBitFlag& operator = (const CBitFlag& flag)
191  {
192  m_value = flag.m_value;
193  return *this;
194  }
195 
196  bool operator == (int value)
197  {
198  return m_value == value;
199  }
200 
201  bool operator == (const CBitFlag& flag)
202  {
203  return m_value == flag.m_value;
204  }
205  };
206 }
207 
208 #endif
209 
210 

The ZipArchive Library Copyright © 2000 - 2022 Artpol Software - Tadeusz Dracz. Generated at Sat Dec 17 2022 19:57:03.