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 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 00112 std::string FileName(void) const; 00113 00126 bool Peek(Token& token); 00127 00140 bool Get(Token& token); 00141 00148 void Rewind(void); 00149 00165 void ReadBegin(const std::string& rLabel); 00166 00178 void ReadEnd(const std::string& rLabel); 00179 00195 void SeekBegin(const std::string& rLabel); 00196 00209 void SeekEnd(const std::string& rLabel); 00210 00231 bool Eos(const std::string& rLabel); 00232 00242 long int ReadInteger(void); 00243 00253 double ReadFloat(void); 00254 00264 const std::string& ReadString(void); 00265 00275 const std::string& ReadOption(void); 00276 00278 bool operator >> (Token& token) { 00279 return Get(token); 00280 } 00281 00288 int Line(void) const; 00289 00293 std::string FileLine(void) const; 00294 00295 private: 00297 Mode mMode; 00298 00300 std::istream* mpStream; 00301 00303 std::ifstream mFStream; 00304 00306 std::istringstream* mpSStream; 00307 00309 std::string mFileName; 00310 00312 int mLineCount; 00313 00315 long int mFilePos; 00316 00318 int mLevel; 00319 00321 std::vector<long int> mLevelPos; 00322 00324 std::vector<long int> mLevelLine; 00325 00327 std::vector<int> mSeekLevel; 00328 00330 std::string mLastString; 00331 00333 bool mHasPeekToken; 00334 00336 Token mPeekToken; 00337 }; 00338 00339 } // namespace faudes 00340 00341 #define TOKENREADER_H 00342 #endif