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

Istream.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 \*---------------------------------------------------------------------------*/
00025 
00026 #include "Istream.H"
00027 #include <OpenFOAM/bool.H>
00028 #include <OpenFOAM/token.H>
00029 
00030 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00031 
00032 // Set t to the put back token if there is one and return true,
00033 // otherwise return false
00034 bool Foam::Istream::getBack(token& t)
00035 {
00036     if (bad())
00037     {
00038         FatalIOErrorIn("void Istream::getBack(token&)", *this)
00039             << "Attempt to get back from bad stream"
00040             << exit(FatalIOError);
00041 
00042         return false;
00043     }
00044     else if (putBack_)
00045     {
00046         t = putBackToken_;
00047         putBack_ = false;
00048         return true;
00049     }
00050 
00051     return false;
00052 }
00053 
00054 
00055 // Keep the put back token
00056 void Foam::Istream::putBack(const token& t)
00057 {
00058     if (bad())
00059     {
00060         FatalIOErrorIn("void Istream::putBack(const token&)", *this)
00061             << "Attempt to put back onto bad stream"
00062             << exit(FatalIOError);
00063     }
00064     else if (putBack_)
00065     {
00066         FatalIOErrorIn("void Istream::putBack(const token&)", *this)
00067             << "Attempt to put back another token"
00068             << exit(FatalIOError);
00069     }
00070     else
00071     {
00072         putBackToken_ = t;
00073         putBack_ = true;
00074     }
00075 }
00076 
00077 
00078 // Functions for reading object delimiters ( ... )
00079 
00080 Foam::Istream& Foam::Istream::readBegin(const char* funcName)
00081 {
00082     token delimiter(*this);
00083     if (delimiter != token::BEGIN_LIST)
00084     {
00085         setBad();
00086         FatalIOErrorIn("Istream::readBegin(const char*)", *this)
00087             << "Expected a '" << token::BEGIN_LIST
00088             << "' while reading " << funcName
00089             << ", found " << delimiter.info()
00090             << exit(FatalIOError);
00091     }
00092 
00093     return *this;
00094 }
00095 
00096 
00097 Foam::Istream& Foam::Istream::readEnd(const char* funcName)
00098 {
00099     token delimiter(*this);
00100     if (delimiter != token::END_LIST)
00101     {
00102         setBad();
00103         FatalIOErrorIn("Istream::readEnd(const char*)", *this)
00104             << "Expected a '" << token::END_LIST
00105             << "' while reading " << funcName
00106             << ", found " << delimiter.info()
00107             << exit(FatalIOError);
00108     }
00109 
00110     return *this;
00111 }
00112 
00113 
00114 Foam::Istream& Foam::Istream::readEndBegin(const char* funcName)
00115 {
00116     readEnd(funcName);
00117     return readBegin(funcName);
00118 }
00119 
00120 
00121 // Functions for reading List delimiters ( ... ) or { ... }
00122 
00123 char Foam::Istream::readBeginList(const char* funcName)
00124 {
00125     token delimiter(*this);
00126 
00127     if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK)
00128     {
00129         setBad();
00130         FatalIOErrorIn("Istream::readBeginList(const char*)", *this)
00131             << "Expected a '" << token::BEGIN_LIST
00132             << "' or a '" << token::BEGIN_BLOCK
00133             << "' while reading " << funcName
00134             << ", found " << delimiter.info()
00135             << exit(FatalIOError);
00136 
00137         return '\0';
00138     }
00139 
00140     return delimiter.pToken();
00141 }
00142 
00143 
00144 char Foam::Istream::readEndList(const char* funcName)
00145 {
00146     token delimiter(*this);
00147 
00148     if (delimiter != token::END_LIST && delimiter != token::END_BLOCK)
00149     {
00150         setBad();
00151         FatalIOErrorIn("Istream::readEndList(const char*)", *this)
00152             << "Expected a '" << token::END_LIST
00153             << "' or a '" << token::END_BLOCK
00154             << "' while reading " << funcName
00155             << ", found " << delimiter.info()
00156             << exit(FatalIOError);
00157 
00158         return '\0';
00159     }
00160 
00161     return delimiter.pToken();
00162 }
00163 
00164 
00165 Foam::Istream& Foam::Istream::operator()() const
00166 {
00167     if (!good())
00168     {
00169         check("Istream::operator()");
00170         FatalIOError.exit();
00171     }
00172 
00173     return const_cast<Istream&>(*this);
00174 }
00175 
00176 
00177 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines