void ConfigParser::import_stream(std::istream& stream) { while(!stream.eof()) { std::string line; getline(stream, line); ConfigParser::Entry* entry = parse_line(line.c_str()); if(entry) { variables.push_back(std::pair<std::string, Entry*>(entry->variable, entry)); } } }
void ConfigParser::import_stream(std::istream& stream) { while(!stream.eof()) { std::string line; getline(stream, line); ConfigParser::Entry* entry = parse_line(line.c_str()); if(entry) { variables[entry->variable] = entry; } } }
int TestWindow::num_of_questions(std::istream &input) { int count = 0; std::string str; while(!input.eof()){ std::getline(input, str); count++; } return count / 6; }
void consume(std::istream &in, char ch) { while (in.good()) { int c; c = in.peek(); if (in.eof()) return; if (std::isspace(c)) { in.ignore(); continue; } if (c == ch) { in.ignore(); } return; } }
// function to output the rot13 of a file on std::cout // returns false if an error occurred processing the file, true otherwise // on entry, the argument is must be open for reading int rot13_stream(std::istream& is) { std::string line; while (std::getline(is, line)) { if (!(std::cout << rot13(line) << "\n")) return false; } return is.eof(); }
osgDB::ReaderWriter::ReadResult ReaderWriterIV::readNode(std::istream& fin, const osgDB::ReaderWriter::Options* options) const { // Notify OSG_NOTICE << "osgDB::ReaderWriterIV::readNode() " "Reading from stream." << std::endl; OSG_INFO << "osgDB::ReaderWriterIV::readNode() " "Inventor version: " << SoDB::getVersion() << std::endl; // Open the file SoInput input; // Assign istream to SoInput // note: It seems there is no straightforward way to do that. // SoInput accepts only FILE by setFilePointer or memory buffer // by setBuffer. The FILE is dangerous on Windows, since it forces // the plugin and Inventor DLL to use the same runtime library // (otherwise there are app crashes). // The memory buffer seems much better option here, even although // there will not be a real streaming. However, the model data // are usually much smaller than textures, so we should not worry // about it and think how to stream textures instead. // Get the data to the buffer size_t bufSize = 126*1024; // let's make it something below 128KB char *buf = (char*)malloc(bufSize); size_t dataSize = 0; while (!fin.eof() && fin.good()) { fin.read(buf+dataSize, bufSize-dataSize); dataSize += fin.gcount(); if (bufSize == dataSize) { bufSize *= 2; char* new_buf = (char*)realloc(buf, bufSize); if (!new_buf) { free(buf); return osgDB::ReaderWriter::ReadResult::INSUFFICIENT_MEMORY_TO_LOAD; } buf = new_buf; } } input.setBuffer(buf, dataSize); OSG_INFO << "osgDB::ReaderWriterIV::readNode() " "Stream size: " << dataSize << std::endl; // Perform reading from SoInput osgDB::ReaderWriter::ReadResult r; std::string fileName(""); r = readNodeFromSoInput(input, fileName, options); // clean up and return free(buf); return r; }
/*********************************************************************** * Extract contiguous lines of comments **********************************************************************/ static std::vector<CodeBlock> extractContiguousBlocks(std::istream &is) { std::vector<CodeBlock> contiguousCommentBlocks; CodeBlock currentCodeBlock; size_t lineNo = 0; std::string partial, line; bool inMultiLineComment = false; while (is.good() and not is.eof()) { if (not partial.empty()) line = partial; else { lineNo++; //starts at 1 std::getline(is, line); } partial.clear(); if (line.empty()) continue; const std::string lineTrim = Poco::trimLeft(line); const auto openMulti = line.find("/*"); const auto closeMulti = line.find("*/"); if (not inMultiLineComment and lineTrim.size() >= 2 and lineTrim.substr(0, 2) == "//") { currentCodeBlock.push_back(CodeLine(line, lineNo)); } else if (not inMultiLineComment and openMulti != std::string::npos) { inMultiLineComment = true; currentCodeBlock.push_back(CodeLine(line.substr(openMulti, std::string::npos), lineNo)); } else if (inMultiLineComment and closeMulti != std::string::npos) { inMultiLineComment = false; currentCodeBlock.push_back(CodeLine(line.substr(0, closeMulti), lineNo)); partial = line.substr(closeMulti+2); } else if (inMultiLineComment) { currentCodeBlock.push_back(CodeLine(line, lineNo)); } else if (not currentCodeBlock.empty()) { contiguousCommentBlocks.push_back(currentCodeBlock); currentCodeBlock.clear(); } } if (not currentCodeBlock.empty()) { contiguousCommentBlocks.push_back(currentCodeBlock); } return contiguousCommentBlocks; }
//////////////////////////////////////////////////////////////////////////// // MemParser constructor ////////////////////////////////////////////////////////////////////////////// MemParser::MemParser(std::istream& in, UInt32 bytes) { if (bytes == 0) { // ----------------------------------------------------------------------------- // Read all available bytes from the stream // ----------------------------------------------------------------------------- std::string data; const int chunkSize = 0x10000; char* chunkP = new char[chunkSize]; while (!in.eof()) { in.read(chunkP, chunkSize); NTA_CHECK (in.good() || in.eof()) << "MemParser::MemParser() - error reading data from stream"; data.append (chunkP, in.gcount()); } bytes_ = (UInt32)data.size(); bufP_ = new char[bytes_+1]; NTA_CHECK (bufP_ != NULL) << "MemParser::MemParser() - out of memory"; ::memmove ((void*)bufP_, data.data(), bytes_); ((char*)bufP_)[bytes_] = 0; delete[] chunkP; } else { // ----------------------------------------------------------------------------- // Read given # of bytes from the stream // ----------------------------------------------------------------------------- bytes_ = bytes; bufP_ = new char[bytes_+1]; NTA_CHECK (bufP_ != NULL) << "MemParser::MemParser() - out of memory"; in.read ((char*)bufP_, bytes); ((char*)bufP_)[bytes] = 0; NTA_CHECK (in.good()) << "MemParser::MemParser() - error reading data from stream"; } // Setup start and end pointers startP_ = bufP_; endP_ = startP_ + bytes_; }
/* input table from csv file */ bool RamRelation::load(std::istream &is, SymbolTable& symTable, const SymbolMask& mask) { bool error = false; auto arity = getArity(); while (!is.eof()) { std::string line; RamDomain tuple[arity]; getline(is,line); if (is.eof()) break; size_t start = 0, end = 0; for(uint32_t col=0;col<arity;col++) { end = line.find('\t', start); if ((size_t)end == std::string::npos) { end = line.length(); } std::string element; if (start <= end && (size_t)end <= line.length() ) { element = line.substr(start,end-start); if (element == "") { element = "n/a"; } } else { error = true; element = "n/a"; } if (mask.isSymbol(col)) { tuple[col] = symTable.lookup(element.c_str()); } else { tuple[col] = atoi(element.c_str()); } start = end+1; } if (end != line.length()) { error = true; } if (!exists(tuple)) { insert(tuple); } } return error; }
bool Parser::strmErr( std::istream & is ) { if ( is.eof() ) { M_handler.handleEOF(); return false; } return false; }
bool LoadObj::readHeader(std::istream &is){ std::string buf; //read only to the first line starting with "v" while(!is.eof() && is.peek() != 'v'){ getline(is, buf); } if (is.good()) return true; else return false; }
void Player::deSerialize(std::istream &is) { Settings args; for(;;) { if(is.eof()) throw SerializationError ("Player::deSerialize(): PlayerArgsEnd not found"); std::string line; std::getline(is, line); std::string trimmedline = trim(line); if(trimmedline == "PlayerArgsEnd") break; args.parseConfigLine(line); } //args.getS32("version"); std::string name = args.get("name"); updateName(name.c_str()); /*std::string password = ""; if(args.exists("password")) password = args.get("password"); updatePassword(password.c_str());*/ m_pitch = args.getFloat("pitch"); m_yaw = args.getFloat("yaw"); m_position = args.getV3F("position"); try{ craftresult_is_preview = args.getBool("craftresult_is_preview"); }catch(SettingNotFoundException &e){ craftresult_is_preview = true; } try{ hp = args.getS32("hp"); }catch(SettingNotFoundException &e){ hp = 20; } /*try{ std::string sprivs = args.get("privs"); if(sprivs == "all") { privs = PRIV_ALL; } else { std::istringstream ss(sprivs); ss>>privs; } }catch(SettingNotFoundException &e){ privs = PRIV_DEFAULT; }*/ inventory.deSerialize(is); }
void Player::deSerialize(std::istream &is, std::string playername) { Settings args; for(;;) { if(is.eof()) throw SerializationError (("Player::deSerialize(): PlayerArgsEnd of player \"" + playername + "\" not found").c_str()); std::string line; std::getline(is, line); std::string trimmedline = trim(line); if(trimmedline == "PlayerArgsEnd") break; args.parseConfigLine(line); } //args.getS32("version"); // Version field value not used std::string name = args.get("name"); updateName(name.c_str()); setPitch(args.getFloat("pitch")); setYaw(args.getFloat("yaw")); setPosition(args.getV3F("position")); try{ hp = args.getS32("hp"); }catch(SettingNotFoundException &e){ hp = 20; } try{ m_breath = args.getS32("breath"); }catch(SettingNotFoundException &e){ m_breath = 11; } inventory.deSerialize(is); if(inventory.getList("craftpreview") == NULL) { // Convert players without craftpreview inventory.addList("craftpreview", 1); bool craftresult_is_preview = true; if(args.exists("craftresult_is_preview")) craftresult_is_preview = args.getBool("craftresult_is_preview"); if(craftresult_is_preview) { // Clear craftresult inventory.getList("craftresult")->changeItem(0, ItemStack()); } } // Set m_last_* checkModified(); }
static string ReadZStr(std::istream& f) { std::string s; char c; while(!f.eof ()) { f >> c; if (!c) break; s += c; } return s; }
std::string getcontent(std::istream &in) { std::string res; while(!in.eof()) { char c; in.get(c); if(in.gcount() == 1) res+=c; } return res; }
bool LoadObj::readData(std::istream & is){ std::string lineBuf; int c; int i=0; while(!is.eof()){ c = is.peek(); switch (c) { case 'V': case 'v': { std::string startBuf; is >> startBuf; // get the start of the line getline(is, lineBuf); // get the rest of the line if(startBuf == "v") loadData.verts.push_back(Vector3<float>(lineBuf)); } break; case 'F': case 'f': { std::stringstream buf; is.get(*buf.rdbuf(), '\n'); // read a line into buf is.get(); // read the not extracted \n buf << "\n"; // and add it to the string stream std::string tmp; buf >> tmp; // get the first f or F (+ whitespace) // count the number of faces, delimited by whitespace int count = 0; while (buf >> tmp) count++; // reset stream buf.clear(); buf.seekg(0, std::ios::beg); // Determine wheter we have a triangle or a quad if (count == 3) loadData.triangles.push_back(readTri(buf)); else { std::cerr << "Encountered polygon with " << count << " faces. i'm giving up.\n"; return false; } } break; default: // otherwise just skip the row getline(is, lineBuf); break; } i++; } return true; }
S32 LLSDXMLParser::Impl::parse(std::istream& input, LLSD& data) { XML_Status status; static const int BUFFER_SIZE = 1024; void* buffer = NULL; int count = 0; while (input.good() && !input.eof()) { buffer = XML_GetBuffer(mParser, BUFFER_SIZE); /* * If we happened to end our last buffer right at the end of the llsd, but the * stream is still going we will get a null buffer here. Check for mGracefullStop. */ if (!buffer) { break; } count = get_till_eol(input, (char *)buffer, BUFFER_SIZE); if (!count) { break; } status = XML_ParseBuffer(mParser, count, false); if (status == XML_STATUS_ERROR) { break; } } // *FIX.: This code is buggy - if the stream was empty or not // good, there is not buffer to parse, both the call to // XML_ParseBuffer and the buffer manipulations are illegal // futhermore, it isn't clear that the expat buffer semantics are // preserved status = XML_ParseBuffer(mParser, 0, true); if (status == XML_STATUS_ERROR && !mGracefullStop) { if (buffer) { ((char*) buffer)[count ? count - 1 : 0] = '\0'; } llinfos << "LLSDXMLParser::Impl::parse: XML_STATUS_ERROR parsing:" << (char*) buffer << llendl; data = LLSD(); return LLSDParser::PARSE_FAILURE; } clear_eol(input); data = mResult; return mParseCount; }
bool multiple_alignment::load_phylip( std::istream &is ) { size_t nTaxon; size_t seqLen; if( !is.good() ) { throw std::runtime_error( "cannot read phylip file" ); } is >> nTaxon; is >> seqLen; printf( "header: %zd %zd\n", nTaxon, seqLen ); size_t n = 0; while ( !is.eof() ) { std::string name; std::string seq; is >> name; is >> seq; if( is.eof() ) { break; } names.push_back(name); data.push_back( std::vector<uint8_t>(seq.begin(), seq.end())); // printf( "name: %s\n", name.c_str() ); n++; } assert( n == nTaxon ); // printf( "n: %zd\n", n ); return n == nTaxon; }
bool OptionsList::readnexttoken(std::istream& is, std::string& token) { token.clear(); int c = is.get(); // First get rid of all comments and white spaces while (!is.eof() && (isspace(c) || c=='#') ) { if (c=='#') { is.ignore(10000000, '\n'); } c=is.get(); } // Now read the token while (!is.eof() && !isspace(c)) { token += c; c = is.get(); } return (!is.eof()); }
// returns base64, header, encoded tuple<std::string, std::string, bool> pem_extract(std::istream& is) { std::ostringstream cs; std::string line; getline(is, line); while(line.find("-----BEGIN ") == std::string::npos) { if(is.eof()) throw runtime_error("Unexpected End of File - Not a PEM file?"); getline(is, line); } std::string name = line.substr(11, line.size()-11-5); cs << line << '\n'; bool encrypted = false; do { if(is.eof()) throw runtime_error("Unexpected End of File - PEM File corrupted?"); getline(is, line); if (line.find("ENCRYPTED") != std::string::npos) encrypted = true; cs << line << '\n'; } while(line.find("-----END ") == std::string::npos); return tuple<std::string, std::string, bool>(cs.str(), name, encrypted); }
void GamesAsciiParser::getCI(std::istream& is) { is.seekg(pivot_begin); //look for CI coefficients bool notfound=true; ci_size=0; CIcoeff.clear(); CIalpha.clear(); CIbeta.clear(); do { if(is.eof()) { cerr<<"Could not find CI expansion. \n"; abort(); } getwords(currentWords,is); if(currentWords.size() < 5 ) continue; if(currentWords[0] == "ALPHA" && currentWords[2] == "BETA" && currentWords[4] == "COEFFICIENT" ) { getwords(currentWords,is); // -------- notfound=false; getwords(currentWords,is); while(currentWords.size() != 0) { if(currentWords[0] == "....." || currentWords[1] == "DONE") break; ci_size++; CIcoeff.push_back(atof(currentWords[4].c_str())); CIalpha.push_back(currentWords[0]); CIbeta.push_back(currentWords[2]); getwords(currentWords,is); } } } while(notfound); ci_nea=ci_neb=0; for(int i=0; i<CIalpha[0].size(); i++) if(CIalpha[0].at(i) == '1') ci_nea++; for(int i=0; i<CIbeta[0].size(); i++) if(CIbeta[0].at(i) == '1') ci_neb++; if(CIalpha[0].size() != CIbeta[0].size()) { cerr<<"QMCPack can't handle different number of active orbitals in alpha and beta channels right now. Contact developers for help (Miguel).\n"; abort(); } int ds=SpinMultiplicity-1; int neb= (NumberOfEls-ds)/2; int nea= NumberOfEls-NumberOfBeta; ci_nca = nea-ci_nea; ci_ncb = neb-ci_neb; ci_nstates = CIalpha[0].size(); }
static void get_line(std::istream& in,std::string& s) { for(;;) { s.resize(0); if(in.fail() || in.eof()) return; getline(in,s); std::string::size_type p; p=s.find_first_not_of(" \t"); if(p != std::string::npos) s=s.substr(p); if((!s.empty()) && (s[0] != '#')) break; }; return; }
////////////////////////////////////////////////////////// // PRE: If in is a file input stream, then in has already been connected // to a file. // POST: vector<LogEntry> result is filled with LogEntry's from lines of // istream // std::vector<LogEntry> parse(std::istream& in) { std::vector<LogEntry> result; do { String line = getline(in); LogEntry log(line); result.push_back(log); } while (!in.eof()); return result; }
bool ObjIO::ReadHeader(std::istream & is){ std::string buf; // just read to the first line starting with a 'v' while(!is.eof() && is.peek() != 'v'){ getline(is, buf); //std::cerr << "\"" << buf << "\"\n"; } if (is.good()) return true; else return false; }
void pocketcalculator(std::istream &in, std::ostream &out) { std::stringstream result; unsigned scale{3}; while (in) { result = calc(in); if(!in.eof()) { sevenSegment(result, scale, out); } } }
int readLine(std::istream& is, std::stringstream& currentLine) { if (is.eof()) return -1; currentLine.str(""); currentLine.clear(); is.get(*currentLine.rdbuf()); if (is.fail()) // fail is set on empty lines is.clear(); G2O_FSKIP_LINE(is); // read \n not read by get() return static_cast<int>(currentLine.str().size()); }
void JobList::init(std::istream &in, Tape *tape) { PCB t(tape); while(!(in.eof() || in.bad() || in.fail())) { in >> *(t.name) >> t.pid >> t.stime >> t.ntime >> t.memory >> t.tapeNum >> t.super; jlist.push_back(t); } auto i = jlist.end(); i--; jlist.erase(i); }
void ucs4getline(std::istream& is, ucs4string& ustr) { while (!is.eof()) { ucs4_t ch = ucs4_t('\n'); is.read(reinterpret_cast<char *>(&ch), 4); if (ch == ucs4_t('\n')) break; ustr.push_back(ch); } }
// --------------------------------------------------------------------------- // importPartials // --------------------------------------------------------------------------- // Clients should be prepared to catch ImportExceptions. // // THIS WON'T WORK IF CHUNKS ARE IN A DIFFERENT ORDER!!! // Fortunately, they never will be, since only the research // version of Lemur ever wrote these files anyway. // static void importPartials( std::istream & s, PartialList & partials, double bweCutoff ) { try { // the Container chunk must be first, read it: readContainer( s ); // read other chunks: bool foundParams = false, foundTracks = false; while ( ! foundParams || ! foundTracks ) { // read a chunk header, if it isn't the one we want, skip over it. CkHeader h; readChunkHeader( s, h ); if ( h.id == AnalysisParamsID ) { readParamsChunk( s ); foundParams = true; } else if ( h.id == TrackDataID ) { if (! foundParams) // I hope this doesn't happen { Throw( ImportException, "Mia culpa! I am not smart enough to read the Track data before the Analysis Parameters data." ); } // read Partials: for ( long counter = readTracksChunk( s ); counter > 0; --counter ) { getPartial(s, partials, bweCutoff); } foundTracks = true; } else { s.ignore( h.size ); } } } catch ( Exception & ex ) { if ( s.eof() ) { ex.append("Reached end of file before finding both a Tracks chunk and a Parameters chunk."); } ex.append( "Import failed." ); Throw( ImportException, ex.str() ); } }
//std::getline(std::istream,std::string); SpellDict::SpellDict(std::istream & DictSource) { std::string S; while (!DictSource.eof()) { std::getline(DictSource,S); if (S != "") { D.push_back(S); } } }