00001 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Bernd Opitz 00006 Exclusive copyright is granted to Klaus Schmidt 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00021 00022 00023 00024 #ifndef FAUDES_TOKENREADER_H 00025 00026 #include <vector> 00027 00028 #include "definitions.h" 00029 #include "exception.h" 00030 #include "token.h" 00031 00032 namespace faudes { 00033 00059 class TokenReader { 00060 public: 00061 00065 enum Mode {File, Stdin, String}; 00066 00079 TokenReader(Mode mode, const std::string& rInString=""); 00080 00090 TokenReader(const std::string& rFilename); 00091 00092 00096 ~TokenReader(void); 00097 00104 bool good(void) const; 00105 00113 std::string FileName(void) const; 00114 00121 Mode SourceMode(void) const { return mMode;}; 00122 00135 bool Peek(Token& token); 00136 00149 bool Get(Token& token); 00150 00157 void Rewind(void); 00158 00174 void ReadBegin(const std::string& rLabel); 00175 00187 void ReadEnd(const std::string& rLabel); 00188 00204 void SeekBegin(const std::string& rLabel); 00205 00218 void SeekEnd(const std::string& rLabel); 00219 00240 bool Eos(const std::string& rLabel); 00241 00251 long int ReadInteger(void); 00252 00262 double ReadFloat(void); 00263 00273 const std::string& ReadString(void); 00274 00284 const std::string& ReadOption(void); 00285 00287 bool operator >> (Token& token) { 00288 return Get(token); 00289 } 00290 00297 int Line(void) const; 00298 00302 std::string FileLine(void) const; 00303 00304 private: 00306 Mode mMode; 00307 00309 std::istream* mpStream; 00310 00312 std::ifstream mFStream; 00313 00315 std::istringstream* mpSStream; 00316 00318 std::string mFileName; 00319 00321 int mLineCount; 00322 00324 long int mFilePos; 00325 00327 int mLevel; 00328 00330 std::vector<long int> mLevelPos; 00331 00333 std::vector<long int> mLevelLine; 00334 00336 std::vector<int> mSeekLevel; 00337 00339 std::string mLastString; 00340 00342 bool mHasPeekToken; 00343 00345 Token mPeekToken; 00346 }; 00347 00348 } // namespace faudes 00349 00350 #define FAUDES_TOKENREADER_H 00351 #endif