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/>.
25 Stream operators for token
27 \*---------------------------------------------------------------------------*/
32 #include "IOstreams.H"
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 Foam::token::token(Istream& is)
45 // * * * * * * * * * * * * IOstream operators * * * * * * * * * * * * * * * //
47 Foam::Istream& Foam::operator>>(Istream& is, token& t)
54 Foam::Ostream& Foam::operator<<(Ostream& os, const token& t)
58 case token::UNDEFINED:
60 WarningIn("Ostream& operator<<(Ostream&, const token&)")
61 << "Undefined token" << endl;
64 case token::PUNCTUATION:
65 os << t.punctuationToken_;
69 os << *t.wordTokenPtr_;
73 os << *t.stringTokenPtr_;
80 case token::FLOAT_SCALAR:
81 os << t.floatScalarToken_;
84 case token::DOUBLE_SCALAR:
85 os << t.doubleScalarToken_;
88 case token::LONG_DOUBLE_SCALAR:
89 os << t.longDoubleScalarToken_;
93 os << *t.compoundTokenPtr_;
96 case token::FATALERROR:
98 WarningIn("Ostream& operator<<(Ostream&, const token&)")
99 << "Error token" << endl;
104 SeriousErrorIn("Ostream& operator<<(Ostream&, const token&)")
109 // Check state of stream
110 os.check("Ostream& operator<<(Ostream&, const token&)");
116 ostream& Foam::operator<<(ostream& os, const token::punctuationToken& pt)
118 return os << char(pt);
122 Foam::Ostream& Foam::operator<<(Ostream& os, const token::punctuationToken& pt)
124 return os << char(pt);
128 Foam::Ostream& Foam::operator<<(Ostream& os, const token::compound& ct)
130 os << ct.type() << token::SPACE;
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip)
141 const token& t = ip.t_;
143 os << "on line " << t.lineNumber();
147 case token::UNDEFINED:
148 os << " an undefined token";
151 case token::PUNCTUATION:
152 os << " the punctuation token " << '\'' << t.pToken() << '\'';
156 os << " the word " << '\'' << t.wordToken() << '\'';
160 os << " the string " << t.stringToken();
164 os << " the label " << t.labelToken();
167 case token::FLOAT_SCALAR:
168 os << " the floatScalar " << t.floatScalarToken();
171 case token::DOUBLE_SCALAR:
172 os << " the doubleScalar " << t.doubleScalarToken();
175 case token::LONG_DOUBLE_SCALAR:
176 os << " the longDoubleScalar " << t.doubleScalarToken();
179 case token::COMPOUND:
181 if (t.compoundToken().empty())
183 os << " the empty compound of type "
184 << t.compoundToken().type();
188 os << " the compound of type "
189 << t.compoundToken().type();
194 case token::FATALERROR:
199 os << " an unknown token type " << '\'' << int(t.type()) << '\'';
206 // template specialization
210 #if defined (__GNUC__)
213 Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip)
215 const token& t = ip.t_;
217 os << "on line " << t.lineNumber();
221 case token::UNDEFINED:
222 os << " an undefined token";
225 case token::PUNCTUATION:
226 os << " the punctuation token " << '\'' << t.pToken() << '\'';
230 os << " the word " << '\'' << t.wordToken() << '\'';
234 os << " the string " << t.stringToken();
238 os << " the label " << t.labelToken();
241 case token::FLOAT_SCALAR:
242 os << " the floatScalar " << t.floatScalarToken();
245 case token::DOUBLE_SCALAR:
246 os << " the doubleScalar " << t.doubleScalarToken();
249 case token::LONG_DOUBLE_SCALAR:
250 os << " the longDoubleScalar " << t.longDoubleScalarToken();
253 case token::COMPOUND:
255 if (t.compoundToken().empty())
257 os << " the empty compound of type "
258 << t.compoundToken().type();
262 os << " the compound of type "
263 << t.compoundToken().type();
268 case token::FATALERROR:
273 os << " an unknown token type " << '\'' << int(t.type()) << '\'';
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 } // End namespace Foam
284 // ************************************************************************* //