void Hoffman::archiving(std::ifstream &f,std::ofstream &g,std::map<char,int> &counting) { int sz = counting.size(); g.write(reinterpret_cast<char *>(&sz), sizeof(sz)); for (std::map<char, int>::iterator i = counting.begin(); i != counting.end(); ++i) { char fr = i->first; int sc = i->second; g.write(reinterpret_cast<char *>(&fr), sizeof(char)); g.write(reinterpret_cast<char *>(&sc), sizeof(int)); } while((c1=f.get()) != EOF)//считали из файла букву,чтобы входили и пробелы { std::vector<bool>x=catalogue[c1];//использу¤ ключ мы выводим код for(int n=0;n<x.size();n++) { if(DEBUG) std::cout <<x[n];//выведем на экран ///////выведем в файл/////// buf=buf | x[n]<<(7-count);//изначально buf 00000000 count++; if(count==8){count=0;g.put(buf);buf=0;} } std::cout<<" "; } if( count > 0) g.put(buf); std::cout<<std::endl; }
/* This function includes an optional tab size selecter, but defaults at 4 spaces */ void replaceTabs(std::ifstream &inFile, std::ofstream &outFile, int numTab = 4) { char ch; int spaceCounter = 0; int sizeToTab = 0; while (inFile.get(ch)) { if (ch == '\n') spaceCounter = -1; if (spaceCounter < 0) { sizeToTab = numTab; } else { sizeToTab = numTab - (spaceCounter % numTab); } if (ch == '\t') { for (int i = 0; i < sizeToTab; i++) { outFile.put(' '); std::cout << ' '; } spaceCounter += sizeToTab; } else { outFile.put(ch); std::cout << ch; spaceCounter++; } } }
void XMLWriter::escape(std::ofstream& iOS, var iVar) { const char* str = iVar.str(); for (int i=0; i<iVar.size(); i++) switch (str[i]) { case '&': iOS << "&"; break; case '<': iOS << "<"; break; case '>': iOS << ">"; break; case '\'': iOS << "'"; break; case '"': iOS << """; break; default: iOS.put(str[i]); break; } }
// flushing strings static void WriteString ( std::ofstream &s, std::string &val) { s << (uint32) val.size() << " "; for( uint32 i=0; i< val.size(); i++) { s.put(val[i]); } s << " "; }
int main(int argc, char* argv[]){ if (argc != 3) { std::cout << argv[0] << " called with incorrect arguments. "<< std::endl; std::cout << "Usage:" << std::endl; std::cout << argv[0] << " infile outfile" << std::endl; exit(-1); } infile.open(argv[1], ios::binary); // Open input file outfile.open(argv[2], ios::binary); // Open output file BitInputStream* input = new BitInputStream(infile); if(infile.is_open()) { // Read the number of unique bytes unsigned int tlength = input -> readInt(); // Read the length of the original text int textbytes = input -> readInt(); // Read the frequencies of each byte from the header unsigned int i = 0; // Start past the two nums, at the actual header while( i < tlength) { int d = input -> readInt(); int s = input -> readByte(); freq[s] = d; i++; } // Build the tree from the frequencies HCTree* myTree = new HCTree(); myTree->build(freq); //Decode individual bytes int y = 0; while (infile.good() && y < textbytes) { int decoded = myTree -> decode(*input); outfile.put((unsigned char)decoded); y++; } outfile.flush(); } else { std::cout << argv[0] << " called with incorrect arguments. "<< std::endl; std::cout << "Usage:" << std::endl; std::cout << argv[0] << " infile outfile" << std::endl; exit(-1); } infile.close(); outfile.close(); }
// TODO: it is not necessary to break a raw chunk for two equal pixels (for the matter of the resulting size) bool TGAImage::unload_rle_data(std::ofstream& out) { const unsigned char max_chunk_length = 128; unsigned long npixels = width * height; unsigned long curpix = 0; while(curpix < npixels) { unsigned long chunkstart = curpix * bytespp; unsigned long curbyte = curpix * bytespp; unsigned char run_length = 1; bool raw = true; while(curpix + run_length < npixels && run_length < max_chunk_length) { bool succ_eq = true; for(int t = 0; succ_eq && t < bytespp; t++) { succ_eq = (data[curbyte + t] == data[curbyte + t + bytespp]); } curbyte += bytespp; if(1 == run_length) { raw = !succ_eq; } if(raw && succ_eq) { run_length--; break; } if(!raw && !succ_eq) { break; } run_length++; } curpix += run_length; out.put(raw ? run_length - 1 : run_length + 127); if(!out.good()) { std::cerr << "can't dump the tga file\n"; return false; } out.write((char*)(data + chunkstart), (raw ? run_length* bytespp : bytespp)); if(!out.good()) { std::cerr << "can't dump the tga file\n"; return false; } } return true; }
void CipherEncrypt::doFilter(std::ifstream &in, std::ofstream &out) { char ch; in.get(ch); wordCount = 0; lineCount = 0; while(in.good()) { if (ch == ' ') // ignore spaces and white space please. in.get(ch); else { wordCount++; if(wordCount % 6 == 0) { out.put(' '); } else { if(ch == 10) // let's get a new line and start over. { wordCount = 0; } ch = transform(ch); out.put(ch); in.get(ch); } } } }
void write_packed(unsigned char *data, int size, std::ofstream &f) { unsigned char c = 0; int bitshift = 7; for (int pos = 0; pos < size; pos++) { c = c | (data[pos] << bitshift); bitshift--; if ((bitshift == -1) || (pos == size-1)) { f.put(c); bitshift = 7; c = 0; } } }
void banishCharacters(std::ifstream &inFile, std::ofstream &outFile, std::string toBanish) { char ch; while (inFile.get(ch)) { bool toPut = true; for (int i = 0; i < toBanish.length(); i++) { if (toBanish.at(i) == ch) { toPut = false; } } if (toPut) { std::cout.put(ch); outFile.put(ch); } } }
void Entity::saveByte(std::ofstream& file, char c) { file.put(c); }
void write_padding(std::ofstream& out, int len) { for (int z = 0; z < len; ++z) out.put(pad_char); }
void writeToLog(std::ofstream& file, std::string str) { file.write(str.c_str(), str.length()); file.put(' '); }
bool write(const uint8_t v) { m_fp.put(v); return true; }