#include #include #include #include #include #include #include #include #include #include using namespace std; const int DEBUG=0; int str2int (std::string ss, int base ); //---------------------------------------------------------------- class TIniFile { private: //FILE *iniFile; public: bool TIniFile_debug; std::ifstream* iniFile; std::string Name; TIniFile(std::string fName,bool debug=false) { TIniFile_debug=debug; if(TIniFile_debug) printf("TIniFile:: Constructor Fname=%s \n",fName.c_str()); Name=fName; //std::ifstream iniFile(Name.c_str()); iniFile = new std::ifstream(Name.c_str(),std::ios_base::in); if(iniFile->is_open() != true) { //--- !iniFile) { printf("TIniFile:: Cannot open input file=%s\n",Name.c_str()); } else{ if(TIniFile_debug){ printf("TIniFile:: Fname=%s opened...\n",Name.c_str()); } } } //-------------------------------------------------- std::string GetHost(std::string COMP) { if(TIniFile_debug) printf("TIniFile::GetHost comp=%s from file: %s \n",COMP.c_str(),Name.c_str()); if(iniFile) { iniFile->clear(); iniFile->seekg(0,std::ios_base::beg); } else { printf(" TIniFile::ReadFADC closed??? \n"); return 0; } std::string str, F0, F1, HOST="localhost"; int SNUM=0; while( std::getline(*iniFile,str) ) { //copy String from inifile if (DEBUG>5) std::cout << str << std::endl; // construct a stream from the string std::stringstream strstr(str); // use stream iterators to copy the stream to the vector as whitespace separated strings std::istream_iterator it(strstr); std::istream_iterator end; std::vector words(it, end); // send the vector to stdout. //std::ostream_iterator oit(std::cout); //std::copy(words.begin(), words.end(), oit); //printf(" size of vector = %d \n",words.size()); // //--------------- skip empty lines ---- if (words.size()<1) continue; //----------------------- F0=words.at(0); //--------------- skip single word ---- if (words.size()<2) continue; if (DEBUG>2) cout << "------> test F0 = " << F0 << endl; //--------------- skip comments ---- if (F0.substr(0,1)=="#" || F0.substr(0,2)=="//" || F0.substr(0,1)=="*" ) { if (DEBUG>2) printf(" Comment line = %s \n",F0.substr(0,2).c_str()); continue; } //----------- test COMP ----- //if (F0==COMP) { //-- case sensitive if (!strcasecmp(F0.c_str(),COMP.c_str())) { //-- case-insensitive F1=words.at(1); //--------------- skip comments in second word ---- if (F1.substr(0,1)=="#" || F1.substr(0,2)=="//" || F1.substr(0,1)=="*" ) { if (DEBUG>0) printf(" Comment line in second word = %s \n",F1.substr(0,2).c_str()); continue; } if (DEBUG>0) cout << "------> found comp " << words.at(1) << SNUM << endl; HOST=words.at(1); SNUM++; continue; } if (DEBUG>0) std::cout << str << std::endl; if (DEBUG>0) printf("\n Read SNUM=%d, next line \n",SNUM); } //-- end of file:: last FADC read:: ---- return HOST; } //-- end ReadFADC() ~TIniFile() { if(TIniFile_debug)printf("TIniFile:: Destructor Fname=%s \n",Name.c_str()); iniFile->close(); } };