/* ///////////////////////////////////////////////////////////////////////////////////////////////////// // bitio.cpp class written by sourena maroofi. // // Email: maroofi[what do you think should be here]gmail.com // // This class contain 2 file(this file and bitio.h). // // you are free to use it anywhere you like. // // use it at your own risk...i am not responsible for any damage caused by this class. // // send your comment or any possible bug (i dont think so!!!) to my email. // // use this class is very simple.just a few function to use: // // *initialize class like this: // // bitio myvar("filename",bitio::in or bitio::out); // // *send bit to write in filename like this: // // myvar.outputBit(1) or myvar.outputBit(0); // // *write buffer to filename like this: // // myvar.flushBuffer(); // // *print out buffer like this: // // myvar.printBuffer(); // // *get any possible error using: // // myvar.getLastError(); // // and Thats it(No more help...easy to use)!!!!!!!! // // sample driver for this class:(copy one file to another bit by bit!!!) // // #include // // #include // // #include "bitio.h" // // using namespace std; // // int main() // // { // // bitio input1("ass.txt",bitio::in); // // bitio output("assss.txt",bitio::out); // // input1.getLastError(); // // while(! input1.eof()) // // { // // output.outputBit(input1.inputBit()); // // } // // output.printBuffer(); // // output.flushBuffer(); // // output.getLastError(); // // input1.getLastError(); // // return 0; // // } // // // // // ///////////////////////////////////////////////////////////////////////////////////////////////////// */ //#include "stdafx.h" #include #include #include #include #include #include "bitio.h" using namespace std; /*********************************************************************************************************/ bitio::bitio(const char * fileName,int mode) { buffer_is_empty=true; errorMessage="No Error Yet"; bytePos=0; error_occured=false; bitPos=0; currentPos=0; eof_occured=false; readBlock=false; hiLimit=0; Buffer=new(nothrow)unsigned char [maxBufferSize]; if (Buffer==0) { cout<<"can not allocate just fuckin 256 bytes of memory for buffer,damn!!!"<fileName=fileName; if ((int)mode==out) { this->fileMode=FILE_OUTPUT; myFileOut.open(fileName,ios::out|ios::binary); if (! myFileOut.is_open()) { errorMessage="can not open fuckin " + (string)fileName +" file...dont know y and dont give a damn!!!"; getLastError(); error_occured=true; exit(1); } } else if ((int)mode==in) { this->fileMode=FILE_INPUT; myFileIn.open(fileName,ios::in|ios::binary); if (!myFileIn.is_open()) { errorMessage="can not open input file " + (string) fileName + " .check if file exist!!!"; getLastError(); error_occured=true; exit(1); } myFileIn.seekg(0,ios::end); fileSize=myFileIn.tellg(); myFileIn.seekg(0,ios::beg); readBlock=false; //cout<<"file size : "<<(unsigned long int)fileSize<>7; if (byteTemp==0) { currentPos++; if (currentPos==hiLimit) { eof_occured=true; } return 0; } else if (byteTemp==1) { currentPos++; if (currentPos==hiLimit) { eof_occured=true; } return 1; } else { cout<<"What the fuck is this??????"<>(7- (bitPos)); if (biti==1) { temp=temp | 0x01; temp=temp<<(7- (bitPos)); Buffer[bytePos]=temp; currentPos++; buffer_is_empty=false; return true; } if (biti==0) { temp=temp & 0xfe; currentPos++; temp=temp<<(7- (bitPos)); Buffer[bytePos]=temp; buffer_is_empty=false; return true; } return false; } /**************************************************************************************************/ void bitio::printBuffer(void) { if (error_occured==true) { cout<<"Error occured...check getLastError() ."<=0;i--) { temp=temp>>i; temp=temp | 0x01; temp=temp<>k; this->outputBit(tempo); tempo=0; bitmask=bitmask>>1; } tempo=0;temp=0; bitmask=0x80; } } return; } /*********************************************************************************************************/