]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/flags.h
ec14d2c2b936ad3b6e53f3a918b60400ccdf58ab
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: a bitset suited for replacing the current style flags
4 // Author: Stefan Csomor
8 // Copyright: (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "flags.h"
19 // wxFlags should be applied to an enum, then this can be used like
20 // bitwise operators but keeps the type safety and information, the
21 // enums must be in a sequence , their value determines the bit position
22 // that they represent
24 template <class T
> class wxFlags
26 friend class wxEnumData
;
28 wxFlags(long val
) { m_data
= val
; }
29 wxFlags() { m_data
= 0; }
30 wxFlags(const wxFlags
&src
) { m_data
= src
.m_data
; }
31 wxFlags(const T el
) { m_data
|= 1 << el
; }
33 operator long() const { return m_data
; }
35 wxFlags
&operator =(const wxFlags
&rhs
)
40 wxFlags
&operator +=(const wxFlags
&rhs
) // union
45 wxFlags
&operator -=(const wxFlags
&rhs
) // difference
51 wxFlags
&operator *=(const wxFlags
&rhs
) // intersection
57 wxFlags
operator +(const wxFlags
&rhs
) const // union
60 s
.m_data
= m_data
| rhs
.m_data
;
63 wxFlags
operator -(const wxFlags
&rhs
) const // difference
66 s
.m_data
= m_data
^ rhs
.m_data
;
69 wxFlags
operator *(const wxFlags
&rhs
) const // intersection
72 s
.m_data
= m_data
& rhs
.m_data
;
76 wxFlags
& Set(const T el
) //Add element
81 wxFlags
& Clear(const T el
) //remove element
87 bool Contains(const T el
) const
89 return (m_data
& (1 << el
)) ? true : false;
103 bool operator ==(const wxFlags
&rhs
) const
105 return m_data
== rhs
.m_data
;
108 bool operator !=(const wxFlags
&rhs
) const
110 return !operator==(rhs
);