blob: 4791df4de51fb7d73268f8503bc2ab392c51899b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000010#ifndef SkBitSet_DEFINED
11#define SkBitSet_DEFINED
12
13#include "SkTypes.h"
vandebo@chromium.org17e66e22011-07-27 20:59:55 +000014#include "SkTDArray.h"
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000015
16class SkBitSet {
17public:
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.org98594282011-07-25 22:34:12 +000037 bool isBitSet(int index) const;
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000038
39 /** Or bits from source. false is returned if this doesn't have the same
40 * bit count as source.
41 */
vandebo@chromium.org98594282011-07-25 22:34:12 +000042 bool orBits(const SkBitSet& source);
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000043
vandebo@chromium.org17e66e22011-07-27 20:59:55 +000044 /** Export set bits to unsigned int array. (used in font subsetting)
45 */
46 void exportTo(SkTDArray<uint32_t>* array) const;
47
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000048private:
49 SkAutoFree fBitData;
50 // Dword (32-bit) count of the bitset.
51 size_t fDwordCount;
52 size_t fBitCount;
53
vandebo@chromium.org98594282011-07-25 22:34:12 +000054 uint32_t* internalGet(int index) const {
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000055 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