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 
32 namespace XALAN_CPP_NAMESPACE {
33 
34 
35 
37 {
38 public:
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  */
60  XalanBitmap(MemoryManager& theManager, size_type theSize);
61 
62  ~XalanBitmap();
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
72  isSet(size_type theBit) const
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
85  set(size_type theBit)
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
98  clear(size_type theBit)
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
122  clearAll();
123 
124  /**
125  * Get the size of the map.
126  *
127  * @return The number of bits in the map.
128  */
129  size_type
130  getSize() const
131  {
132  return m_size;
133  }
134 
135 private:
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
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanVector< UnitType >
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::XalanBitmap::getSize
size_type getSize() const
Get the size of the map.
Definition: XalanBitmap.hpp:130
XalanVector.hpp
xalanc::XalanBitmap::UnitType
char UnitType
Definition: XalanBitmap.hpp:41
XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_PLATFORMSUPPORT_EXPORT
Definition: PlatformSupportDefinitions.hpp:35
PlatformSupportDefinitions.hpp
xalanc::XalanBitmap
Definition: XalanBitmap.hpp:36
xalanc::XalanBitmap::isSet
bool isSet(size_type theBit) const
Determine if a bit is set.
Definition: XalanBitmap.hpp:72
xalanc::XalanBitmap::clear
void clear(size_type theBit)
Clear a bit.
Definition: XalanBitmap.hpp:98
xalanc::XalanBitmap::size_type
size_t size_type
Definition: XalanBitmap.hpp:44
xalanc::XalanBitmap::set
void set(size_type theBit)
Set a bit.
Definition: XalanBitmap.hpp:85
xalanc::XalanBitmap::toggle
void toggle(size_type theBit)
Toggle a bit.
Definition: XalanBitmap.hpp:111