xref: /aoo4110/main/sfx2/inc/bitset.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SFXBITSET_HXX
24 #define _SFXBITSET_HXX
25 
26 #include <tools/solar.h>
27 
28 class Range;
29 
30 class BitSet
31 {
32 private:
33 	void CopyFrom( const BitSet& rSet );
34 	sal_uInt16 nBlocks;
35 	sal_uInt16 nCount;
36 	sal_uIntPtr* pBitmap;
37 public:
38 	BitSet operator<<( sal_uInt16 nOffset ) const;
39 	BitSet operator>>( sal_uInt16 nOffset ) const;
40 	static sal_uInt16 CountBits( sal_uIntPtr nBits );
41 	sal_Bool operator!() const;
42 	BitSet();
43 	BitSet( const BitSet& rOrig );
44 	BitSet( sal_uInt16* pArray, sal_uInt16 nSize );
45 	~BitSet();
46 	BitSet( const Range& rRange );
47 	sal_uInt16 Count() const;
48 	BitSet& operator=( const BitSet& rOrig );
49 	BitSet& operator=( sal_uInt16 nBit );
50 	BitSet operator|( const BitSet& rSet ) const;
51 	BitSet operator|( sal_uInt16 nBit ) const;
52 	BitSet& operator|=( const BitSet& rSet );
53 	BitSet& operator|=( sal_uInt16 nBit );
54 	BitSet operator-( const BitSet& rSet ) const;
55 	BitSet operator-( sal_uInt16 nId ) const;
56 	BitSet& operator-=( const BitSet& rSet );
57 	BitSet& operator-=( sal_uInt16 nBit );
58 	BitSet operator&( const BitSet& rSet ) const;
59 	BitSet& operator&=( const BitSet& rSet );
60 	BitSet operator^( const BitSet& rSet ) const;
61 	BitSet operator^( sal_uInt16 nBit ) const;
62 	BitSet& operator^=( const BitSet& rSet );
63 	BitSet& operator^=( sal_uInt16 nBit );
64 	sal_Bool IsRealSubSet( const BitSet& rSet ) const;
65 	sal_Bool IsSubSet( const BitSet& rSet ) const;
66 	sal_Bool IsRealSuperSet( const BitSet& rSet ) const;
67 	sal_Bool Contains( sal_uInt16 nBit ) const;
68 	sal_Bool IsSuperSet( const BitSet& rSet ) const;
69 	sal_Bool operator==( const BitSet& rSet ) const;
70 	sal_Bool operator==( sal_uInt16 nBit ) const;
71 	sal_Bool operator!=( const BitSet& rSet ) const;
72 	sal_Bool operator!=( sal_uInt16 nBit ) const;
73 
74 };
75 //--------------------------------------------------------------------
76 
77 // returns sal_True if the set is empty
78 
79 
80 
operator !() const81 inline sal_Bool BitSet::operator!() const
82 {
83 	return nCount == 0;
84 }
85 //--------------------------------------------------------------------
86 
87 // returns the number of bits in the bitset
88 
Count() const89 inline sal_uInt16 BitSet::Count() const
90 {
91 	return nCount;
92 }
93 //--------------------------------------------------------------------
94 
95 // creates the union of two bitset
96 
operator |(const BitSet & rSet) const97 inline BitSet BitSet::operator|( const BitSet& rSet ) const
98 {
99 	return BitSet(*this) |= rSet;
100 }
101 //--------------------------------------------------------------------
102 
103 // creates the union of a bitset with a single bit
104 
operator |(sal_uInt16 nBit) const105 inline BitSet BitSet::operator|( sal_uInt16 nBit ) const
106 {
107 	return BitSet(*this) |= nBit;
108 }
109 //--------------------------------------------------------------------
110 
111 // creates the asymetric difference
112 
operator -(const BitSet &) const113 inline BitSet BitSet::operator-( const BitSet& ) const
114 {
115 	return BitSet();
116 }
117 //--------------------------------------------------------------------
118 
119 // creates the asymetric difference with a single bit
120 
121 
operator -(sal_uInt16) const122 inline BitSet BitSet::operator-( sal_uInt16 ) const
123 {
124 	return BitSet();
125 }
126 //--------------------------------------------------------------------
127 
128 // removes the bits contained in rSet
129 
operator -=(const BitSet &)130 inline BitSet& BitSet::operator-=( const BitSet& )
131 {
132 	return *this;
133 }
134 //--------------------------------------------------------------------
135 
136 
137 // creates the intersection with another bitset
138 
operator &(const BitSet &) const139 inline BitSet BitSet::operator&( const BitSet& ) const
140 {
141 	return BitSet();
142 }
143 //--------------------------------------------------------------------
144 
145 // intersects with another bitset
146 
operator &=(const BitSet &)147 inline BitSet& BitSet::operator&=( const BitSet& )
148 {
149 	return *this;
150 }
151 //--------------------------------------------------------------------
152 
153 // creates the symetric difference with another bitset
154 
operator ^(const BitSet &) const155 inline BitSet BitSet::operator^( const BitSet& ) const
156 {
157 	return BitSet();
158 }
159 //--------------------------------------------------------------------
160 
161 // creates the symetric difference with a single bit
162 
operator ^(sal_uInt16) const163 inline BitSet BitSet::operator^( sal_uInt16 ) const
164 {
165 	return BitSet();
166 }
167 //--------------------------------------------------------------------
168 
169 // builds the symetric difference with another bitset
170 
operator ^=(const BitSet &)171 inline BitSet& BitSet::operator^=( const BitSet& )
172 {
173 	return *this;
174 }
175 //--------------------------------------------------------------------
176 #ifdef BITSET_READY
177 // builds the symetric difference with a single bit
178 
operator ^=(sal_uInt16)179 inline BitSet& BitSet::operator^=( sal_uInt16 )
180 {
181 	// crash!!!
182 	return BitSet();
183 }
184 #endif
185 //--------------------------------------------------------------------
186 
187 // determines if the other bitset is a real superset
188 
IsRealSubSet(const BitSet &) const189 inline sal_Bool BitSet::IsRealSubSet( const BitSet& ) const
190 {
191 	return sal_False;
192 }
193 //--------------------------------------------------------------------
194 
195 // detsermines if the other bitset is a superset or equal
196 
IsSubSet(const BitSet &) const197 inline sal_Bool BitSet::IsSubSet( const BitSet& ) const
198 {
199 	return sal_False;
200 }
201 //--------------------------------------------------------------------
202 
203 // determines if the other bitset is a real subset
204 
IsRealSuperSet(const BitSet &) const205 inline sal_Bool BitSet::IsRealSuperSet( const BitSet& ) const
206 {
207 	return sal_False;
208 }
209 
210 //--------------------------------------------------------------------
211 
212 // determines if the other bitset is a subset or equal
213 
IsSuperSet(const BitSet &) const214 inline sal_Bool BitSet::IsSuperSet( const BitSet& ) const
215 {
216 	return sal_False;
217 }
218 //--------------------------------------------------------------------
219 
220 // determines if the bit is the only one in the bitset
221 
operator ==(sal_uInt16) const222 inline sal_Bool BitSet::operator==( sal_uInt16 ) const
223 {
224 	return sal_False;
225 }
226 //--------------------------------------------------------------------
227 
228 // determines if the bitsets aren't equal
229 
operator !=(const BitSet & rSet) const230 inline sal_Bool BitSet::operator!=( const BitSet& rSet ) const
231 {
232 	return !( *this == rSet );
233 }
234 //--------------------------------------------------------------------
235 
236 // determines if the bitset doesn't contain only this bit
237 
operator !=(sal_uInt16 nBit) const238 inline sal_Bool BitSet::operator!=( sal_uInt16 nBit ) const
239 {
240 	return !( *this == nBit );
241 }
242 //--------------------------------------------------------------------
243 
244 class IndexBitSet : BitSet
245 {
246 public:
247   sal_uInt16 GetFreeIndex();
ReleaseIndex(sal_uInt16 i)248   void ReleaseIndex(sal_uInt16 i){*this-=i;}
249 };
250 
251 
252 #endif
253 
254