ConfigFile.cc
Go to the documentation of this file.
00001 
00005 #include <blort/Recognizer3D/Except.hh>
00006 #include <blort/Recognizer3D/ConfigFile.hh>
00007 
00008 namespace P 
00009 {
00010 
00011 ConfigFile::ConfigFile(const string &name)
00012 {
00013   line_cnt = 0;
00014   file.open(name.c_str(), ios::in);
00015   if(!file)
00016     throw Except(__HERE__, "failed to open file '%s'", name.c_str());
00017 }
00018 
00019 ConfigFile::~ConfigFile()
00020 {
00021   file.close();
00022 }
00023 
00030 bool ConfigFile::GetLine(string &str)
00031 {
00032   bool success = false;
00033   while(file && !success)
00034   {
00035     // get the next line
00036     str.erase();
00037     getline(file, str);
00038     line_cnt++;
00039     RemoveEOL(str);
00040     if(!IsComment(str))
00041       success = true;
00042   }
00043   return success;
00044 }
00045 
00052 void ConfigFile::RemoveEOL(string &str)
00053 {
00054   string::size_type p = str.find_last_of("\n\r");
00055   if(p != string::npos)
00056     str.erase(p, 1);
00057 }
00058 
00063 bool ConfigFile::IsComment(string &str)
00064 {
00065   // skip leading whitespaces
00066   string::size_type p = str.find_first_not_of(" \f\n\r\t\v");
00067   if(p == string::npos)
00068     return true;
00069   if(str[p] == '#')
00070     return true;
00071   return false;
00072 }
00073 
00081 bool GetWord(const string &str, string &word, string::size_type &pos)
00082 {
00083   // skip leading whitespaces
00084   string::size_type s = str.find_first_not_of(" \f\n\r\t\v", pos);
00085   if(s != string::npos)
00086   {
00087     string::size_type e = str.find_first_of(" \f\n\r\t\v", s);
00088     if(e != string::npos)
00089       word = str.substr(s, e - s);
00090     else
00091       word = str.substr(s);
00092     pos = e;
00093     return true;
00094   }
00095   else
00096   {
00097     pos = s;
00098     return false;
00099   }
00100 }
00101 
00102 }
00103 


blort
Author(s): Michael Zillich, Thomas Mörwald, Johann Prankl, Andreas Richtsfeld, Bence Magyar (ROS version)
autogenerated on Thu Jan 2 2014 11:38:25