]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/set.h
7457b0f97d614ed9977fc2b84b3fec9314462000
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 "set.h"
19 // wxSet 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 wxSet
26 friend class wxEnumData
;
28 wxSet() { m_data
= 0; }
29 wxSet(const wxSet
&src
) { m_data
= src
.m_data
; }
30 wxSet(const T el
) { m_data
|= 1 << el
; }
31 wxSet
&operator =(const wxSet
&rhs
)
36 wxSet
&operator +=(const wxSet
&rhs
) // union
41 wxSet
&operator -=(const wxSet
&rhs
) // difference
47 wxSet
&operator *=(const wxSet
&rhs
) // intersection
53 wxSet
operator +(const wxSet
&rhs
) const // union
56 s
.m_data
= m_data
| rhs
.m_data
;
59 wxSet
operator -(const wxSet
&rhs
) const // difference
62 s
.m_data
= m_data
^ rhs
.m_data
;
65 wxSet
operator *(const wxSet
&rhs
) const // intersection
68 s
.m_data
= m_data
& rhs
.m_data
;
72 wxSet
& Set(const T el
) //Add element
77 wxSet
& Clear(const T el
) //remove element
83 bool Contains(const T el
) const
85 return (m_data
& (1 << el
)) ? true : false;
99 bool operator ==(const wxSet
&rhs
) const
101 return m_data
== rhs
.m_data
;
104 bool operator !=(const wxSet
&rhs
) const
106 return !operator==(rhs
);