Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / db / IOstreams / Sstreams / prefixOSstream.C
blob8ef62bf021c26810879656e516172df9e55d6506
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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 \*---------------------------------------------------------------------------*/
26 #include "prefixOSstream.H"
27 #include "Pstream.H"
28 #include "token.H"
30 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
32 inline void Foam::prefixOSstream::checkWritePrefix()
34     if (printPrefix_ && prefix_.size())
35     {
36         OSstream::write(prefix_.c_str());
37         printPrefix_ = false;
38     }
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
44 Foam::prefixOSstream::prefixOSstream
46     ostream& os,
47     const string& name,
48     streamFormat format,
49     versionNumber version,
50     compressionType compression
53     OSstream(os, name, format, version, compression),
54     printPrefix_(true),
55     prefix_("")
59 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
61 void Foam::prefixOSstream::print(Ostream& os) const
63     os  << "prefixOSstream ";
64     OSstream::print(os);
68 Foam::Ostream& Foam::prefixOSstream::write(const token&)
70     return *this;
74 Foam::Ostream& Foam::prefixOSstream::write(const char c)
76     checkWritePrefix();
77     OSstream::write(c);
79     if (c == token::NL)
80     {
81         printPrefix_ = true;
82     }
84     return *this;
88 Foam::Ostream& Foam::prefixOSstream::write(const char* str)
90     checkWritePrefix();
91     OSstream::write(str);
93     size_t len = strlen(str);
94     if (len && str[len-1] == token::NL)
95     {
96         printPrefix_ = true;
97     }
99     return *this;
103 Foam::Ostream& Foam::prefixOSstream::write(const word& val)
105     checkWritePrefix();
106     return OSstream::write(val);
110 Foam::Ostream& Foam::prefixOSstream::write(const string& val)
112     checkWritePrefix();
113     return OSstream::write(val);
117 Foam::Ostream& Foam::prefixOSstream::writeQuoted
119     const std::string& val,
120     const bool quoted
123     checkWritePrefix();
124     return OSstream::writeQuoted(val, quoted);
128 Foam::Ostream& Foam::prefixOSstream::write(const label val)
130     checkWritePrefix();
131     return OSstream::write(val);
135 Foam::Ostream& Foam::prefixOSstream::write(const floatScalar val)
137     checkWritePrefix();
138     return OSstream::write(val);
142 Foam::Ostream& Foam::prefixOSstream::write(const doubleScalar val)
144     checkWritePrefix();
145     return OSstream::write(val);
149 Foam::Ostream& Foam::prefixOSstream::write(const longDoubleScalar val)
151     checkWritePrefix();
152     return OSstream::write(val);
156 Foam::Ostream& Foam::prefixOSstream::write
158     const char* buf,
159     std::streamsize count
162     checkWritePrefix();
163     return OSstream::write(buf, count);
167 void Foam::prefixOSstream::indent()
169     checkWritePrefix();
170     OSstream::indent();
173 // ************************************************************************* //