epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 1 | |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 3 | * Copyright 2011 Google Inc. |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 9 | |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 10 | #ifndef SkBitSet_DEFINED |
| 11 | #define SkBitSet_DEFINED |
| 12 | |
| 13 | #include "SkTypes.h" |
vandebo@chromium.org | 17e66e2 | 2011-07-27 20:59:55 +0000 | [diff] [blame] | 14 | #include "SkTDArray.h" |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 15 | |
| 16 | class SkBitSet { |
| 17 | public: |
| 18 | /** NumberOfBits must be greater than zero. |
| 19 | */ |
| 20 | explicit SkBitSet(int numberOfBits); |
| 21 | explicit SkBitSet(const SkBitSet& source); |
| 22 | |
| 23 | const SkBitSet& operator=(const SkBitSet& rhs); |
| 24 | bool operator==(const SkBitSet& rhs); |
| 25 | bool operator!=(const SkBitSet& rhs); |
| 26 | |
| 27 | /** Clear all data. |
| 28 | */ |
| 29 | void clearAll(); |
| 30 | |
| 31 | /** Set the value of the index-th bit. |
| 32 | */ |
| 33 | void setBit(int index, bool value); |
| 34 | |
| 35 | /** Test if bit index is set. |
| 36 | */ |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 37 | bool isBitSet(int index) const; |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 38 | |
| 39 | /** Or bits from source. false is returned if this doesn't have the same |
| 40 | * bit count as source. |
| 41 | */ |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 42 | bool orBits(const SkBitSet& source); |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 43 | |
vandebo@chromium.org | 17e66e2 | 2011-07-27 20:59:55 +0000 | [diff] [blame] | 44 | /** Export set bits to unsigned int array. (used in font subsetting) |
| 45 | */ |
| 46 | void exportTo(SkTDArray<uint32_t>* array) const; |
| 47 | |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 48 | private: |
| 49 | SkAutoFree fBitData; |
| 50 | // Dword (32-bit) count of the bitset. |
| 51 | size_t fDwordCount; |
| 52 | size_t fBitCount; |
| 53 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 54 | uint32_t* internalGet(int index) const { |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 55 | SkASSERT((size_t)index < fBitCount); |
| 56 | size_t internalIndex = index / 32; |
| 57 | SkASSERT(internalIndex < fDwordCount); |
| 58 | return (uint32_t*)fBitData.get() + internalIndex; |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | #endif |