~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_bitmap.h

Merge Trond

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 * @brief Represents a dynamically sized bitmap.
29
29
 *
30
30
 * Handling of unsigned char arrays as large bitmaps.
31
 
 * 
 
31
 *
32
32
 * API limitations (or, rather asserted safety assumptions,
33
33
 * to encourage correct programming)
34
34
 *   - the internal size is a set of 32 bit words
36
36
 *     greater than 0
37
37
 *
38
38
 * Original version created by Sergei Golubchik 2001 - 2004.
39
 
 * New version written and test program added and some changes to the 
40
 
 * interface was made by Mikael Ronström 2005, with assistance of Tomas 
 
39
 * New version written and test program added and some changes to the
 
40
 * interface was made by Mikael Ronström 2005, with assistance of Tomas
41
41
 * Ulin and Mats Kindahl.
42
42
 */
43
43
class MyBitmap
161
161
   */
162
162
  bool isBitSet(const uint32_t bit) const
163
163
  {
164
 
    return (bool)(((unsigned char *)bitmap)[bit / 8] &  (1 << ((bit) & 7)));
 
164
     return (bool)((reinterpret_cast<unsigned char *>(bitmap))[bit / 8] &  (1 << ((bit) & 7)));
165
165
  }
166
166
 
167
167
  /**
171
171
   */
172
172
  void setBit(const uint32_t bit)
173
173
  {
174
 
    reinterpret_cast<unsigned char *>(bitmap)[bit / 8]= 
 
174
    reinterpret_cast<unsigned char *>(bitmap)[bit / 8]=
175
175
      static_cast<unsigned char>(
176
 
      (reinterpret_cast<unsigned char *>(bitmap))[bit / 8] | 
 
176
      (reinterpret_cast<unsigned char *>(bitmap))[bit / 8] |
177
177
      (1 << ((bit) & 7)));
178
178
  }
179
179
 
184
184
   */
185
185
  void flipBit(const uint32_t bit)
186
186
  {
187
 
    reinterpret_cast<unsigned char *>(bitmap)[bit / 8]= 
 
187
    reinterpret_cast<unsigned char *>(bitmap)[bit / 8]=
188
188
      static_cast<unsigned char>(
189
 
      (reinterpret_cast<unsigned char *>(bitmap))[bit / 8] ^ 
 
189
      (reinterpret_cast<unsigned char *>(bitmap))[bit / 8] ^
190
190
      (1 << ((bit) & 7)));
191
191
  }
192
192
 
197
197
   */
198
198
  void clearBit(const uint32_t bit)
199
199
  {
200
 
    reinterpret_cast<unsigned char *>(bitmap)[bit / 8]= 
 
200
    reinterpret_cast<unsigned char *>(bitmap)[bit / 8]=
201
201
      static_cast<unsigned char>(
202
 
      (reinterpret_cast<unsigned char *>(bitmap))[bit / 8] & 
 
202
      (reinterpret_cast<unsigned char *>(bitmap))[bit / 8] &
203
203
      ~ (1 << ((bit) & 7)));
204
204
  }
205
205
 
268
268
  /**
269
269
   * Obtains the number of used bits (1..8) in the last
270
270
   * byte and creates a mask with the upper 'unused' bits
271
 
   * set and the lower 'used' bits clear. 
 
271
   * set and the lower 'used' bits clear.
272
272
   */
273
273
  void createLastWordMask();
274
274
 
341
341
{
342
342
  map1->addMaskToLastWord();
343
343
  map2->addMaskToLastWord();
344
 
  return memcmp((map1)->getBitmap(), 
 
344
  return memcmp((map1)->getBitmap(),
345
345
                (map2)->getBitmap(),
346
346
                4*map1->numOfWordsInMap()) == 0;
347
347
}