.. _program_listing_file_src_util_parser.cpp: Program Listing for File parser.cpp =================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src_util/parser.cpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #include #include "parser.hpp" #include "global_parameter.hpp" using namespace std; bool parser::no_rewind = false; istream & parser::find_next(istream &flux, const char* search) { string buff; //recherche la chaine while (flux.peek() != EOF) { flux >> buff; if(buff.compare(search)==0){ return flux; } flux.ignore(numeric_limits::max(), '\n'); } qcm_throw(to_string(search)+" not found in input file."); return flux; } istream & operator==(istream &flux, const char* search) { string buff; // resets the stream to the beginning if(!parser::no_rewind){ flux.clear(); flux.seekg(0); } //recherche la chaine while (flux.peek() != EOF) { flux >> buff; if(buff.compare(search)==0){ return flux; } flux.ignore(numeric_limits::max(), '\n'); } flux.setstate(ios::failbit); return flux; } istream & operator==(istream &flux, const string &search) { string buff; // resets the stream to the beginning if(!parser::no_rewind){ flux.clear(); flux.seekg(0); } //recherche la chaine while (flux.peek() != EOF) { flux >> buff; if(buff.compare(search)==0){ return flux; } flux.ignore(numeric_limits::max(), '\n'); } flux.setstate(ios::failbit); return flux; } istream & operator>>(istream &flux, const char* search) { string buff; // resets the stream to the beginning if(!parser::no_rewind){ flux.clear(); flux.seekg(0); } //recherche la chaine while (flux.peek() != EOF) { flux >> buff; if(buff.compare(search)==0){ return flux; } flux.ignore(numeric_limits::max(), '\n'); } qcm_throw(to_string(search)+" not found in input file."); return flux; } istream & operator>>(istream &flux, const string &search) { string buff; // resets the stream to the beginning if(!parser::no_rewind){ flux.clear(); flux.seekg(0); } //recherche la chaine while (flux.peek() != EOF) { flux >> buff; if(buff.compare(search)==0){ return flux; } flux.ignore(numeric_limits::max(), '\n'); } qcm_throw(to_string(search)+" not found in input file."); return flux; } vector read_strings(istream &s) { vector X; string line; do{ getline(s,line); istringstream sin(line); while(sin.good()){ string tmp; sin >> skipws >> tmp; if(tmp[0]=='#' or tmp.size() == 0) break; X.push_back(tmp); } } while(line.length() > 0 and line[0]=='#'); return X; } ostream & operator<<(ostream &s, vector &X) { for(auto& x: X) s << x << " "; return s; } int cluster_index_from_string(string& S) { int label = 0; size_t pos = S.rfind('_'); if(pos != string::npos){ label = from_string(S.substr(pos+1)); S.erase(pos); } return label; } void check_name(const string& S) { if(S.rfind('_') != string::npos) qcm_ED_throw("the separator '_' is forbidden within operator names!" ); } vector split_string(const string &s, char delim) { vector elems; std::stringstream ss; ss.str(s); string item; while (getline(ss, item, delim)) elems.push_back(item); return elems; } void banner(const char c, const char s[128], ostream &fout) { size_t i,l,l2,l3; l = (int)strlen(s); if(l==0){ for(i=0; i<80; ++i) fout << c; fout << endl; return; } if(l < 76){ l2 = 80 - l - 4; if(l2%2) l3 = l2/2 + 1; else l3 = l2/2; l2 = l2/2; fout << "\n"; for(i=0; i