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 #ifndef FAUDES_TOKENWRITER_H 00024 00025 #include "definitions.h" 00026 #include "token.h" 00027 #include <fstream> 00028 #include <iostream> 00029 00030 namespace faudes { 00031 00038 class TokenWriter { 00039 00040 public: 00041 00045 enum Mode {File, Stdout, String}; 00046 00059 TokenWriter(Mode mode); 00060 00071 TokenWriter(const std::string& rFilename, 00072 std::ios::openmode openmode = std::ios::out|std::ios::trunc); 00073 00075 ~TokenWriter(void); 00076 00084 std::string FileName(void) const; 00085 00092 Mode DestMode(void) const { return mMode;}; 00093 00100 std::string Str(void); 00101 00108 int Columns(void) const; 00109 00116 void Columns(int columns); 00117 00124 void Endl(void); 00125 00134 void Write(Token& rToken); 00135 00144 void WriteString(const std::string& rString); 00145 00154 void WriteInteger(Idx index); 00155 00164 void WriteFloat(const double& val); 00165 00174 void WriteInteger16(long int val); 00175 00184 void WriteOption(const std::string& rOpt); 00185 00194 void WriteBegin(const std::string& rLabel); 00195 00204 void WriteEnd(const std::string& rLabel); 00205 00214 void WriteComment(const std::string& rComment); 00215 00226 TokenWriter& operator << (Token& rToken) { 00227 Write(rToken); 00228 return *this; 00229 } 00230 00241 TokenWriter& operator << (const std::string& rString) { 00242 WriteString(rString); 00243 return *this; 00244 } 00245 00256 TokenWriter& operator << (const Idx index) { 00257 WriteInteger(index); 00258 return *this; 00259 } 00260 00261 00262 private: 00264 Mode mMode; 00265 00267 std::ostream* mpStream; 00268 00270 std::ofstream mFStream; 00271 00273 std::ostringstream mSStream; 00274 00276 std::string mFileName; 00277 00279 int mColumns; 00280 00282 int mColCount; 00283 00284 }; 00285 00286 } // namespace faudes 00287 00288 #define FAUDES_TOKENWRITER_H 00289 #endif 00290