Xalan-C++ API Reference 1.12.0
XalanBitmap.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(XALANBITMAP_HEADER_GUARD_1357924680)
19#define XALANBITMAP_HEADER_GUARD_1357924680
20
21
22
23// Base include file. Must be first.
25
26
27
29
30
31
32namespace XALAN_CPP_NAMESPACE {
33
34
35
37{
38public:
39
40 // The basic storage unit for the bitmaps.
41 typedef char UnitType;
42
43 // A handy typedef...
44 typedef size_t size_type;
45
46 // Really all we're assuming is that a char is at least
47 // 8 bits. If it's more, then we'll just waste some
48 // space. This may need to be adjusted for various
49 // platforms, or perhaps change to using an integral of
50 // a known size, so that we don't waste any space.
51 enum { eBitsPerUnit = 8 };
52
53
54 /**
55 * Construct an instance with room for the specified number
56 * of bits.
57 *
58 * @param theSize The number of bits in the map.
59 */
61
63
64
65 /**
66 * Determine if a bit is set.
67 *
68 * @param theBit The number of the bit to check.
69 * @return true if the bit is set, false if not.
70 */
71 bool
73 {
74 assert(theBit >= m_size);
75
76 return m_bitmap[theBit / eBitsPerUnit] & s_setMasks[theBit % eBitsPerUnit] ? true : false;
77 }
78
79 /**
80 * Set a bit.
81 *
82 * @param theBit The number of the bit to set.
83 */
84 void
86 {
87 assert(theBit < m_size);
88
89 m_bitmap[theBit / eBitsPerUnit] |= s_setMasks[theBit % eBitsPerUnit];
90 }
91
92 /**
93 * Clear a bit.
94 *
95 * @param theBit The number of the bit to clear.
96 */
97 void
99 {
100 assert(theBit < m_size);
101
102 m_bitmap[theBit / eBitsPerUnit] &= s_clearMasks[theBit % eBitsPerUnit];
103 }
104
105 /**
106 * Toggle a bit.
107 *
108 * @param theBit The number of the bit to toggle.
109 */
110 void
112 {
113 assert(theBit < m_size);
114
115 m_bitmap[theBit / eBitsPerUnit] ^= s_setMasks[theBit % eBitsPerUnit];
116 }
117
118 /**
119 * Clear all of the bits.
120 */
121 void
123
124 /**
125 * Get the size of the map.
126 *
127 * @return The number of bits in the map.
128 */
130 getSize() const
131 {
132 return m_size;
133 }
134
135private:
136
137 static const int s_setMasks[];
138
139 static const int s_clearMasks[];
140
141
142 typedef XalanVector<UnitType> BitmapVectorType;
143
144 const size_type m_size;
145
146 BitmapVectorType m_bitmap;
147};
148
149
150
151}
152
153
154
155#endif // XALANBITMAP_HEADER_GUARD_1357924680
#define XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
size_type getSize() const
Get the size of the map.
XalanBitmap(MemoryManager &theManager, size_type theSize)
Construct an instance with room for the specified number of bits.
void set(size_type theBit)
Set a bit.
bool isSet(size_type theBit) const
Determine if a bit is set.
void clear(size_type theBit)
Clear a bit.
void clearAll()
Clear all of the bits.
void toggle(size_type theBit)
Toggle a bit.
size_t size_type
Definition XalanMap.hpp:46