bool XTextureFileName::ParseFromFStream(std::ifstream& in) { std::streampos pos; char separator; if (!in.good()) { return false; } in.clear(); pos = in.tellg(); if (!FileName.ParseFromFStream(in)) { in.clear(); in.seekg(pos); return false; } in >> separator; if (!in.good() || separator != ';') { in.clear(); in.seekg(pos); return false; } return true; }
char* solveMoreOfTheProblem() { try { if (! inFile.eof()) { string t = getaline(inFile); if (t.size() == 0) { inFile.clear(); inFile.close(); return error[4]; } else { sprintf(lzbfr, "%s", t.c_str()); } return lzbfr; } else { inFile.clear(); inFile.close(); return error[4]; } } catch (string message) { inFile.clear(); inFile.close(); throw message; } catch (...) { inFile.clear(); inFile.close(); throw string("More went bad!!"); } return error[3]; }
static int readRecord(std::ifstream& stream, string& id, string& counts) { std::string line; if (std::getline(stream, line)) { if ('>' == line[0]) { id.assign(line.begin() + 1, line.end()); //std::string sequence; /*while (stream.good() && '>' != stream.peek()) { std::getline(stream, line); sequence += line; }*/ // We assume the counts are on a single line std::getline(stream, line); counts = line; stream.clear(); return 0; } else { stream.clear(std::ios_base::failbit); } } return -1; }
ossim_uint32 ossimRpfToc::getNumberOfFrames(std::ifstream& dotRpfStr) const { ossim_uint32 result = 0; if ( !dotRpfStr.good() ) { // see if we can clear it. Someone might have hit end of file(eof). dotRpfStr.clear(); } dotRpfStr.seekg(0, ios_base::beg); // Eat the first line which is the bounding rect. std::string line; std::getline(dotRpfStr, line); while( dotRpfStr.good() ) { std::getline(dotRpfStr, line); if ( dotRpfStr.good() ) { ++result; } } dotRpfStr.clear(); dotRpfStr.seekg(0, ios_base::beg); return result; }
ossimFilename ossimRpfToc::getSourceTocFile(std::ifstream& dotRpfStr) const { ossimFilename tocFile; if ( !dotRpfStr.good() ) { dotRpfStr.clear(); } dotRpfStr.seekg(0, ios_base::beg); // Eat the first line which is the bounding rect. std::string line; std::getline(dotRpfStr, line); // Get the second line which is first file. std::getline(dotRpfStr, line); // Get the file name and make the sub directory if needed. ossimFilename file; if ( getFile(line, file) ) { ossimFilename subDir = file.path(); tocFile = subDir.dirCat("a.toc"); if ( !tocFile.exists() ) { tocFile = subDir.dirCat("A.TOC"); if ( !tocFile.exists() ) { subDir = subDir.path(); tocFile = subDir.dirCat("a.toc"); if ( !tocFile.exists() ) { tocFile = subDir.dirCat("A.TOC"); if ( !tocFile.exists() ) { tocFile.clear(); } } } } } if ( !dotRpfStr.good() ) { dotRpfStr.clear(); } dotRpfStr.seekg(0, ios_base::beg); if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimRpfToc::getSourceTocFile result: " << tocFile << "\n"; } return tocFile; }
bool NxsFilePath::OpenInput(std::ifstream &inFStream) const { inFStream.close(); inFStream.clear(); inFStream.open(GetNative().c_str()); if (inFStream.good()) return true; inFStream.close(); inFStream.clear(); return false; }
inline void lf_file::rewind() { if (post_header_pos>0) { f.clear(); f.seekg(post_header_pos); } }
/****************************************************************************************************** void strip_file(std::ifstream& inStream, std::string fileName) Description: Opens a input file and strips symbols and outputs to temp file. Parameters: std::ifstream& inStream, std::string fileName Pre-Conditions: Input file must be opened. Post-Conditions: Input file will be stripped of symnbols and output to temp file. ******************************************************************************************************/ void strip_file(std::ifstream& inStream, std::fstream& tempStream) { std::vector<char> lines;//create a vector to hold characters. while (inStream)//iterate through each line in file. { char ch; int count = 0; ch = inStream.get();//Get character from line. while (ch != EOF)//While not end of line. { if (ch != ',' && ch != '[' && ch != ']')//Do not add these symbols. { lines.push_back(ch);//Push character to vector. count++;//inc count, used to loop through vector. } ch = inStream.get();//get next char in line. } for (int i = 0; i < count; i++) { //std::cout << lines[i]; //Outputs each line in file to console. tempStream << lines[i];//Outputs to temp.txt file } lines.clear();//Clears the vector of all values. } inStream.clear();//clears the end of file flag (eof). inStream.seekg(0L, std::ios::beg);//Move back to the beginning of the input file stream. tempStream.clear();//clears the end of file flag (eof). tempStream.seekg(0L, std::ios::beg);//Move back to the beginning of the input file stream. }//end strip_file
void AnimatedObjModel::loadFile(std::ifstream& _dataStream) { DataCounts counts = readFileCounts(_dataStream); _dataStream.clear(std::ios::goodbit); _dataStream.seekg(0, std::ios::beg); loadDataStructures(_dataStream, counts); }
void open( const std::string& anchorFile ) { _in.close(); _in.clear(); _in.open( anchorFile.c_str() ); _buffer.clear(); _readDocumentHeader(); }
IndexEntry readEntry(std::ifstream & indexistr, uint64_t const entryid) const { uint64_t const entrybitpos = getEntryBitPos(entryid); uint64_t const entrybytepos = entrybitpos>>3; uint64_t const entrybitoff = entrybitpos - (entrybytepos<<3); // seek to index position indexistr.clear(); indexistr.seekg(entrybytepos,std::ios::beg); if ( static_cast<int64_t>(indexistr.tellg()) != static_cast<int64_t>(entrybytepos) ) { ::libmaus2::exception::LibMausException se; se.getStream() << "Failed to seek to index position " << entrybytepos << " in file " << filename << " of size " << ::libmaus2::util::GetFileSize::getFileSize(filename) << std::endl; se.finish(); throw se; } ::libmaus2::bitio::StreamBitInputStream SBIS(indexistr); SBIS.read(entrybitoff); uint64_t const pos = SBIS.read(posbits); uint64_t const kcnt = SBIS.read(kbits); uint64_t const vcnt = SBIS.read(vbits); return IndexEntry(pos,kcnt,vcnt); }
std::vector <points> read (std::ifstream &f,int a,int b,int c,int d){ std::vector <points> v; f.clear(); f.seekg(0, std::ios::beg); while (f.good()){ std::string s; f>>s; std::stringstream ss; ss<<s; int temp_x,temp_y; ss>>temp_x; s.clear();ss.clear(); f>>s; ss<<s; ss>>temp_y; points temp(temp_x,temp_y,a,b,c,d); v.push_back(temp); } return v; }
/**\brief Used by testers. * * Not operators because that would conflict * with the std:: operators for unsigned ints, alas. */ void in(std::ifstream& i, unsigned48_t& res) { /* * print "0x........,0x........,0x........" */ union { unsigned48_t seed; unsigned short dummy[sizeof(unsigned48_t)/sizeof(unsigned short)]; } PUN ; char comma = ','; unsigned j=0; while( (comma == ',') && (j < sizeof(PUN.dummy)/sizeof(unsigned short)) && (i >> PUN.dummy[j]) ) { if(i.peek() == ',') i >> comma; j++; } if(j < sizeof(PUN.dummy)/sizeof(unsigned short) ) { // This actually sets the badbit: i.clear(std::ios::badbit|i.rdstate()); } res = PUN.seed; }
void GlowNodeGroup::open(std::ifstream& fp) { int type = 0; int end_found = 0; char dummy[40]; for (;;) { if (!fp.good()) { fp.clear(); fp.getline(dummy, sizeof(dummy)); printf("** Read error GlowNodeGroup: \"%d %s\"\n", type, dummy); } fp >> type; switch (type) { case glow_eSave_NodeGroup: break; case glow_eSave_NodeGroup_nodeclass_part: GlowNodeClass::open(fp); break; case glow_eSave_End: end_found = 1; break; default: std::cout << "GrowGroup:open syntax error\n"; fp.getline(dummy, sizeof(dummy)); } if (end_found) break; } }
void CSourceFilesProcessor::Error( const CError& error ) { std::cerr << error.UserMessage() << std::endl; if( error.Severity() == ES_FatalError ) { file.clear( std::ios_base::eofbit ); std::cin.clear( std::ios_base::eofbit ); } }
std::string GetLastLine(std::ifstream& in) { std::ifstream::pos_type pos = in.tellg(); std::ifstream::pos_type lastPos; while (in >> std::ws && Ignoreline(in, lastPos)) pos = lastPos; in.clear(); in.seekg(pos); std::string line; std::getline(in, line); in.clear(); in.seekg(std::ios::beg); return line; }
Gslib_input_pointset_dialog::Gslib_input_pointset_dialog( std::ifstream& infile, QWidget* parent , const char* name ) : QWidget( parent) { setupUi(this); std::streampos mark = infile.tellg(); // read how many properties are defined in the file (indicated at the // second line of the file) std::string line; std::getline( infile, line ); int nb_properties; infile >> nb_properties; infile.clear(); infile.seekg( mark ); X_col_->setMaximum( nb_properties ); Y_col_->setMaximum( nb_properties ); Z_col_->setMaximum( nb_properties ); // make a preview of the file QString text; int count = 0; const int limit = 50; // Read up to "limit" lines while( std::getline( infile, line ) && count < limit ) { line += "\n"; text.append( line.c_str() ); count ++; } text_preview_->setPlainText( text ); // set the stream back to where it was infile.clear(); infile.seekg( mark ); name_->setFocus(); }
/** Opens the filestream with the first file called @p filename found by looking successively in the following directories: - the current directory - in a subdirectory (of the directory below) with the version of OpenBabel as its name - the parent directory specified by the environment variable named @p envvar or "BABEL_DATADIR" if @p envvar is not specified, or the compiled-in macro BABEL_DATADIR if the environment variable is not set \param ifs Stream to load \param filename Name of the data file to load \param envvar Name of the environment variable \return the name of the file that was opened. This includes the path unless it is in current directory **/ std::string OpenDatafile(std::ifstream& ifs, const std::string& filename, const std::string& envvar) { ios_base::openmode imode = ios_base::in; #ifdef ALL_READS_BINARY //Makes unix files compatible with VC++6 imode = ios_base::in|ios_base::binary; #endif // check the current directory ifs.close(); ifs.clear(); ifs.open(filename.c_str(),imode); if(ifs) return filename; string file; const char* datadir = getenv(envvar.c_str()); if(!datadir) datadir = BABEL_DATADIR; // check the subdirectory for this version number file = datadir; file += FILE_SEP_CHAR; file += BABEL_VERSION; file += FILE_SEP_CHAR + filename; ifs.clear(); ifs.open(file.c_str(),imode); if(ifs) return file; // couldn't find it with the version built in, so try the parent file = datadir; file += FILE_SEP_CHAR; file += filename; ifs.clear(); ifs.open(file.c_str(),imode); if (ifs) return file; ifs.clear(); ifs.close(); return(""); // error }
void readline(std::string* dst, std::ifstream& stream) { char buf[1024]; do { stream.clear(); stream.getline(buf, 1024); *dst += buf; } while( stream.fail() && !stream.eof() ); }
bool XAnimationKey::ParseFromFStream(std::ifstream& in) { std::streampos pos; char separator; if (!in.good()) { return false; } in.clear(); pos = in.tellg(); if (!KeyType.ParseFromFStream(in)) { in.clear(); in.seekg(pos); return false; } in >> separator; if (!in.good() || separator != ';') { in.clear(); in.seekg(pos); return false; } if (!NKeys.ParseFromFStream(in)) { in.clear(); in.seekg(pos); return false; } in >> separator; if (!in.good() || separator != ';') { in.clear(); in.seekg(pos); return false; } if (!Keys.ParseFromFStream(in, NKeys)) { in.clear(); in.seekg(pos); return false; } in >> separator; if (!in.good() || separator != ';') { in.clear(); in.seekg(pos); return false; } return true; }
// This closes the file which was being parsed, if there is one open. inline void RestrictedXmlParser::CloseFile() { if( xmlFileStream.is_open() ) { xmlFileStream.close(); } xmlFileStream.clear(); xmlStream = &xmlStringStream; }
int insert_signals( T& signal, char * signal_name, char * wu_name, sqlint8_t sah_result_id, std::ifstream& result_file, receiver_config& receiver_cfg, int appid, int max_signals_allowed, list<long>& qpixlist) { int signal_count=0, signal_inserted_count=0, retval=0, qpix; sqlint8_t signal_id=0; result_file.clear(); result_file.seekg(0); while (!result_file.eof()) { result_file >> signal; if (!result_file.eof()) { signal_count++; if (max_signals_allowed == 0 || signal_count <= max_signals_allowed) { if (!(signal.rfi_found = check_values(signal, sah_result_id, wu_name))) { // preprocess only if we have good values retval = pre_process(signal, receiver_cfg); qpixlist.push_back(npix2qpix((long long)signal.q_pix)); } signal.result_id = sah_result_id; if (appid == 2) signal.reserved = 1; // temporary for enhanced rollout signal_id = signal.insert(); if (signal_id) { log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "[%s] Inserted %s %"INT8_FMT" for sah result %"INT8_FMT"\n", wu_name, signal_name, INT8_PRINT_CAST(signal_id), INT8_PRINT_CAST(sah_result_id) ); signal_inserted_count++; } else { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "[%s] Could not insert %s for sah result %"INT8_FMT". SQLCODE is %d. q_pix is %"INT8_FMT" ra is %lf decl is %lf .\n", wu_name, signal_name, sah_result_id, sql_last_error_code(), signal.q_pix, signal.ra, signal.decl ); #if 0 log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "[%s] Could not insert %s for sah result %ld. SQLCODE is %d. SQLMSG is %s q_pix is %"INT8_FMT".\n", wu_name, signal_name, sah_result_id, sql_last_error_code(), sql_error_message(), signal.q_pix ); #endif return -1; } } } } log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL, "[%s] Inserted %d out of %d %s(s) for sah result %"INT8_FMT" \n", wu_name, signal_inserted_count, signal_count, signal_name, INT8_PRINT_CAST(sah_result_id) ); }
/* * Opens a text file whose name is entered by the user. If the file * does not exist, the user is given additional chances to enter a * valid file. The prompt string is used to tell the user what kind * of file is required. */ void askUserForInputFile(std::string prompt, std::ifstream & infile) { while (true) { cout << prompt; string filename = getLine(); infile.open(filename.c_str()); if (!infile.fail()) break; cout << "Unable to open " << filename << endl; infile.clear(); } }
Csv_input_pointset_dialog::Csv_input_pointset_dialog( std::ifstream& infile, QWidget* parent , const char* name ) : QWidget( parent) { setupUi(this); std::streampos mark = infile.tellg(); std::string str; std::getline(infile, str); QString qstr(str.c_str()); // QTextStream inFileStream(infile,QIODevice::ReadWrite); // QString str; // inFileStream >> str; // inFileStream.readLine(); QStringList property_names = qstr.split(","); X_col_name_->addItems(property_names); X_col_name_->addItem("None"); Y_col_name_->addItems(property_names); Y_col_name_->addItem("None"); Z_col_name_->addItems(property_names); Z_col_name_->addItem("None"); //Set default selection X_col_name_->setCurrentIndex(0); Y_col_name_->setCurrentIndex(std::min(1,property_names.size())); Z_col_name_->setCurrentIndex(std::min(2,property_names.size())); // make a preview of the file QString text; std::string line; int count = 0; const int limit = 50; // Read up to "limit" lines while( std::getline( infile, line ) && count < limit ) { line += "\n"; text.append( line.c_str() ); count ++; } text_preview_->setPlainText( text ); // set the stream back to where it was infile.clear(); infile.seekg( mark ); name_->setFocus(); }
inline void AsciiXmlParser::closeFile() // this closes fileToParse, if it was open. { if( fileParsingStream.is_open() ) { fileParsingStream.close(); } fileParsingStream.clear(); textStream = &stringParsingStream; }
void Inventory::scanInventory() { string s; input_kitchen_inventory.clear(); // clear fail and eof bits input_kitchen_inventory.seekg(0, std::ios::beg); while (getline(input_kitchen_inventory, s)) { config[s.substr(0, s.find(':'))] = stoi(s.substr(s.find(':') + 1)); // counter++; } }
std::string promptUserForFile(std::ifstream &inFile, std::string prompt) { while (true) { std::cout << prompt; std::string fileName; getline(std::cin, fileName); inFile.open(fileName.c_str()); if (!inFile.fail()) return fileName; inFile.clear(); std::cout << "Unable to open that file. Try again." << std::endl; if (prompt == "") prompt = "Input file: "; } }
std::string GetLineWithSize(std::size_t const size, std::ifstream& stream) { std::unique_ptr<char[]> buffer(new char[size]); if (!stream.getline(&buffer[0], size).eof() && stream.fail()) { stream.clear(); std::string string_buffer(buffer.get()); string_buffer += GetLineWithSize(2 * size, stream); return std::move(string_buffer); } else { std::string string_buffer(buffer.get()); return std::move(string_buffer); } }
// read a line in headerLine and discards the any remaining characters static void readLine(char *headerLine, std::ifstream& infile){ infile.getline( headerLine, kMaxNameLength ); // still some characters left on the current line ? if ( !infile.eof() && !infile.bad() && infile.rdstate() & std::ios::failbit){ // clear failbit infile.clear(infile.rdstate() & ~std::ios::failbit); // discard characters. char c; while( infile.get(c) && c != '\n'); } }
bool ossimRpfToc::getCorespondingEntry( ossimRpfFrameFileIndexSubsection* frameFileSubSection, std::ifstream& dotRpfStr, ossim_uint32& entry) const { bool result = false; if ( !dotRpfStr.good() ) { // see if we can clear it. Someone might have hit end of file(eof). dotRpfStr.clear(); } dotRpfStr.seekg(0, ios_base::beg); std::string line; ossimFilename file; ossimRpfFrameFileIndexRecord record; // Eat the first line which is the bounding rect line std::getline(dotRpfStr, line); std::getline(dotRpfStr, line); if ( getFile(line, file) ) { if ( frameFileSubSection->getFrameFileIndexRecordFromFile(file.file(), record) ) { entry = record.getBoundaryRecNumber(); result = true; } } if ( !dotRpfStr.good() ) { dotRpfStr.clear(); } dotRpfStr.seekg(0, ios_base::beg); return result; }