37 #ifndef NVWA_BOOL_ARRAY_H 38 #define NVWA_BOOL_ARRAY_H 72 #if (defined(__x86_64) || defined(__ia64) || defined(__ppc64__) || \ 73 defined(_WIN64) || defined(_M_IA64)) && \ 74 !(defined(_LP64) || defined(__lp64)) 84 typedef unsigned char byte;
87 template <
typename _Byte_type>
91 _Element(_Byte_type* ptr, size_type pos);
92 bool operator=(
bool value);
93 operator bool()
const;
95 _Byte_type* _M_byte_ptr;
104 #if defined(_MSC_VER) && _MSC_VER < 1300 105 enum { npos = (size_type)-1 };
108 static const size_type npos = (size_type)-1;
119 bool create(size_type size) _NOEXCEPT;
120 void initialize(
bool value) _NOEXCEPT;
122 reference operator[](size_type pos);
123 const_reference operator[](size_type pos) const;
125 bool at(size_type pos) const;
126 void reset(size_type pos);
127 void set(size_type pos);
129 size_type size() const _NOEXCEPT;
130 size_type count() const _NOEXCEPT;
131 size_type count(size_type begin, size_type end = npos) const;
132 size_type find(
bool value, size_type offset = 0) const;
133 size_type find(
bool value, size_type offset, size_type count) const;
134 size_type find_until(
bool value, size_type begin, size_type end) const;
136 void flip() _NOEXCEPT;
140 size_type end = npos,
141 size_type offset = 0);
144 size_type end = npos,
145 size_type offset = 0);
146 void copy_to_bitmap(
void* dest, size_type begin = 0, size_type end = npos);
148 static
size_t get_num_bytes_from_bits(size_type num_bits);
151 byte get_8bits(size_type offset, size_type end) const;
155 static byte _S_bit_count[256];
156 static byte _S_bit_ordinal[256];
168 template <typename _Byte_type>
174 _M_byte_pos = (size_t)(pos / 8);
175 _M_bit_pos = (size_t)(pos % 8);
184 template <
typename _Byte_type>
188 *(_M_byte_ptr + _M_byte_pos) |= 1 << _M_bit_pos;
190 *(_M_byte_ptr + _M_byte_pos) &= ~(1 << _M_bit_pos);
199 template <
typename _Byte_type>
202 return *(_M_byte_ptr + _M_byte_pos) & (1 << _M_bit_pos) ? true :
false;
208 inline bool_array::bool_array() _NOEXCEPT : _M_byte_ptr(_NULLPTR), _M_length(0)
215 inline bool_array::~bool_array()
217 if (_M_byte_ptr != _NULLPTR)
230 assert(pos < _M_length);
231 return reference(_M_byte_ptr, pos);
243 assert(pos < _M_length);
244 return const_reference(_M_byte_ptr, pos);
254 inline bool bool_array::at(size_type pos)
const 256 size_t byte_pos, bit_pos;
257 if (pos >= _M_length)
258 throw std::out_of_range(
"invalid bool_array position");
259 byte_pos = (size_t)(pos / 8);
260 bit_pos = (size_t)(pos % 8);
261 return *(_M_byte_ptr + byte_pos) & (1 << bit_pos) ? true :
false;
270 inline void bool_array::reset(size_type pos)
272 size_t byte_pos, bit_pos;
273 if (pos >= _M_length)
274 throw std::out_of_range(
"invalid bool_array position");
275 byte_pos = (size_t)(pos / 8);
276 bit_pos = (size_t)(pos % 8);
277 *(_M_byte_ptr + byte_pos) &= ~(1 << bit_pos);
286 inline void bool_array::set(size_type pos)
288 size_t byte_pos, bit_pos;
289 if (pos >= _M_length)
290 throw std::out_of_range(
"invalid bool_array position");
291 byte_pos = (size_t)(pos / 8);
292 bit_pos = (size_t)(pos % 8);
293 *(_M_byte_ptr + byte_pos) |= 1 << bit_pos;
317 size_type offset)
const 319 return find_until(value, offset, _M_length);
336 size_type count)
const 338 return find_until(value, offset, offset + count);
347 inline size_t bool_array::get_num_bytes_from_bits(size_type num_bits)
349 return (
size_t)((num_bits + 7) / 8);
365 #endif // NVWA_BOOL_ARRAY_H _Element< const byte > const_reference
Type of const reference.
Definition: bool_array.h:102
unsigned long size_type
Type of array indices.
Definition: bool_array.h:79
Class to represent a packed boolean array.
Definition: bool_array.h:69
void swap(bool_array &lhs, bool_array &rhs) noexcept
Exchanges the content of two bool_arrays.
Definition: bool_array.h:358
unsigned char byte
Private definition of byte to avoid polluting the global namespace.
Definition: bool_array.h:84
Class to represent a reference to an array element.
Definition: bool_array.h:88
C++11 feature detection macros and workarounds.
_Element< byte > reference
Type of reference.
Definition: bool_array.h:101
Common definitions for preprocessing.