/* ///////////////////////////////////////////////////////////////////// // bitio.h of of bitio class for writing bit/s to output file.// // written by sourena maroofi // // // ///////////////////////////////////////////////////////////////////// */ #include #include #include #include #define maxBufferSize 1024 //*1024 using namespace std; enum MODE {FILE_INPUT,FILE_OUTPUT}; class bitio { public: void writeByte(unsigned char *,int); //write one byte to output file /*outputBit write one bit into buffer.bit can be 0 or 1.function return true if succeed and false if fails. check getLastError for error message .*/ //MODE fileMode; static const int out=1; static const int in=0; bool outputBit(int); bool eof(void); bool flushBuffer(void); void getLastError(void); void printBuffer(void); /*inputBit read one bit from the internal buffer of bitio class which made from every 256 bytes of the input file. and return 0 or 1 if succeed and -1 if fails.*/ int inputBit(void); bitio(const char *,int); ~bitio(); private: bool error_occured; MODE fileMode; ofstream myFileOut; ifstream myFileIn; unsigned long int fileSize; /*write outputBuffer into file and return true if succeed and false if fails.*/ const char * fileName; string errorMessage; unsigned char * Buffer; unsigned long int bytePos; unsigned long int bitPos; unsigned long int currentPos; unsigned long int hiLimit; bool eof_occured; bool readBlock; bool buffer_is_empty; };