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

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