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

state.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 Description
00026     Implementation of parser: test the state of either an istream or an
00027     ostream. Report an error if there is one.
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include "error.H"
00032 #include "token.H"
00033 #include "int.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 //  Print state of ostream.
00037 
00038 void Foam::state(ostream& to, const string& s)
00039 {
00040     state_value osState = state_value(to.rdstate());
00041 
00042     switch (osState)
00043     {
00044         case _good:                // Do not anything 'unusual'.
00045             break;
00046 
00047         case _eof:
00048             Info
00049                 << "Output stream: premature end of stream", s << endl;
00050         break;
00051 
00052         case _fail:
00053             SeriousErrorIn("state(ostream& to, const string& s)")
00054                 << "Output stream failure (bad format?)", s << endl;
00055         break;
00056 
00057         case (_fail + _eof) :
00058          SeriousErrorIn("state(ostream& to, const string& s)")
00059              << "Output stream failure and end of stream", s << endl;
00060         break;
00061 
00062         case _bad:
00063             SeriousErrorIn("state(ostream& to, const string& s)")
00064                 << "Serious output stream failure", s << endl;
00065         break;
00066 
00067         default:
00068             SeriousErrorIn("state(ostream& to, const string& s)")
00069                 << "Output stream failure of unknown type", s << endl
00070                 << "Stream state value = ", osState << endl;
00071         break;
00072     }
00073 
00074     return;
00075 }
00076 
00077 
00078 //  Print state of istream.
00079 void Foam::state(istream& from, const string& s)
00080 {
00081     state_value isState = state_value(from.rdstate());
00082 
00083     switch (isState)
00084     {
00085         case _good:                // Do not anything 'unusual'.
00086             break;
00087 
00088         case _eof:
00089             Info
00090                 << "Input stream: premature end of stream", s << endl;
00091             Info<< "If all else well, possibly a quote mark missing" << endl;
00092         break;
00093 
00094         case _fail:
00095             SeriousErrorIn("state(istream& from, const string& s)")
00096                 << "Input stream failure (bad format?)", s << endl;
00097             Info<< "If all else well, possibly a quote mark missing" << endl;
00098         break;
00099 
00100         case (_fail + _eof) :
00101             SeriousErrorIn("state(istream& from, const string& s)")
00102                 << "Input stream failure and end of stream", s << endl;
00103             Info<< "If all else well, possibly a quote mark missing" << endl;
00104         break;
00105 
00106         case _bad:
00107             SeriousErrorIn("state(istream& from, const string& s)")
00108                 << "Serious input stream failure", s << endl;
00109         break;
00110 
00111         default:
00112             SeriousErrorIn("state(istream& from, const string& s)")
00113                 << "Input stream failure of unknown type", s << endl;
00114             SeriousErrorIn("state(istream& from, const string& s)")
00115                 << "Stream state value = ", isState << endl;
00116         break;
00117     }
00118 
00119     return;
00120 }
00121 
00122 
00123 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd