vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SkBitSet_DEFINED |
| 18 | #define SkBitSet_DEFINED |
| 19 | |
| 20 | #include "SkTypes.h" |
vandebo@chromium.org | 17e66e2 | 2011-07-27 20:59:55 +0000 | [diff] [blame^] | 21 | #include "SkTDArray.h" |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 22 | |
| 23 | class SkBitSet { |
| 24 | public: |
| 25 | /** NumberOfBits must be greater than zero. |
| 26 | */ |
| 27 | explicit SkBitSet(int numberOfBits); |
| 28 | explicit SkBitSet(const SkBitSet& source); |
| 29 | |
| 30 | const SkBitSet& operator=(const SkBitSet& rhs); |
| 31 | bool operator==(const SkBitSet& rhs); |
| 32 | bool operator!=(const SkBitSet& rhs); |
| 33 | |
| 34 | /** Clear all data. |
| 35 | */ |
| 36 | void clearAll(); |
| 37 | |
| 38 | /** Set the value of the index-th bit. |
| 39 | */ |
| 40 | void setBit(int index, bool value); |
| 41 | |
| 42 | /** Test if bit index is set. |
| 43 | */ |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 44 | bool isBitSet(int index) const; |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 45 | |
| 46 | /** Or bits from source. false is returned if this doesn't have the same |
| 47 | * bit count as source. |
| 48 | */ |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 49 | bool orBits(const SkBitSet& source); |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 50 | |
vandebo@chromium.org | 17e66e2 | 2011-07-27 20:59:55 +0000 | [diff] [blame^] | 51 | /** Export set bits to unsigned int array. (used in font subsetting) |
| 52 | */ |
| 53 | void exportTo(SkTDArray<uint32_t>* array) const; |
| 54 | |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 55 | private: |
| 56 | SkAutoFree fBitData; |
| 57 | // Dword (32-bit) count of the bitset. |
| 58 | size_t fDwordCount; |
| 59 | size_t fBitCount; |
| 60 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 61 | uint32_t* internalGet(int index) const { |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 62 | SkASSERT((size_t)index < fBitCount); |
| 63 | size_t internalIndex = index / 32; |
| 64 | SkASSERT(internalIndex < fDwordCount); |
| 65 | return (uint32_t*)fBitData.get() + internalIndex; |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | #endif |