// This utilitu function returns the bytes remaining until the end of the file // is reached. It should be probably made publicly availale in a separate util // section of the library (e.g. util/io.h) size_t bytesRemainingToTheEnd(ifstream& ifs) { std::streampos tmp = ifs.tellg(); ifs.seekg(0, ifs.end); size_t totalLength = ifs.tellg(); ifs.seekg(tmp); return (totalLength - ifs.tellg()); }
/* ********************************************************************************************* */ void processCentersWFN(ifstream &ifil,const int nnu,string* &atlbl,solreal* &rr,solreal* &atch) { alloc1DStringArray("atlbl",nnu,atlbl); alloc1DRealArray("rr",3*nnu,rr); alloc1DRealArray("atch",nnu,atch); string line; int fipos,fepos; size_t pos; //bool isspace=true; for (int i=0; i<nnu; i++) { fipos=ifil.tellg(); getline(ifil,line); fepos=ifil.tellg(); atlbl[i]=line.substr(0,12); while (atlbl[i][0]==' ') {atlbl[i].erase(0,1);} while (atlbl[i][atlbl[i].length()-1]==' ') { atlbl[i].erase(atlbl[i].length()-1); } pos=atlbl[i].find_first_of(' '); while (pos!=string::npos) { atlbl[i].erase(pos,1); pos=atlbl[i].find_first_of(' '); } line.erase(0,23); //sscanf(line.c_str(),"%g %g %g",&rr[3*i],&rr[3*i+1],&rr[3*i+2]); ifil.seekg(fipos+23); ifil >> rr[3*i] >> rr[3*i+1] >> rr[3*i+2]; //cout << atlbl[i] << endl; //cout << "R[" << i << "]: " << rr[3*i] << " " << rr[3*i+1] << " " << rr[3*i+2] << endl; ifil.seekg(fipos+70); ifil >> atch[i]; //cout << "Charge[" << i << "]: " << atch[i] << endl; ifil.seekg(fepos); } }
// Method to read an entry from a binary file // @param string filename - the name of the file which stores binary log entries // @param streampos entry_position - the position of the log entry to be read // @return BinaryLogEntry - the BinaryLogEntry struct containing all pertinent data // // Our binary log entry size is always the same. Some error checking // should be performed to ensure bytes received are expected and // and in correct order // TODO current operation is dangerous and unreliable. A single missing byte will break all future log entry reading - use a delimination phrase between log entries, and scan accordingly BinaryLogEntry read_bin_entry(string filename, streampos entry_position) { Shakespeare::BinaryLogEntry log_entry; static ifstream inputBinary; inputBinary.open(filename.c_str(),ios_base::binary); streampos abs_position = entry_position*sizeof(log_entry); // store EOF conditions inputBinary.seekg(0,ios::end); size_t file_size; file_size = inputBinary.tellg(); #ifdef CS1_DEBUG printf ("End: filesize:%d,entries:%ld\n", file_size, file_size / sizeof(log_entry) ); #endif // seek back to beginning of file inputBinary.seekg(0,ios::beg); if (entry_position > 0) {// seek as required inputBinary.seekg(abs_position); } // take a reading if boundary conditions are met int cur_pos = inputBinary.tellg(); if ( (unsigned)(file_size - cur_pos) >= sizeof(log_entry) ) { if (inputBinary) { // read and return log entry inputBinary.read( (char*)&log_entry, sizeof(log_entry) ); } } // close and return inputBinary.close(); return log_entry; }
size_t CommonTools::GetFileSize(ifstream &fin) { streampos loc = fin.tellg(); fin.seekg(0, fin.end); size_t size = fin.tellg(); fin.seekg(loc); return size; }
size_t CommonFunction::FileLength(ifstream &file) { streampos current_pos = file.tellg(); file.seekg(0, ios::end); size_t len = file.tellg(); file.seekg(current_pos); return len; }
/** * Returns the size of the given file. */ int get_file_size(ifstream &ifs) { long begin, end; begin = ifs.tellg(); ifs.seekg(0, ios::end); end = ifs.tellg(); ifs.seekg(ios::beg); return end - begin; }
ifstream::pos_type get_length(ifstream &file) /* Note that this function requires a binary file. */ { auto current_position = file.tellg(); file.seekg(0, file.end); auto file_length = file.tellg(); file.seekg(current_position); return file_length; }
long GetFileLength(ifstream &ifs) { long tmppos; long respos; tmppos = ifs.tellg(); ifs.seekg(0, ios::end); respos = ifs.tellg(); ifs.seekg(tmppos, ios::beg); return respos; }
unsigned long getFileLength(ifstream& file) { if(!file.good()) return 0; unsigned long pos=file.tellg(); file.seekg(0,ios::end); unsigned long len = file.tellg(); file.seekg(ios::beg); return len; }
int size_of_stream(ifstream& f){ /* Save the current position. */ long save_pos = f.tellg( ); /* Jump to the end of the file. */ f.seekg(0, ios::end ); /* Get the end position. */ long size_of_file = f.tellg( ); /* Jump back to the original position. */ f.seekg( save_pos, ios::beg ); return( size_of_file ); };
unsigned long CShaderMngr::_getFileLength(ifstream &inFile) const { if(!inFile.good()) return 0; streamoff pos = inFile.tellg(); inFile.seekg(0,ios::end); streamoff len = inFile.tellg(); inFile.seekg(pos); return static_cast<unsigned long>(len); }
long filesize(ifstream& f) { long current = f.tellg(); f.seekg(0, ios::beg); long beg = f.tellg(); f.seekg(0, ios::end); long end = f.tellg(); f.seekg(current, ios::beg); return end-beg; }
unsigned long long fileLength(ifstream & file_stream) { unsigned long long old_position = (unsigned long long) file_stream.tellg(); file_stream.seekg(0, ios::end); unsigned long long length = (unsigned long long) file_stream.tellg(); file_stream.seekg(old_position); return length; }
JSize JGetFStreamLength ( ifstream& theStream ) { const long savedMark = theStream.tellg(); theStream.seekg(0, ios::end); const JSize fileLength = theStream.tellg(); theStream.seekg(savedMark, ios::beg); return fileLength; }
size_t dami::getFileSize(ifstream& file) { size_t size = 0; if (file.is_open()) { streamoff curpos = file.tellg(); file.seekg(0, ios::end); size = file.tellg(); file.seekg(curpos); } return size; }
int build_index(ifstream &data, ostream &output) { map<string, int> index; unsigned numoflinks; streampos pos = data.tellg(); CPageLink link; while (data>>link) { if (index.find(link.url) == index.end()) { //index[link.url] = pos; index.insert(pair<string, int>(link.url, pos)); //try_insert(index, link.url, pos); } else { ostringstream oss; oss<<"Duplicated url:"<<link.url; throw runtime_error(oss.str()); } pos = data.tellg(); } data.clear(); data.seekg(0, ios::beg); while (data>>link) { for (unsigned i=0; i<link.outlinks.size(); i++) { string target = link.outlinks[i]; if (index.find(target)==index.end()) { #ifdef _DEBUG_09192008 cerr<<'['<<target<<']'<<endl; #endif // _DEBUG_09192008 //index[target]=-1; index.insert(pair<string, int>(target, -1)); //try_insert(index, target, -1); } } } for (map<string, int>::const_iterator cit = index.begin() ; cit != index.end(); cit ++) { output<<cit->first<<'\t'<<cit->second<<endl; } return index.size(); }
/* Ta funkcija prebere binarno datoteko. */ void binarnoBranje() { //odpiranje datoteke inputFile.open(filename.c_str(), ios::binary|ios::in); //ugotavljanje velikosti datoteke: inputFile.seekg(0,inputFile.end); long long fileSize = inputFile.tellg(); //pointer nazaj na zacetek datoteke inputFile.seekg(0,inputFile.beg); //preracunanje koliko je koncnih bytov, za katere bo treba prilagoditi char array in stevilo iteracij long long endBytes = fileSize % writingSize, pos = 0, iterations = fileSize/writingSize; //branje while (iterations--) { inputFile.read(c, writingSize); pos+=writingSize; inputFile.seekg(pos, ios::beg); } //koncni byti delete[] c; c = new char[endBytes]; inputFile.read(c, endBytes); //velikost c nastavimo nazaj na zacetek delete[] c; c = new char[writingSize]; }
int parse_nodes_to_coords_vector(ifstream& reader, double*** nodes) { string buf; getline(reader, buf); if (string(buf).compare("nodes") != 0) { cerr << "not at nodes section of file" << endl; return -1; } streampos start = reader.tellg(); int len = 0; for(;buf[0] != '\0';len++) { getline(reader,buf); } len--; reader.seekg(start); *nodes = new double*[len]; (*nodes)[0] = new double[len * 2]; for (int i = 1; i < len; i++) (*nodes)[i] = (*nodes)[i-1] + 2; getline(reader, buf); for(int i = 0 ; buf[0] != '\0'; i++) { string coord; istringstream s(buf); getline(s,coord,','); double x = strtod(coord.c_str(),NULL); getline(s,coord); double y = strtod(coord.c_str(),NULL); (*nodes)[i][0] = x; (*nodes)[i][1] = y; getline(reader, buf); } cout << "Processed nodes" << endl; return len; }
int main(int argc, char* argv[]) { if(argc < 2) { cerr << "Not enough arguments!" << endl; return -1; } else if (argc > 2) { cerr << "Too many arguments!" << endl; return -1; } try { fin.open(argv[1], ios::binary); if(fin == NULL) throw ios::failure(" can't open image file"); int prev = 0, tmp; char* buf = new char[1]; while(!fin.eof()) { fin.read(buf, 1); tmp = buf[0]; if(tmp == char(0xAA) && prev == char(0x55)) WriteCandidate(fin.tellg()); prev = tmp; } } catch(ios::failure& exc) { cerr << exc.what() << endl; return -1; } catch(exception& exc) { cerr << "Error: " << exc.what() << endl; return -1; } return 0; }
void FileCalc() { unsigned int filesize_long,loop; char fchar[0x4000F]; game.seekg(0,ios::end); filesize_long=game.tellg(); //Get file length game.seekg(0,ios::beg); game.read(fchar,filesize_long); filesize_32=(filesize_long + 0x0F) & 0xFFFFFFF0; //File size realignment to xxxxx0h if (filesize_32<0x01C0) //Adjust if too small filesize_32 = 0x01C0; if (filesize_32>0x40000) //Quit if too big { printf ("File to be transfered is too big....\n\n"); QuitProgram(); } for (loop=0; loop<filesize_32; loop++) { if (loop<filesize_long) program[loop]=fchar[loop]; else program[loop]=0; } game.close(); filesize_long=((filesize_32-0xC0)>>2)-0x34; //transfer length in 32 bits encoded (for length transfer protocol) filesize_32=(filesize_32-0xC0)/4; //transfer length in 32 bits, after realignment (see SendMainData Function) filesize[0]=(filesize_long>>8)&(0x000000FF); //put upper byte into universal variable filesize[0] filesize[1]=(filesize_long)&(0x000000FF); //put lower byte into universal variable filesize[1] }
double read_point(vector<string> * features, vector<double> * weights) { if (data.tellg() == length) { data.seekg(0, data.beg); } string buffer; std::getline(data, buffer); return parse_string(features, weights, buffer); }
string read_file(ifstream & file){ file.seekg(0, std::ios::end); size_t size = file.tellg(); std::string buffer(size, ' '); file.seekg(0); file.read(&buffer[0], size); return buffer; }
streamsize getFileSize( ifstream& fp ) { streamsize fileSize = 0; fp.seekg(0, ifstream::end); fileSize = fp.tellg(); fp.seekg(0); return fileSize; }
long ServerProcess::GetFileLength(ifstream& filestream) { long length = 0; filestream.seekg (0, ios::end); length = filestream.tellg(); filestream.seekg (0, ios::beg); return length; }
unsigned long CShader::getFileLength(ifstream &file) { if(!file.good()) return 0; file.seekg(0,ios::end); unsigned long length = file.tellg(); file.seekg(0,ios::beg); return length; }
int filesize(string fn) { int a; is.open(fn.c_str(),ios::binary); is.seekg(0,ios::end); a = is.tellg(); is.close(); return a; }
void samFileAnalyzer::readHeader(void) //read header from sam file { int positionInFile; string headerLine; positionInFile = inputFile.tellg(); getline(inputFile,headerLine); while(headerLine.at(0)=='@') { positionInFile = inputFile.tellg(); getline(inputFile,headerLine); } inputFile.seekg(positionInFile, ios::beg); return; }
void performIO(){ input.open(inputFileName, ifstream::binary); ref.open(refFileName, ifstream::binary); if(input.eof() || input.fail()) printf("Arquivo inexistente: %s\n", inputFileName), exit(2); if(ref.eof() || ref.fail()) printf("Arquivo inexistente: %s\n", refFileName), exit(2); input.seekg(0, ios::end); frameTotal = input.tellg(); frameTotal /= frameSize*1.5; input.seekg(0, ios::beg); ref.seekg(0, ios::end); if(frameTotal != ref.tellg()/(frameSize*1.5)) printf("Arquivos de tamanho diferente!\n"), exit(2); ref.seekg(0, ios::beg); free(inputFileName); free(refFileName); #ifdef DEBUG_INPUT printf("FrameTotal: %d\n", frameTotal); #endif }
void genetic::ReadIntegral_BCS(ifstream& fdump, Matrix& K) { // save file pointer ifstream::pos_type fp = fdump.tellg(); // rewind fdump.seekg(0, ios::beg); char sbuf[256]; fdump.getline(sbuf, 256); string entry(sbuf); vector<string> fields; split(fields, entry, is_any_of("=, \t"), token_compress_on); int nOrbs = 0; for(int i = 0; i < fields.size(); ++i) { if(fields[i] == "NORB") { nOrbs = atoi(fields[i+1].c_str()); break; } } K.ReSize(nOrbs, nOrbs); K = 0.0; while(fdump >> entry) if((entry == "&END") || (entry == "/")) break; int i, j, k, l; double v; while(fdump >> v >> i >> j >> k >> l) { if(i == 0 && j == 0 && k == 0 && l == 0) continue; //* Read by Mulliken Notation if(i == k && j == l) { i--; j--; K.element(i, j) += fabs(v); K.element(j, i) = K.element(i, j); } if(i == l && j == k) { i--; j--; K.element(i, j) += fabs(v); K.element(j, i) = K.element(i, j); } if(k == 0 && l == 0) { i--; j--; K.element(i, j) += 1.0e-7 * fabs(v); K.element(j, i) = K.element(i, j); } } // set file pointer to original position fdump.clear(); fdump.seekg(fp); }
void FileToVector( ifstream& file, vector<T>& vec, const streampos& start = 0, const streampos& end = 0 ) { // First calculate how many bytes to read file.seekg( start ); const streampos first = file.tellg(); file.seekg( -end, ios::end ); const streampos last = file.tellg(); // bufferSize is the total number of bytes to read const size_t bufferSize = last - first; // Calculate the size of vector required to hold the data from the file const size_t vecSize = bufferSize / sizeof( T ); vec.resize( vecSize ); file.seekg( start ); file.read( reinterpret_cast<char*>( &vec[0] ), vec.size() * sizeof( T ) ); }