1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 Foam::Ostream& Foam::OSstream::write(const token&)
38 Foam::Ostream& Foam::OSstream::write(const char c)
45 setState(os_.rdstate());
50 Foam::Ostream& Foam::OSstream::write(const char* str)
52 lineNumber_ += string(str).count(token::NL);
54 setState(os_.rdstate());
59 Foam::Ostream& Foam::OSstream::write(const word& str)
62 setState(os_.rdstate());
67 Foam::Ostream& Foam::OSstream::write(const string& str)
69 os_ << token::BEGIN_STRING;
71 register int backslash = 0;
72 for (string::const_iterator iter = str.begin(); iter != str.end(); ++iter)
74 register char c = *iter;
79 // suppress output until we know if other characters follow
82 else if (c == token::NL)
85 backslash++; // backslash escape for newline
87 else if (c == token::END_STRING)
89 backslash++; // backslash escape for quote
92 // output pending backslashes
102 // silently drop any trailing backslashes
103 // they would otherwise appear like an escaped end-quote
105 os_ << token::END_STRING;
107 setState(os_.rdstate());
112 Foam::Ostream& Foam::OSstream::writeQuoted
114 const std::string& str,
120 os_ << token::BEGIN_STRING;
122 register int backslash = 0;
125 string::const_iterator iter = str.begin();
130 register char c = *iter;
135 // suppress output until we know if other characters follow
138 else if (c == token::NL)
141 backslash++; // backslash escape for newline
143 else if (c == token::END_STRING)
145 backslash++; // backslash escape for quote
148 // output pending backslashes
158 // silently drop any trailing backslashes
159 // they would otherwise appear like an escaped end-quote
160 os_ << token::END_STRING;
164 // output unquoted string, only advance line number on newline
165 lineNumber_ += string(str).count(token::NL);
169 setState(os_.rdstate());
174 Foam::Ostream& Foam::OSstream::write(const label val)
177 setState(os_.rdstate());
182 Foam::Ostream& Foam::OSstream::write(const floatScalar val)
185 setState(os_.rdstate());
190 Foam::Ostream& Foam::OSstream::write(const doubleScalar val)
193 setState(os_.rdstate());
198 Foam::Ostream& Foam::OSstream::write(const longDoubleScalar val)
201 setState(os_.rdstate());
206 Foam::Ostream& Foam::OSstream::write(const char* buf, std::streamsize count)
208 if (format() != BINARY)
210 FatalIOErrorIn("Ostream::write(const char*, std::streamsize)", *this)
211 << "stream format not binary"
212 << abort(FatalIOError);
215 os_ << token::BEGIN_LIST;
216 os_.write(buf, count);
217 os_ << token::END_LIST;
219 setState(os_.rdstate());
225 void Foam::OSstream::indent()
227 for (register unsigned short i = 0; i < indentLevel_*indentSize_; i++)
234 void Foam::OSstream::flush()
240 // Add carriage return and flush stream
241 void Foam::OSstream::endl()
248 // Get flags of output stream
249 std::ios_base::fmtflags Foam::OSstream::flags() const
255 // Set flags of output stream
256 std::ios_base::fmtflags Foam::OSstream::flags(const ios_base::fmtflags f)
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 // Get width of output field
266 int Foam::OSstream::width() const
271 // Set width of output field (and return old width)
272 int Foam::OSstream::width(const int w)
277 // Get precision of output field
278 int Foam::OSstream::precision() const
280 return os_.precision();
283 // Set precision of output field (and return old precision)
284 int Foam::OSstream::precision(const int p)
286 return os_.precision(p);
290 // ************************************************************************* //