From 5c721f719e8e99d305ccc9dce42741e4c173b4f2 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sun, 4 Sep 2005 15:00:50 +0000 Subject: [PATCH] A more complete implementation. --- src/common/bit_cursor.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/common/bit_cursor.h b/src/common/bit_cursor.h index 15fa6df86..542d48e95 100644 --- a/src/common/bit_cursor.h +++ b/src/common/bit_cursor.h @@ -117,10 +117,10 @@ public: } void byte_align() { - if (out_of_data) - throw mm_io_eof_error_c(); if (bits_valid == 8) return; + if (out_of_data) + throw mm_io_eof_error_c(); bits_valid = 0; byte_position += 1; } @@ -176,7 +176,7 @@ public: } } - void put_bit(int bit) { + void put_bit(bool bit) { if (byte_position >= end_of_data) { out_of_data = true; throw mm_io_eof_error_c(); @@ -207,6 +207,18 @@ public: byte_position = start_of_data + (pos / 8); mask = 0x80 >> (pos % 8); } + + int get_bit_position() { + int i, pos; + + pos = (byte_position - start_of_data) * 8; + for (i = 0; 8 > i; ++i) + if ((0x80 >> i) == mask) { + pos += i; + break; + } + return pos; + } }; #endif // __BIT_CURSOR_H