1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, 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 case token::VERBATIMSTRING:
74 os << *t.stringTokenPtr_;
81 case token::FLOAT_SCALAR:
82 os << t.floatScalarToken_;
85 case token::DOUBLE_SCALAR:
86 os << t.doubleScalarToken_;
90 os << *t.compoundTokenPtr_;
95 WarningIn("Ostream& operator<<(Ostream&, const token&)")
96 << "Error token" << endl;
101 SeriousErrorIn("Ostream& operator<<(Ostream&, const token&)")
106 // Check state of stream
107 os.check("Ostream& operator<<(Ostream&, const token&)");
113 ostream& Foam::operator<<(ostream& os, const token::punctuationToken& pt)
115 return os << char(pt);
119 Foam::Ostream& Foam::operator<<(Ostream& os, const token::punctuationToken& pt)
121 return os << char(pt);
125 Foam::Ostream& Foam::operator<<(Ostream& os, const token::compound& ct)
127 os << ct.type() << token::SPACE;
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip)
138 const token& t = ip.t_;
140 os << "on line " << t.lineNumber();
144 case token::UNDEFINED:
145 os << " an undefined token";
148 case token::PUNCTUATION:
149 os << " the punctuation token " << '\'' << t.pToken() << '\'';
153 os << " the word " << '\'' << t.wordToken() << '\'';
157 os << " the string " << t.stringToken();
160 case token::VERBATIMSTRING:
161 os << " the verbatim string " << t.stringToken();
165 os << " the label " << t.labelToken();
168 case token::FLOAT_SCALAR:
169 os << " the floatScalar " << t.floatScalarToken();
172 case token::DOUBLE_SCALAR:
173 os << " the doubleScalar " << t.doubleScalarToken();
176 case token::COMPOUND:
178 if (t.compoundToken().empty())
180 os << " the empty compound of type "
181 << t.compoundToken().type();
185 os << " the compound of type "
186 << t.compoundToken().type();
196 os << " an unknown token type " << '\'' << int(t.type()) << '\'';
203 // template specialization
207 #if defined (__GNUC__)
210 Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip)
212 const token& t = ip.t_;
214 os << "on line " << t.lineNumber();
218 case token::UNDEFINED:
219 os << " an undefined token";
222 case token::PUNCTUATION:
223 os << " the punctuation token " << '\'' << t.pToken() << '\'';
227 os << " the word " << '\'' << t.wordToken() << '\'';
231 os << " the string " << t.stringToken();
234 case token::VERBATIMSTRING:
235 os << " the verbatim string " << t.stringToken();
239 os << " the label " << t.labelToken();
242 case token::FLOAT_SCALAR:
243 os << " the floatScalar " << t.floatScalarToken();
246 case token::DOUBLE_SCALAR:
247 os << " the doubleScalar " << t.doubleScalarToken();
250 case token::COMPOUND:
252 if (t.compoundToken().empty())
254 os << " the empty compound of type "
255 << t.compoundToken().type();
259 os << " the compound of type "
260 << t.compoundToken().type();
270 os << " an unknown token type " << '\'' << int(t.type()) << '\'';
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 } // End namespace Foam
281 // ************************************************************************* //