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