FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

tokenIO.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     Stream operators for token
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include <OpenFOAM/error.H>
00030 #include "token.H"
00031 
00032 #include <OpenFOAM/IOstreams.H>
00033 #include <OpenFOAM/scalar.H>
00034 
00035 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00036 
00037 Foam::token::token(Istream& is)
00038 :
00039     type_(UNDEFINED)
00040 {
00041     is.read(*this);
00042 }
00043 
00044 
00045 // * * * * * * * * * * * * IOstream operators  * * * * * * * * * * * * * * * //
00046 
00047 Foam::Istream& Foam::operator>>(Istream& is, token& t)
00048 {
00049     t.clear();
00050     return is.read(t);
00051 }
00052 
00053 
00054 Foam::Ostream& Foam::operator<<(Ostream& os, const token& t)
00055 {
00056     switch (t.type_)
00057     {
00058         case token::UNDEFINED:
00059             os << "UNDEFINED";
00060             WarningIn("Ostream& operator<<(Ostream&, const token&)")
00061                 << "Undefined token" << endl;
00062         break;
00063 
00064         case token::PUNCTUATION:
00065             os << t.punctuationToken_;
00066         break;
00067 
00068         case token::WORD:
00069             os << *t.wordTokenPtr_;
00070         break;
00071 
00072         case token::STRING:
00073             os << *t.stringTokenPtr_;
00074         break;
00075 
00076         case token::LABEL:
00077             os << t.labelToken_;
00078         break;
00079 
00080         case token::FLOAT_SCALAR:
00081             os << t.floatScalarToken_;
00082         break;
00083 
00084         case token::DOUBLE_SCALAR:
00085             os << t.doubleScalarToken_;
00086         break;
00087 
00088         case token::COMPOUND:
00089             os << *t.compoundTokenPtr_;
00090         break;
00091 
00092         case token::ERROR:
00093             os << "ERROR";
00094             WarningIn("Ostream& operator<<(Ostream&, const token&)")
00095                 << "Error token" << endl;
00096         break;
00097 
00098         default:
00099             os << "UNKNOWN";
00100             SeriousErrorIn("Ostream& operator<<(Ostream&, const token&)")
00101                 << "Unknown token"
00102                 << endl;
00103     }
00104 
00105     // Check state of stream
00106     os.check("Ostream& operator<<(Ostream&, const token&)");
00107 
00108     return os;
00109 }
00110 
00111 
00112 ostream& Foam::operator<<(ostream& os, const token::punctuationToken& pt)
00113 {
00114     return os << char(pt);
00115 }
00116 
00117 
00118 Foam::Ostream& Foam::operator<<(Ostream& os, const token::punctuationToken& pt)
00119 {
00120     return os << char(pt);
00121 }
00122 
00123 
00124 Foam::Ostream& Foam::operator<<(Ostream& os, const token::compound& ct)
00125 {
00126     os << ct.type() << token::SPACE;
00127     ct.write(os);
00128 
00129     return os;
00130 }
00131 
00132 
00133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00134 
00135 ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip)
00136 {
00137     const token& t = ip.t_;
00138 
00139     os  << "on line " << t.lineNumber();
00140 
00141     switch (t.type())
00142     {
00143         case token::UNDEFINED:
00144             os  << " an undefined token";
00145         break;
00146 
00147         case token::PUNCTUATION:
00148             os  << " the punctuation token " << '\'' << t.pToken() << '\'';
00149         break;
00150 
00151         case token::WORD:
00152             os  << " the word " << '\'' << t.wordToken() << '\'';
00153         break;
00154 
00155         case token::STRING:
00156             os  << " the string " << t.stringToken();
00157         break;
00158 
00159         case token::LABEL:
00160             os  << " the label " << t.labelToken();
00161         break;
00162 
00163         case token::FLOAT_SCALAR:
00164             os  << " the floatScalar " << t.floatScalarToken();
00165         break;
00166 
00167         case token::DOUBLE_SCALAR:
00168             os  << " the doubleScalar " << t.doubleScalarToken();
00169         break;
00170 
00171         case token::COMPOUND:
00172         {
00173             if (t.compoundToken().empty())
00174             {
00175                 os  << " the empty compound of type "
00176                     << t.compoundToken().type();
00177             }
00178             else
00179             {
00180                 os  << " the compound of type "
00181                     << t.compoundToken().type();
00182             }
00183         }
00184         break;
00185 
00186         case token::ERROR:
00187             os  << " an error";
00188         break;
00189 
00190         default:
00191             os  << " an unknown token type " << '\'' << int(t.type()) << '\'';
00192     }
00193 
00194     return os;
00195 }
00196 
00197 
00198 // template specialization
00199 namespace Foam
00200 {
00201 
00202 #if defined (__GNUC__)
00203 template<>
00204 #endif
00205 Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip)
00206 {
00207     const token& t = ip.t_;
00208 
00209     os  << "on line " << t.lineNumber();
00210 
00211     switch (t.type())
00212     {
00213         case token::UNDEFINED:
00214             os  << " an undefined token";
00215         break;
00216 
00217         case token::PUNCTUATION:
00218             os  << " the punctuation token " << '\'' << t.pToken() << '\'';
00219         break;
00220 
00221         case token::WORD:
00222             os  << " the word " << '\'' << t.wordToken() << '\'';
00223         break;
00224 
00225         case token::STRING:
00226             os  << " the string " << t.stringToken();
00227         break;
00228 
00229         case token::LABEL:
00230             os  << " the label " << t.labelToken();
00231         break;
00232 
00233         case token::FLOAT_SCALAR:
00234             os  << " the floatScalar " << t.floatScalarToken();
00235         break;
00236 
00237         case token::DOUBLE_SCALAR:
00238             os  << " the doubleScalar " << t.doubleScalarToken();
00239         break;
00240 
00241         case token::COMPOUND:
00242         {
00243             if (t.compoundToken().empty())
00244             {
00245                 os  << " the empty compound of type "
00246                     << t.compoundToken().type();
00247             }
00248             else
00249             {
00250                 os  << " the compound of type "
00251                     << t.compoundToken().type();
00252             }
00253         }
00254         break;
00255 
00256         case token::ERROR:
00257             os  << " an error";
00258         break;
00259 
00260         default:
00261             os  << " an unknown token type "  << '\'' << int(t.type()) << '\'';
00262     }
00263 
00264     return os;
00265 }
00266 
00267 
00268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00269 
00270 } // End namespace Foam
00271 
00272 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines