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 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 00053 TokenWriter(Mode mode); 00054 00065 TokenWriter(const std::string& rFilename, 00066 std::ios::openmode openmode = std::ios::out|std::ios::trunc); 00067 00069 ~TokenWriter(void); 00070 00077 std::string Str(void); 00078 00085 int Columns(void) const; 00086 00093 void Columns(int columns); 00094 00101 void Endl(void); 00102 00111 void Write(Token& rToken); 00112 00121 void Write(const std::string& rString); 00122 00131 void Write(Idx index); 00132 00141 void WriteFloat(const double& val); 00142 00151 void WriteOption(const std::string& rOpt); 00152 00161 void WriteBegin(const std::string& rLabel); 00162 00171 void WriteEnd(const std::string& rLabel); 00172 00181 void Comment(const std::string& rComment); 00182 00191 void operator << (Token& rToken) { 00192 Write(rToken); 00193 } 00194 00203 void operator << (const std::string& rString) { 00204 Write(rString); 00205 } 00206 00215 void operator << (const Idx index) { 00216 Write(index); 00217 } 00218 00219 00220 private: 00222 Mode mMode; 00223 00225 std::ostream* mpStream; 00226 00228 std::ofstream mFStream; 00229 00231 std::ostringstream mSStream; 00232 00234 std::string mFileName; 00235 00237 int mColumns; 00238 00240 int mColCount; 00241 00242 }; 00243 00244 } // namespace faudes 00245 00246 #define TOKENWRITER_H 00247 #endif 00248