blob: 84d52e547c52167f0dd4dc47dcefeabc191a7f29 [file] [log] [blame]
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +00001/*
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"
21
22class SkBitSet {
23public:
24 /** NumberOfBits must be greater than zero.
25 */
26 explicit SkBitSet(int numberOfBits);
27 explicit SkBitSet(const SkBitSet& source);
28
29 const SkBitSet& operator=(const SkBitSet& rhs);
30 bool operator==(const SkBitSet& rhs);
31 bool operator!=(const SkBitSet& rhs);
32
33 /** Clear all data.
34 */
35 void clearAll();
36
37 /** Set the value of the index-th bit.
38 */
39 void setBit(int index, bool value);
40
41 /** Test if bit index is set.
42 */
43 bool isBitSet(int index);
44
45 /** Or bits from source. false is returned if this doesn't have the same
46 * bit count as source.
47 */
48 bool orBits(SkBitSet& source);
49
50private:
51 SkAutoFree fBitData;
52 // Dword (32-bit) count of the bitset.
53 size_t fDwordCount;
54 size_t fBitCount;
55
56 uint32_t* internalGet(int index) {
57 SkASSERT((size_t)index < fBitCount);
58 size_t internalIndex = index / 32;
59 SkASSERT(internalIndex < fDwordCount);
60 return (uint32_t*)fBitData.get() + internalIndex;
61 }
62};
63
64
65#endif