1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include <OpenFOAM/error.H>
29 #include <OpenFOAM/token.H>
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 Foam::Ostream& Foam::OSstream::write(const token&)
39 Foam::Ostream& Foam::OSstream::write(const char c)
46 setState(os_.rdstate());
51 Foam::Ostream& Foam::OSstream::write(const char* str)
53 lineNumber_ += string(str).count(token::NL);
55 setState(os_.rdstate());
60 Foam::Ostream& Foam::OSstream::write(const word& str)
63 setState(os_.rdstate());
68 Foam::Ostream& Foam::OSstream::write(const string& str)
70 os_ << token::BEGIN_STRING;
72 register int backslash = 0;
73 for (string::const_iterator iter = str.begin(); iter != str.end(); ++iter)
75 register char c = *iter;
80 // suppress output until we know if other characters follow
83 else if (c == token::NL)
86 backslash++; // backslash escape for newline
88 else if (c == token::END_STRING)
90 backslash++; // backslash escape for quote
93 // output pending backslashes
103 // silently drop any trailing backslashes
104 // they would otherwise appear like an escaped end-quote
106 os_ << token::END_STRING;
108 setState(os_.rdstate());
113 Foam::Ostream& Foam::OSstream::writeQuoted
115 const std::string& str,
121 os_ << token::BEGIN_STRING;
123 register int backslash = 0;
126 string::const_iterator iter = str.begin();
131 register char c = *iter;
136 // suppress output until we know if other characters follow
139 else if (c == token::NL)
142 backslash++; // backslash escape for newline
144 else if (c == token::END_STRING)
146 backslash++; // backslash escape for quote
149 // output pending backslashes
159 // silently drop any trailing backslashes
160 // they would otherwise appear like an escaped end-quote
161 os_ << token::END_STRING;
165 // output unquoted string, only advance line number on newline
166 lineNumber_ += string(str).count(token::NL);
170 setState(os_.rdstate());
175 Foam::Ostream& Foam::OSstream::write(const label val)
178 setState(os_.rdstate());
183 Foam::Ostream& Foam::OSstream::write(const floatScalar val)
186 setState(os_.rdstate());
191 Foam::Ostream& Foam::OSstream::write(const doubleScalar val)
194 setState(os_.rdstate());
199 Foam::Ostream& Foam::OSstream::write(const char* buf, std::streamsize count)
201 if (format() != BINARY)
203 FatalIOErrorIn("Ostream::write(const char*, std::streamsize)", *this)
204 << "stream format not binary"
205 << abort(FatalIOError);
208 os_ << token::BEGIN_LIST;
209 os_.write(buf, count);
210 os_ << token::END_LIST;
212 setState(os_.rdstate());
218 void Foam::OSstream::indent()
220 for (register unsigned short i = 0; i < indentLevel_*indentSize_; i++)
227 void Foam::OSstream::flush()
233 // Add carriage return and flush stream
234 void Foam::OSstream::endl()
241 // Get flags of output stream
242 std::ios_base::fmtflags Foam::OSstream::flags() const
248 // Set flags of output stream
249 std::ios_base::fmtflags Foam::OSstream::flags(const ios_base::fmtflags f)
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 // Get width of output field
259 int Foam::OSstream::width() const
264 // Set width of output field (and return old width)
265 int Foam::OSstream::width(const int w)
270 // Get precision of output field
271 int Foam::OSstream::precision() const
273 return os_.precision();
276 // Set precision of output field (and return old precision)
277 int Foam::OSstream::precision(const int p)
279 return os_.precision(p);
283 // ************************ vim: set sw=4 sts=4 et: ************************ //