--- dyn_bitset2.hpp Mon Jun 3 19:34:54 2002 +++ dyn_bitset.hpp Mon Jun 3 19:50:47 2002 @@ -51,7 +51,7 @@ dyn_bitset_base(size_type num_bits, const Allocator& alloc) : dyn_bitset_alloc_base(alloc), - m_bits(m_alloc.allocate(num_blocks(num_bits))), + m_bits(this->m_alloc.allocate(num_blocks(num_bits))), m_num_bits(num_bits), m_num_blocks(num_blocks(num_bits)) { @@ -60,7 +60,7 @@ } ~dyn_bitset_base() { if (m_bits) - m_alloc.deallocate(m_bits, m_num_blocks); + this->m_alloc.deallocate(m_bits, m_num_blocks); } protected: Block* m_bits; @@ -324,7 +324,7 @@ #ifdef BOOST_OLD_IOSTREAMS template inline std::ostream& -operator<<(std::ostream& os, const dyn_bitset::reference& br) +operator<<(std::ostream& os, const typename dyn_bitset::reference& br) { return os << (bool)br; } @@ -332,7 +332,7 @@ template inline std::basic_ostream& operator<<(std::basic_ostream& os, - const dyn_bitset::reference& br) + const typename dyn_bitset::reference& br) { return os << (bool)br; } @@ -361,8 +361,8 @@ template dyn_bitset:: dyn_bitset(const std::string& s, - std::string::size_type pos, - std::string::size_type n, + typename std::string::size_type pos, + typename std::string::size_type n, const Allocator& alloc) : detail::dyn_bitset_base(std::min(n, s.size() - pos), alloc) @@ -372,8 +372,8 @@ template dyn_bitset:: dyn_bitset(const std::basic_string& s, - std::basic_string::size_type pos, - std::basic_string::size_type n, + typename std::basic_string::size_type pos, + typename std::basic_string::size_type n, const Allocator& alloc) : detail::dyn_bitset_base(std::min(n, s.size() - pos), alloc) @@ -419,7 +419,7 @@ * block_size, alloc) { if (first != last) { - if (m_num_bits == 0) { // dealing with input iterators + if (this->m_num_bits == 0) { // dealing with input iterators this->append(first, last); } else { // dealing with forward iterators, memory has been allocated for (std::size_t i = 0; first != last; ++first, ++i) @@ -435,16 +435,16 @@ : detail::dyn_bitset_base(b.size(), b.m_alloc) { using namespace std; - memcpy(m_bits, b.m_bits, m_num_blocks * sizeof(Block)); + memcpy(this->m_bits, b.m_bits, this->m_num_blocks * sizeof(Block)); } template inline void dyn_bitset::swap(dyn_bitset& b) { - std::swap(m_bits, b.m_bits); - std::swap(m_num_bits, b.m_num_bits); - std::swap(m_num_blocks, b.m_num_blocks); - std::swap(m_alloc, b.m_alloc); + std::swap(this->m_bits, b.m_bits); + std::swap(this->m_num_bits, b.m_num_bits); + std::swap(this->m_num_blocks, b.m_num_blocks); + std::swap(this->m_alloc, b.m_alloc); } template @@ -465,24 +465,24 @@ { if (num_bits == size()) return; - size_type new_nblocks = num_blocks(num_bits); - Block* d = m_alloc.allocate(new_nblocks); + size_type new_nblocks = this->num_blocks(num_bits); + Block* d = this->m_alloc.allocate(new_nblocks); if (num_bits < size()) { // shrink - std::copy(m_bits, m_bits + new_nblocks, d); - std::swap(d, m_bits); - m_alloc.deallocate(d, m_num_blocks); + std::copy(this->m_bits, this->m_bits + new_nblocks, d); + std::swap(d, this->m_bits); + this->m_alloc.deallocate(d, this->m_num_blocks); } else { // grow - std::copy(m_bits, m_bits + m_num_blocks, d); + std::copy(this->m_bits, this->m_bits + this->m_num_blocks, d); Block val = value? ~static_cast(0) : static_cast(0); - std::fill(d + m_num_blocks, d + new_nblocks, val); - std::swap(d, m_bits); - for (std::size_t i = m_num_bits; i < m_num_blocks * block_size; ++i) + std::fill(d + this->m_num_blocks, d + new_nblocks, val); + std::swap(d, this->m_bits); + for (std::size_t i = this->m_num_bits; i < this->m_num_blocks * block_size; ++i) set_(i, value); if (d != 0) - m_alloc.deallocate(d, m_num_blocks); + this->m_alloc.deallocate(d, this->m_num_blocks); } - m_num_bits = num_bits; - m_num_blocks = num_blocks(num_bits); + this->m_num_bits = num_bits; + this->m_num_blocks = this->num_blocks(num_bits); cleanup(); } @@ -490,11 +490,11 @@ void dyn_bitset:: clear() { - if (m_bits != 0) { - m_alloc.deallocate(m_bits, m_num_blocks); - m_bits = 0; - m_num_bits = 0; - m_num_blocks = 0; + if (this->m_bits != 0) { + this->m_alloc.deallocate(this->m_bits, this->m_num_blocks); + this->m_bits = 0; + this->m_num_bits = 0; + this->m_num_blocks = 0; } } @@ -514,7 +514,7 @@ std::size_t old_size = size(); resize(old_size + block_size); if (size() % block_size == 0) - set_block_(m_num_blocks - 1, value); + set_block_(this->m_num_blocks - 1, value); else { for (std::size_t i = old_size; i < size(); ++i, value >>= 1) set_(i, value & 1); @@ -534,7 +534,7 @@ append(*first); } else { // dealing with forward iterators if (size() % block_size == 0) { - std::size_t old_nblocks = m_num_blocks; + std::size_t old_nblocks = this->m_num_blocks; resize(size() + nblocks * block_size); for (std::size_t i = old_nblocks; first != last; ++first, ++i) set_block_(i, *first); @@ -555,8 +555,8 @@ dyn_bitset::operator&=(const dyn_bitset& rhs) { assert(size() == rhs.size()); - for (size_type i = 0; i < m_num_blocks; ++i) - m_bits[i] &= rhs.m_bits[i]; + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] &= rhs.m_bits[i]; return *this; } @@ -565,8 +565,8 @@ dyn_bitset::operator|=(const dyn_bitset& rhs) { assert(size() == rhs.size()); - for (size_type i = 0; i < m_num_blocks; ++i) - m_bits[i] |= rhs.m_bits[i]; + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] |= rhs.m_bits[i]; cleanup(); return *this; } @@ -576,8 +576,8 @@ dyn_bitset::operator^=(const dyn_bitset& rhs) { assert(size() == rhs.size()); - for (size_type i = 0; i < m_num_blocks; ++i) - m_bits[i] ^= rhs.m_bits[i]; + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] ^= rhs.m_bits[i]; cleanup(); return *this; } @@ -586,12 +586,12 @@ dyn_bitset& dyn_bitset::operator<<=(size_type n) { - if (n >= m_num_bits) + if (n >= this->m_num_bits) reset(); else { size_type i; - for (i = m_num_bits - 1; i > n; --i) + for (i = this->m_num_bits - 1; i > n; --i) set_(i,test_(i-n)); if (i == n) // careful, unsigned can't go negative! set_(i,test_(i-n)); @@ -605,14 +605,14 @@ dyn_bitset& dyn_bitset::operator>>=(size_type n) { - if (n >= m_num_bits) + if (n >= this->m_num_bits) reset(); else { size_type i; - for (i = 0; i < m_num_bits - n; ++i) + for (i = 0; i < this->m_num_bits - n; ++i) set_(i,test_(i+n)); - for (i = m_num_bits - n; i < m_num_bits; ++i) + for (i = this->m_num_bits - n; i < this->m_num_bits; ++i) reset_(i); } return *this; @@ -642,7 +642,7 @@ dyn_bitset& dyn_bitset::set(size_type pos, bool val) { - if (pos >= m_num_bits) + if (pos >= this->m_num_bits) throw std::out_of_range("invalid position, dyn_bitset::set(size_type, bool)"); set_(pos, val); return *this; @@ -652,9 +652,9 @@ dyn_bitset& dyn_bitset::set() { - if (m_num_bits > 0) { + if (this->m_num_bits > 0) { using namespace std; - memset(m_bits, ~0u, m_num_blocks * sizeof(m_bits[0])); + memset(this->m_bits, ~0u, this->m_num_blocks * sizeof(this->m_bits[0])); cleanup(); } return *this; @@ -664,7 +664,7 @@ dyn_bitset& dyn_bitset::reset(size_type pos) { - if (pos >= m_num_bits) + if (pos >= this->m_num_bits) throw std::out_of_range("invalid position, dyn_bitset::reset(size_type, bool)"); reset_(pos); return *this; @@ -674,9 +674,9 @@ dyn_bitset& dyn_bitset::reset() { - if (m_num_bits > 0) { + if (this->m_num_bits > 0) { using namespace std; - memset(m_bits, 0, m_num_blocks * sizeof(m_bits[0])); + memset(this->m_bits, 0, this->m_num_blocks * sizeof(this->m_bits[0])); } return *this; } @@ -685,9 +685,9 @@ dyn_bitset& dyn_bitset::flip(size_type pos) { - if (pos >= m_num_bits) + if (pos >= this->m_num_bits) throw std::out_of_range("invalid position, dyn_bitset::toggle(size_type)"); - m_bits[word(pos)] ^= mask1(pos); + this->m_bits[this->word(pos)] ^= this->mask1(pos); return *this; } @@ -695,8 +695,8 @@ dyn_bitset& dyn_bitset::flip() { - for (size_type i = 0; i < m_num_blocks; ++i) - m_bits[i] = ~m_bits[i]; + for (size_type i = 0; i < this->m_num_blocks; ++i) + this->m_bits[i] = ~this->m_bits[i]; cleanup(); return *this; } @@ -704,7 +704,7 @@ template bool dyn_bitset::test(size_type pos) const { - if (pos >= m_num_bits) + if (pos >= this->m_num_bits) throw std::out_of_range("invalid position, dyn_bitset::test(size_type)"); return test_(pos); } @@ -712,8 +712,8 @@ template bool dyn_bitset::any() const { - for (size_type i = 0; i < m_num_blocks; ++i) - if (m_bits[i]) + for (size_type i = 0; i < this->m_num_blocks; ++i) + if (this->m_bits[i]) return 1; return 0; } @@ -738,7 +738,7 @@ dyn_bitset::count() const { size_type sum = 0; - for (size_type i = 0; i < m_num_bits; ++i) + for (size_type i = 0; i < this->m_num_bits; ++i) if (test_(i)) ++sum; return sum; @@ -774,30 +774,30 @@ const std::overflow_error overflow("boost::bit_set::operator unsigned long()"); - if (m_num_blocks == 0) + if (this->m_num_blocks == 0) return 0; if (sizeof(Block) >= sizeof(unsigned long)) { - for (size_type i = 1; i < m_num_blocks; ++i) - if (m_bits[i]) + for (size_type i = 1; i < this->m_num_blocks; ++i) + if (this->m_bits[i]) throw overflow; const Block mask = static_cast(static_cast(-1)); - if (m_bits[0] & ~mask) + if (this->m_bits[0] & ~mask) throw overflow; - return static_cast(m_bits[0] & mask); + return static_cast(this->m_bits[0] & mask); } else { // sizeof(Block) < sizeof(unsigned long). const size_type nwords = (sizeof(unsigned long) + sizeof(Block) - 1) / sizeof(Block); size_type min_nwords = nwords; - if (m_num_blocks > nwords) { - for (size_type i = nwords; i < m_num_blocks; ++i) - if (m_bits[i]) + if (this->m_num_blocks > nwords) { + for (size_type i = nwords; i < this->m_num_blocks; ++i) + if (this->m_bits[i]) throw overflow; } else - min_nwords = m_num_blocks; + min_nwords = this->m_num_blocks; // If unsigned long is 8 bytes and Block is 6 bytes, then // an unsigned long consists of all of one word plus 2 bytes @@ -806,7 +806,7 @@ unsigned long result = 0; for (size_type i = 0; i < min_nwords; ++i) { result |= static_cast( - m_bits[i]) << (i * block_size); + this->m_bits[i]) << (i * block_size); } return result; } @@ -817,7 +817,7 @@ inline typename dyn_bitset::size_type dyn_bitset::size() const { - return m_num_bits; + return this->m_num_bits; } //----------------------------------------------------------------------------- @@ -1062,7 +1062,7 @@ inline void dyn_bitset:: set_(size_type bit) { - m_bits[word(bit)] |= mask1(bit); + this->m_bits[this->word(bit)] |= this->mask1(bit); } template @@ -1080,13 +1080,13 @@ inline void dyn_bitset:: reset_(size_type b) { - m_bits[word(b)] &= mask0(b); + this->m_bits[this->word(b)] &= this->mask0(b); } template inline bool dyn_bitset::test_(size_type b) const { - return (m_bits[word(b)] & mask1(b)) != static_cast(0); + return (this->m_bits[this->word(b)] & this->mask1(b)) != static_cast(0); } template @@ -1108,9 +1108,9 @@ { // Assumes string contains only 0's and 1's for (size_type i = 0; i < rlen; ++i) { - if (s[pos + m_num_bits - i - 1] == '1') + if (s[pos + this->m_num_bits - i - 1] == '1') set_(i); - else if (s[pos + m_num_bits - i - 1] != '0') + else if (s[pos + this->m_num_bits - i - 1] != '0') throw std::invalid_argument("invalid argument, characters in s must be 0 or 1, dyn_bitset::dyn_bitset(const std::string&,...)"); } } @@ -1122,17 +1122,17 @@ { // PRE: distance(first, last) == size() / block_size for (size_type i = 0; first != last; ++first, ++i) - m_bits[i] = *first; + this->m_bits[i] = *first; } template void dyn_bitset::cleanup() { - const std::size_t extrabits = m_num_blocks * block_size - m_num_bits; + const std::size_t extrabits = this->m_num_blocks * block_size - this->m_num_bits; const Block clean_mask = ~static_cast(0) << extrabits; // Make sure unused bits don't get set - if (m_num_bits % block_size) - m_bits[m_num_blocks - 1] &= clean_mask; + if (this->m_num_bits % block_size) + this->m_bits[this->m_num_blocks - 1] &= clean_mask; } } // namespace boost