OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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