GeometryLoaderDX11::PlyElementDesc GeometryLoaderDX11::ParsePLYElementHeader(std::string headerLine, std::ifstream& input) { GeometryLoaderDX11::PlyElementDesc desc; std::string txt; // Parse the header line // "element <name> <count>" int split = headerLine.find_first_of(' ', 8); desc.name = headerLine.substr(8, split - 8); split = headerLine.rfind( ' ' ); std::istringstream elemCount(headerLine.substr(split, headerLine.length() - split)); elemCount >> desc.elementCount; // Parse any attached properties while(input.is_open() && !input.eof()) { std::getline( input, txt ); if(0 == txt.compare(0, 13, "property list")) { // Parse this property list declaration desc.dataFormat.push_back(ParsePLYElementPropertyList(txt.substr(14, txt.length() - 14))); } else if(0 == txt.compare(0, 8, "property")) { // Parse this property declaration desc.dataFormat.push_back(ParsePLYElementProperty(txt.substr(9, txt.length() - 9))); } else { // At this point we'll also have read a line too far so // need to "unread" it to avoid breaking remaining parsing. input.putback('\n'); for(int i = -1 + txt.length(); i >= 0; i--) input.putback(txt.at(i)); // (there must be a better way, no?!?) break; } } return desc; }
// reads until first non-whitespace character void MD5Model::skipWhitespace(std::ifstream &fin) { char c = '\0'; while (!fin.eof()) { fin.get(c); if (!IS_WHITESPACE(c)) { fin.putback(c); break; } } }
static void readIntList(std::vector<unsigned>& ints, std::ifstream& i) { std::string tok; while (i.good()) { i >> tok; if (isInt(tok)) { ints.push_back(atoi(tok.c_str())); } else { for (unsigned j=tok.size(); j>0; --j) i.putback(tok[j-1]); break; } } }
void MD5Model::skipComments(std::ifstream &fin) { char c; fin.get(c); if (c != '/') throw Exception("MD5Model::skipComments(): invalid comment, expected //"); while (!fin.eof() && c != '\n') fin.get(c); // put back last character read fin.putback(c); }
void MovingMeshFB::readDummy(std::ifstream& is) { char c; for (is.get(c);true;is.get(c)) { if (c == '#') { while (true) { is.get(c); if (c == '#') break; } } else if (('0' <= c && c <= '9')||(c == '.')||(c =='-')) break; } is.putback(c); }
uint32_t read_next_number( std::ifstream & is ) { uint32_t value = 0; // Skip whitespace char c; while( ( is.get(c) ) && (c == ' ' || c == '\t' || c=='\n' || c == '\r' ) ); while( c >= '0' && c <= '9' ) { value *= 10; value += ( c - '0' ); is.get(c); } is.putback(c); return value; }
void pnm_read(std::ifstream &file, char *buf) { char doc[PNM_BUFFER_SIZE]; char c; file >> c; while (c == '#') { file.getline(doc, PNM_BUFFER_SIZE); file >> c; } file.putback(c); file.width(PNM_BUFFER_SIZE); file >> buf; file.ignore(); }
inline void FileParse::passWhiteSpaces(std::ifstream& fin) { // Check for eof if (fin.eof()) return; char c; // Get first character fin.get(c); // Loop while (!fin.eof()) { if (c==' ' || c=='\n' || c=='\r'); else { // Encountered a non-whitespace fin.putback(c); return; } // Get next character fin.get(c); } }
inline bool FileParse::passSpaces(std::ifstream& fin) { char c; // Get first character fin.get(c); // Loop while (!fin.eof()) { if (c==' '); else if (c=='\n' || c=='\r') return true; else { // Encountered a non-whitespace fin.putback(c); return false; } // Get next character fin.get(c); } // Return success return true; }
inline void FileParse::getBody(std::ifstream& fin) { // Look for heads char c; bool end = false; while (!fin.eof() && !end) { passWhiteSpaces(fin); if (!fin.eof()) fin.get(c); else return; if (c=='}') // End of a body return; else if (c=='/') { // Could be the start of a comment checkComment(fin); } else { fin.putback(c); getHead(fin); } } }
inline void FileParse::passComment(std::ifstream& fin, bool mline) { string comment; // Start right after "//" or "/*" char c; fin.get(c); while (!fin.eof()) { if (mline && c=='*') { fin.get(c); if (fin.eof()) { // Message message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n"); message += "--> EOF\n"; // End of file encountered return; // Check end of file } if (c=='/') { // Message message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n"); // End of the comment return; } else message += ('*' + c); } else if (c=='\n' || c=='\r') {// Single line comments end with at newline if (mline) comment += "[\\n]"; else { // Message message += (tabs() + (mline ? "ML" : "SL") + " <" + comment +">\n"); // In case a newline signifies something for whoever called this function fin.putback(c); return; } } else { if (c=='\t') comment += "[\\t]"; else comment.push_back(c); } // Get next character fin.get(c); } }
void CFileSystemLongArray::ReadLongArray2D( std::ifstream &stream, unsigned int nx, unsigned int ny, long *pdata ) { std::string buffer; while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, buffer ); // str if ( g_verbose > 1) { std::cout << "Read token <" << buffer << ">\n"; } switch( token_match( buffer, token_list, token_num ) ) { case TOKEN_YSLICE: if ( g_verbose > 1 ) { std::cout << "Reading Y-slice\n"; } ReadLongArray1D( stream, nx, pdata ); pdata += nx; break; default: std::cout << "ReadLongArray2D::Unknown token <"; std::cout << buffer.c_str() << " >\n"; break; } ReadClosePar( stream ); // } } stream.putback( '}' ); }
int CExtensionHeaderFileSettingsIODataAsciiIO::ReadFile( std::ifstream &stream ) { int result; std::string tokenid; int entry_savedstates; result = true; if ( g_verbose ) { std::cout << "Reading CExtensionHeaderFileSettingsIODataAsciiIO" << std::endl; } while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, tokenid ); if ( g_verbose > 1 ) { std::cout << "Read Token = <" << tokenid << ">\n"; } switch( token_match( tokenid, token_list, token_num ) ) { case TOKEN_SYSTEMLIST: m_systemlist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <systemlist>\n"; } break; case TOKEN_NEWLIST: m_newlist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <newlist>\n"; } break; case TOKEN_IGNORELIST: m_ignorelist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <ignorelist>\n"; } break; case TOKEN_VENDORLIST: m_vendorlist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <vendorlist>\n"; } break; case TOKEN_VERSIONLIST: m_versionlist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <versionlist>\n"; } break; case TOKEN_SAVEDSTATES: ReadInteger( stream, entry_savedstates ); m_savedstates = entry_savedstates; if ( g_verbose ) { std::cout << "Read <savedstates> = <" << entry_savedstates << ">\n"; } break; default: std::cout << "CExtensionHeaderFileSetIO::Unknown token <" << tokenid << ">\n"; break; } ReadClosePar( stream ); } stream.putback( '}' ); if ( g_verbose ) { std::cout << "Reading complete." << std::endl << std::endl; } return( result ); }
/**! * The function loads ASCII file header and tries to identify the type of the *header. * Possible types are * SPE, PAR or PHS * * if none three above identified, returns "undefined" type * it also returns the FileTypeDescriptor, which identifyes the position of the *data in correcponding ASCII file * plus characteristics of the data extracted from correspondent data header. */ FileTypeDescriptor FindDetectorsPar::get_ASCII_header(std::string const &fileName, std::ifstream &data_stream) { std::vector<char> BUF(1024); FileTypeDescriptor file_descriptor; file_descriptor.Type = NumFileTypes; // set the autotype to invalid data_stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary); if (!data_stream.is_open()) { g_log.error() << " can not open existing ASCII data file: " << fileName << std::endl; throw(Kernel::Exception::FileError(" Can not open existing input data file", fileName)); } // let's identify the EOL symbol; As the file may have been prepared on // different OS, from where you are reading it // and no conversion have been performed; char symbol; data_stream.get(symbol); while (symbol > 0x1F) { data_stream.get(symbol); } char EOL; if (symbol == 0x0D) { // Win or old Mac file data_stream.get(symbol); if (symbol == 0x0A) { // Windows file EOL = 0x0A; } else { // Mac EOL = 0x0D; data_stream.putback(symbol); } } else if (symbol == 0x0A) { // unix file. EOL = 0x0A; } else { g_log.error() << " Error reading the first row of the input ASCII data file: " << fileName << " as it contains unprintable characters\n"; throw(Kernel::Exception::FileError(" Error reading the first row of the " "input ASCII data file, as it contains " "unprintable characters", fileName)); } file_descriptor.line_end = EOL; data_stream.seekg(0, std::ios::beg); get_my_line(data_stream, &BUF[0], BUF.size(), EOL); if (!data_stream.good()) { g_log.error() << " Error reading the first row of the input data file " << fileName << ", It may be bigger then 1024 symbols\n"; throw(Kernel::Exception::FileError(" Error reading the first row of the " "input data file, It may be bigger then " "1024 symbols", fileName)); } // let's find if there is one or more groups of symbols inside of the buffer; int space_to_symbol_change = count_changes(&BUF[0], BUF.size()); if (space_to_symbol_change > 1) { // more then one group of symbols in the string, spe file int nData_records(0), nData_blocks(0); // cppcheck-suppress invalidscanf int nDatas = sscanf(&BUF[0], " %d %d ", &nData_records, &nData_blocks); file_descriptor.nData_records = (size_t)nData_records; file_descriptor.nData_blocks = (size_t)nData_blocks; if (nDatas != 2) { g_log.error() << " File " << fileName << " iterpreted as SPE but does " "not have two numbers in the " "first row\n"; throw(Kernel::Exception::FileError(" File iterpreted as SPE but does not " "have two numbers in the first row", fileName)); } file_descriptor.Type = SPE_type; get_my_line(data_stream, &BUF[0], BUF.size(), EOL); if (BUF[0] != '#') { g_log.error() << " File " << fileName << "iterpreted as SPE does not have symbol # in the second row\n"; throw(Kernel::Exception::FileError( " File iterpreted as SPE does not have symbol # in the second row", fileName)); } file_descriptor.data_start_position = data_stream.tellg(); // if it is SPE file then the data begin after the // second line; } else { file_descriptor.data_start_position = data_stream.tellg(); // if it is PHX or PAR file then the data begin // after the first line; file_descriptor.nData_records = atoi(&BUF[0]); file_descriptor.nData_blocks = 0; // let's ifendify now if is PHX or PAR file; data_stream.getline(&BUF[0], BUF.size(), EOL); int space_to_symbol_change = count_changes(&BUF[0], BUF.size()); if (space_to_symbol_change == 6 || space_to_symbol_change == 5) { // PAR file file_descriptor.Type = PAR_type; file_descriptor.nData_blocks = space_to_symbol_change; } else if (space_to_symbol_change == 7) { // PHX file file_descriptor.Type = PHX_type; file_descriptor.nData_blocks = space_to_symbol_change; } else { // something unclear or damaged g_log.error() << " can not identify format of the input data file " << fileName << std::endl; throw(Kernel::Exception::FileError( " can not identify format of the input data file", fileName)); } } return file_descriptor; }
// reads in next token from file and matches it to a token type, // if tokStr is non-NULL then it will be set to the text of the token MD5Model::TOKEN MD5Model::getNextToken(std::ifstream &fin, std::string *tokStr) { skipWhitespace(fin); std::string str; TOKEN t = TOKEN_INVALID; while (!fin.eof()) { char c = '\0'; fin.get(c); // single character tokens if ('{' == c || '}' == c || '(' == c || ')' == c) { // if already reading in a token, treat this as a delimiter if (t != TOKEN_INVALID) { fin.putback(c); if (tokStr != NULL) (*tokStr) = str; } if ('{' == c) t = TOKEN_LBRACE; if ('}' == c) t = TOKEN_RBRACE; if ('(' == c) t = TOKEN_LPAREN; if (')' == c) t = TOKEN_RPAREN; if (tokStr) { (*tokStr) = std::string(); (*tokStr) += c; } return t; } if (isdigit(c)) { str += c; if (TOKEN_INVALID == t) t = TOKEN_INT; else if (t != TOKEN_INT && t != TOKEN_FLOAT && t != TOKEN_KEYWORD) { std::string msg("MD5Model::getNextToken(): invalid token '"); msg += str + "'"; throw Exception(msg); } } if ('-' == c) { str += c; if (TOKEN_INVALID == t) t = TOKEN_INT; else { std::string msg("MD5Model::getNextToken(): invalid token '"); msg += str + "'"; throw Exception(msg); } } if (isalpha(c)) { str += c; if (TOKEN_INVALID == t) t = TOKEN_KEYWORD; else if (t != TOKEN_KEYWORD) { std::string msg("MD5Model::getNextToken(): invalid token '"); msg += str + "'"; throw Exception(msg); } } if ('"' == c) { // treat as a delimeter if already reading in a token if (t != TOKEN_INVALID) { fin.putback(c); if (tokStr != NULL) (*tokStr) = str; return t; } readString(fin, str); if (tokStr != NULL) (*tokStr) = str; return TOKEN_STRING; } if ('.' == c) { str += c; if (t != TOKEN_INT) { std::string msg("MD5Model::getNextToken(): invalid token '"); msg += str + "'"; throw Exception(msg); } t = TOKEN_FLOAT; } if ('/' == c) { // treat as a delimeter if already reading in a token if (t != TOKEN_INVALID) { if (tokStr != NULL) (*tokStr) = str; return t; } skipComments(fin); skipWhitespace(fin); continue; } // treat whitespace as a delimeter if (IS_WHITESPACE(c)) { if (tokStr != NULL) (*tokStr) = str; return t; } // at this point token type should be set, if it hasn't been then // token is invalid if (TOKEN_INVALID == t) { std::string msg("MD5Model::getNextToken(): invalid token '"); str += c; msg += str + "'"; throw Exception(msg); } } return TOKEN_INVALID; }
void Config::putbackIntoStream(std::ifstream& file, const std::string& line) { for(int i = line.length(); i >= 0; i--) { file.putback(line[i]); } }
int CConfigurationFileSettingsDataAsciiIO::ReadFile( std::ifstream &stream ) { int result; std::string tokenid; int entry_newconfigflag; std::string entry_configsettingsfile; int entry_autoreadheaderflags; int entry_autoloadconfigflags; int entry_autosaveconfigflags; result = true; if ( g_verbose ) { ctrace << "Reading CConfigurationFileSettingsDataAsciiIO" << std::endl; } while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, tokenid ); if ( g_verbose > 1 ) { std::cout << "Read Token = <" << tokenid << ">\n"; } switch( token_match( tokenid, token_list, token_num ) ) { case TOKEN_NEWCONFIGFLAG: ReadInteger( stream, entry_newconfigflag ); m_newconfigflag = entry_newconfigflag; if ( g_verbose ) { std::cout << "Read <newconfigflag> = <" << entry_newconfigflag << ">\n"; } break; case TOKEN_CONFIGSETTINGSFILE: ReadQuotedString( stream, entry_configsettingsfile ); m_configfile = entry_configsettingsfile; if ( g_verbose ) { std::cout << "Read <configsettingsfile> = <" << entry_configsettingsfile << ">\n"; } break; case TOKEN_AUTOREADHEADERFLAGS: ReadInteger( stream, entry_autoreadheaderflags ); m_autoreadheaderflags = entry_autoreadheaderflags; if ( g_verbose ) { std::cout << "Read <autoreadheaderflags> = <" << entry_autoreadheaderflags << ">\n"; } break; case TOKEN_AUTOLOADCONFIGFLAGS: ReadInteger( stream, entry_autoloadconfigflags ); m_autoloadconfigflags = entry_autoloadconfigflags; if ( g_verbose ) { std::cout << "Read <autoloadconfigflags> = <" << entry_autoloadconfigflags << ">\n"; } break; case TOKEN_AUTOSAVECONFIGFLAGS: ReadInteger( stream, entry_autosaveconfigflags ); m_autosaveconfigflags = entry_autosaveconfigflags; if ( g_verbose ) { std::cout << "Read <autosaveconfigflags> = <" << entry_autosaveconfigflags << ">\n"; } break; default: std::cout << "CConfigurationFileSettingsIO::Unknown token <" << tokenid << ">\n"; break; } ReadClosePar( stream ); } stream.putback( '}' ); if ( g_verbose ) { std::cout << "Reading complete." << std::endl << std::endl; } return result; }
int CExtensionSiteInfoIODataAsciiIO::ReadFile( std::ifstream &stream ) { int result; std::string tokenid; std::string entry_description; std::string entry_indexdirlocal; std::string entry_indexpagenet; std::string entry_indexpagelocal; std::string entry_glheadernet; std::string entry_glheaderlocal; std::string entry_glxheadernet; std::string entry_glxheaderlocal; std::string entry_wglheadernet; std::string entry_wglheaderlocal; std::string entry_coreheadernet; std::string entry_coreheaderlocal; int entry_downloadflags; std::string entry_filetypefilters; result = true; if ( g_verbose ) { std::cout << "Reading CExtensionSiteInfoIODataAsciiIO" << std::endl; } while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, tokenid ); if ( g_verbose > 1 ) { std::cout << "Read Token = <" << tokenid << ">\n"; } switch( token_match( tokenid, token_list, token_num ) ) { case TOKEN_DESCRIPTION: ReadQuotedString( stream, entry_description ); m_description = entry_description; if ( g_verbose ) { std::cout << "Read <description> = <" << entry_description << ">\n"; } break; case TOKEN_INDEXDIRLOCAL: ReadQuotedString( stream, entry_indexdirlocal ); m_indexdirlocal = entry_indexdirlocal; if ( g_verbose ) { std::cout << "Read <indexdirlocal> = <" << entry_indexdirlocal << ">\n"; } break; case TOKEN_INDEXPAGENET: ReadQuotedString( stream, entry_indexpagenet ); m_indexpagenet = entry_indexpagenet; if ( g_verbose ) { std::cout << "Read <indexpagenet> = <" << entry_indexpagenet << ">\n"; } break; case TOKEN_INDEXPAGELOCAL: ReadQuotedString( stream, entry_indexpagelocal ); m_indexpagelocal = entry_indexpagelocal; if ( g_verbose ) { std::cout << "Read <indexpagelocal> = <" << entry_indexpagelocal << ">\n"; } break; case TOKEN_GLHEADERNET: ReadQuotedString( stream, entry_glheadernet ); m_glheadernet = entry_glheadernet; if ( g_verbose ) { std::cout << "Read <glheadernet> = <" << entry_glheadernet << ">\n"; } break; case TOKEN_GLHEADERLOCAL: ReadQuotedString( stream, entry_glheaderlocal ); m_glheaderlocal = entry_glheaderlocal; if ( g_verbose ) { std::cout << "Read <glheaderlocal> = <" << entry_glheaderlocal << ">\n"; } break; case TOKEN_GLXHEADERNET: ReadQuotedString( stream, entry_glxheadernet ); m_glxheadernet = entry_glxheadernet; if ( g_verbose ) { std::cout << "Read <glxheadernet> = <" << entry_glxheadernet << ">\n"; } break; case TOKEN_GLXHEADERLOCAL: ReadQuotedString( stream, entry_glxheaderlocal ); m_glxheaderlocal = entry_glxheaderlocal; if ( g_verbose ) { std::cout << "Read <glxheaderlocal> = <" << entry_glxheaderlocal << ">\n"; } break; case TOKEN_WGLHEADERNET: ReadQuotedString( stream, entry_wglheadernet ); m_wglheadernet = entry_wglheadernet; if ( g_verbose ) { std::cout << "Read <wglheadernet> = <" << entry_wglheadernet << ">\n"; } break; case TOKEN_WGLHEADERLOCAL: ReadQuotedString( stream, entry_wglheaderlocal ); m_wglheaderlocal = entry_wglheaderlocal; if ( g_verbose ) { std::cout << "Read <wglheaderlocal> = <" << entry_wglheaderlocal << ">\n"; } break; case TOKEN_COREHEADERNET: ReadQuotedString( stream, entry_coreheadernet ); m_coreheadernet = entry_coreheadernet; if ( g_verbose ) { std::cout << "Read <coreheadernet> = <" << entry_coreheadernet << ">\n"; } break; case TOKEN_COREHEADERLOCAL: ReadQuotedString( stream, entry_coreheaderlocal ); m_coreheaderlocal = entry_coreheaderlocal; if ( g_verbose ) { std::cout << "Read <coreheaderlocal> = <" << entry_coreheaderlocal << ">\n"; } break; case TOKEN_DOWNLOADFLAGS: ReadInteger( stream, entry_downloadflags ); m_downloadflags = entry_downloadflags; if ( g_verbose ) { std::cout << "Read <downloadflags> = <" << entry_downloadflags << ">\n"; } break; case TOKEN_FILETYPEFILTERS: ReadQuotedString( stream, entry_filetypefilters ); m_filetypefilter = entry_filetypefilters; if ( g_verbose ) { std::cout << "Read <filetypefilters> = <" << entry_filetypefilters << ">\n"; } break; default: std::cout << "CExtensionSiteInfoIO::Unknown token <" << tokenid << ">\n"; break; } ReadClosePar( stream ); } stream.putback( '}' ); if ( g_verbose ) { std::cout << "Reading complete." << std::endl << std::endl; } return( result ); }