This commit is contained in:
parent
3f109798a4
commit
2bc1ad8c20
5 changed files with 35 additions and 14 deletions
|
@ -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(){
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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<i; j++){
|
||||
eof_bg.setBitAt(j, result.getBitAt(j));
|
||||
}
|
||||
printf("pre-copy\n");
|
||||
result = eof_bg;
|
||||
printf("post-copy\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->_current_bit_position += 1;
|
||||
}
|
||||
printf("END result = %s",result.toString().c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue