00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00021 #if !defined(ZIPARCHIVE_BITFLAG_DOT_H)
00022 #define ZIPARCHIVE_BITFLAG_DOT_H
00023
00024 #if _MSC_VER > 1000
00025 #pragma once
00026 #endif
00027
00028 namespace ZipArchiveLib
00029 {
00033 struct ZIP_API CBitFlag
00034 {
00035 public:
00036
00040 int m_value;
00041
00045 CBitFlag()
00046 :m_value(0)
00047 {
00048 }
00049
00056 CBitFlag(int value)
00057 :m_value(value)
00058 {
00059 }
00060
00067 void Set(int flags)
00068 {
00069 m_value |= flags;
00070 }
00071
00078 void Clear(int flags)
00079 {
00080 m_value &= ~flags;
00081 }
00082
00092 bool IsSetAny(int flags) const
00093 {
00094 return (m_value & flags) != 0;
00095 }
00096
00097
00107 bool IsSetAll(int flags) const
00108 {
00109 return (m_value & flags) == flags;
00110 }
00111
00112
00122 bool SetWithCheck(int flags)
00123 {
00124 if (!IsSetAll(flags))
00125 {
00126 Set(flags);
00127 return true;
00128 }
00129 else
00130 return false;
00131 }
00132
00142 bool ClearWithCheck(int flags)
00143 {
00144 if (IsSetAny(flags))
00145 {
00146 Clear(flags);
00147 return true;
00148 }
00149 else
00150 return false;
00151 }
00152
00164 bool ChangeWithCheck(int flags, bool set)
00165 {
00166 return set ? SetWithCheck(flags) : ClearWithCheck(flags);
00167 }
00168
00178 void Change(int flags, bool set)
00179 {
00180 set ? Set(flags) : Clear(flags);
00181 }
00182
00186 operator int() const
00187 {
00188 return m_value;
00189 }
00190
00191 CBitFlag& operator = (const CBitFlag& flag)
00192 {
00193 m_value = flag.m_value;
00194 return *this;
00195 }
00196
00197 bool operator == (int value)
00198 {
00199 return m_value == value;
00200 }
00201
00202 bool operator == (const CBitFlag& flag)
00203 {
00204 return m_value == flag.m_value;
00205 }
00206 };
00207 }
00208
00209 #endif
00210
00211