]> git.saurik.com Git - wxWidgets.git/blob - include/wx/set.h
moved wxWave, wxJoystick and wxTaskBarIcon to wxAdvanced
[wxWidgets.git] / include / wx / set.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/set.h
3 // Purpose: a bitset suited for replacing the current style flags
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 27/07/03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_SETH__
13 #define _WX_SETH__
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "set.h"
17 #endif
18
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
23
24 template <class T> class wxSet
25 {
26 friend class wxEnumData ;
27 public:
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)
32 {
33 m_data = rhs.m_data;
34 return *this;
35 }
36 wxSet &operator +=(const wxSet &rhs) // union
37 {
38 m_data |= rhs.m_data;
39 return *this;
40 }
41 wxSet &operator -=(const wxSet &rhs) // difference
42 {
43 m_data ^= rhs.m_data;
44 return *this;
45 }
46
47 wxSet &operator *=(const wxSet &rhs) // intersection
48 {
49 m_data &= rhs.m_data;
50 return *this;
51 }
52
53 wxSet operator +(const wxSet &rhs) const // union
54 {
55 wxSet<T> s;
56 s.m_data = m_data | rhs.m_data;
57 return s;
58 }
59 wxSet operator -(const wxSet &rhs) const // difference
60 {
61 wxSet<T> s;
62 s.m_data = m_data ^ rhs.m_data;
63 return s;
64 }
65 wxSet operator *(const wxSet &rhs) const // intersection
66 {
67 wxSet<T> s;
68 s.m_data = m_data & rhs.m_data;
69 return s;
70 }
71
72 wxSet& Set(const T el) //Add element
73 {
74 m_data |= 1 << el;
75 return *this;
76 }
77 wxSet& Clear(const T el) //remove element
78 {
79 m_data &= ~(1 << el);
80 return *this;
81 }
82
83 bool Contains(const T el) const
84 {
85 return (m_data & (1 << el)) ? true : false;
86 }
87
88 wxSet &Clear()
89 {
90 m_data = 0;
91 return *this;
92 }
93
94 bool Empty() const
95 {
96 return m_data == 0;
97 }
98
99 bool operator ==(const wxSet &rhs) const
100 {
101 return m_data == rhs.m_data;
102 }
103
104 bool operator !=(const wxSet &rhs) const
105 {
106 return !operator==(rhs);
107 }
108 private :
109 int m_data;
110 };
111
112
113 #endif