From 2bc1ad8c2098f8cfa75e4940271024176a489491 Mon Sep 17 00:00:00 2001 From: glenux Date: Sat, 29 Oct 2005 20:17:39 +0000 Subject: [PATCH] --- src/lib/eyd_bitgroup.cpp | 21 +++++++++++++++++++-- src/lib/eyd_bitgroup.hh | 3 +++ src/lib/eyd_bitreader.cpp | 11 ++++------- src/lib/eyd_bitwriter.cpp | 8 ++++---- src/tools/Makefile.am | 6 +++++- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/lib/eyd_bitgroup.cpp b/src/lib/eyd_bitgroup.cpp index c137b27..b7e202a 100644 --- a/src/lib/eyd_bitgroup.cpp +++ b/src/lib/eyd_bitgroup.cpp @@ -24,6 +24,10 @@ namespace EydLib { } } + bool BitGroup::operator!=(const BitGroup &original){ + return ((*this)==original)?false:true; + } + bool BitGroup::operator==(const BitGroup &original){ bool identity = true; if (this->_group_size == original._group_size){ @@ -118,9 +122,22 @@ namespace EydLib { } void BitGroup::setValue(unsigned long int value){ - + unsigned long int val; + val = value; + if (val > this->maxValue()){ + throw eBitGroupOutOfRangeValue(); + } else { + int position = (this->_group_size -1); + while (val>0){ + this->setBitAt(position, val%2); + val = val >> 1; + position--; + } + } + } + unsigned long int BitGroup::maxValue(){ + return ((1 << this->_group_size)-1); } - unsigned long int BitGroup::getValue(){ } diff --git a/src/lib/eyd_bitgroup.hh b/src/lib/eyd_bitgroup.hh index a7599c6..933529f 100644 --- a/src/lib/eyd_bitgroup.hh +++ b/src/lib/eyd_bitgroup.hh @@ -7,6 +7,7 @@ namespace EydLib { class eBitGroupOutOfBound : public std::exception { }; + class eBitGroupOutOfRangeValue : public std::exception { }; class BitGroup { private: @@ -25,6 +26,7 @@ namespace EydLib { bool getBitAt(int pos); void setValue(unsigned long value); + unsigned long maxValue(); unsigned long getValue(); int size(); @@ -33,6 +35,7 @@ namespace EydLib { BitGroup operator=(BitGroup &original); BitGroup operator=(const BitGroup &original); bool operator==(const BitGroup &original); + bool operator!=(const BitGroup &original); // comparer les groupes }; diff --git a/src/lib/eyd_bitreader.cpp b/src/lib/eyd_bitreader.cpp index 7ae2127..3a8cc27 100644 --- a/src/lib/eyd_bitreader.cpp +++ b/src/lib/eyd_bitreader.cpp @@ -55,7 +55,7 @@ namespace EydLib { reader = this->_read_buffer[index_of_char]; if (shift_of_char > 0){ reader = reader << shift_of_char; reader = reader >> shift_of_char; } reader = reader >> (size_of_char - shift_of_char - 1 ); - printf("->%c<- shift %d = %d\n",this->_read_buffer[index_of_char], shift_of_char, reader); + pDEBUG("BitReader::getBitAt","->%c<- shift %d = %d\n",this->_read_buffer[index_of_char], shift_of_char, reader); } return reader; } @@ -72,8 +72,8 @@ namespace EydLib { if (this->_current_bit_position >= (this->_wanted_buffer_size * 8)){ // on charge un nouveau bout de fichier this->_real_buffer_size = ::read(this->_file_desc, this->_read_buffer, this->_wanted_buffer_size); - printf("BitReader::read / read() -> buffer()\n"); - printf("READ BUFFER(%d): %s\n",this->_real_buffer_size, this->_read_buffer); + pDEBUG("BitReader::read","read() -> buffer()\n"); + pDEBUG("BitReader::read","READ BUFFER(%d): %s\n",this->_real_buffer_size, this->_read_buffer); this->_current_bit_position = 0; } if (this->_current_bit_position < this->_real_buffer_size * 8){ @@ -87,19 +87,16 @@ namespace EydLib { throw eBitReaderEndOfFile(); } else { BitGroup eof_bg(i); - printf("SMALLER BITGROUP ! (%d)\n",i); + pDEBUG("BitReader::read","SMALLER BITGROUP ! (%d)\n",i); for (int j=0; j_current_bit_position += 1; } - printf("END result = %s",result.toString().c_str()); return result; } diff --git a/src/lib/eyd_bitwriter.cpp b/src/lib/eyd_bitwriter.cpp index 1e9600f..9784950 100644 --- a/src/lib/eyd_bitwriter.cpp +++ b/src/lib/eyd_bitwriter.cpp @@ -44,7 +44,7 @@ namespace EydLib { int shift_of_char = position % size_of_char; char writer; - printf("BitWriter::setBitAt / pos %d - size %d\n", position, this->_real_buffer_size_in_bits ); + pDEBUG("BitWriter::setBitAt","pos %d - size %d\n", position, this->_real_buffer_size_in_bits ); if (position >= this->_real_buffer_size_in_bits){ throw eBitWriterOutOfBound(); @@ -87,8 +87,8 @@ namespace EydLib { if ((this->_real_buffer_size_in_bits - 1) > this->_bitgroup_size) { // on flush seulement si on a écrit + de 1 bitgroup dans le nouveau // buffer - printf("BitWriter::write / buffer() -> write()\n"); - printf("WRITE_BUFFER(%d chars) = %s\n",nb_chars, this->_write_buffer); + pDEBUG("BitWriter::flush","buffer() -> write()\n"); + pDEBUG("BitWriter::flush","WRITE_BUFFER(%d chars) = %s\n",nb_chars, this->_write_buffer); ::write(this->_file_desc, this->_write_buffer, nb_chars); } @@ -121,7 +121,7 @@ namespace EydLib { void BitWriter::close(){ // on vide le dernier buffer jusqu'a la position réelle... - printf("Remaining %d\n",this->_real_buffer_size_in_bits); + pDEBUG("BitWriter::close","Remaining %d\n",this->_real_buffer_size_in_bits); this->flush(); ::close(this->_file_desc); } diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index 3a140e2..c660973 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = . -bin_PROGRAMS = eyd bittest bitcopy +bin_PROGRAMS = eyd bittest bitcopy bitcompress eyd_SOURCES = eyd_console.cpp eyd_init.cpp eyd_LDADD = -leyd @@ -33,3 +33,7 @@ bitcopy_SOURCES = bitcopy.cpp bitcopy_LDADD = -leyd bitcopy_LDFLAGS = @LDFLAGS@ -L../lib -L../lib/.libs +bitcompress_SOURCES = bitcompress.cpp +bitcompress_LDADD = -leyd +bitcompress_LDFLAGS = @LDFLAGS@ -L../lib -L../lib/.libs +