initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / db / IOstreams / Sstreams / state.C
blob8f1b3df7400fab47a4370643e2a57dbde4772d4d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Implementation of parser: test the state of either an istream or an
27     ostream. Report an error if there is one.
29 \*---------------------------------------------------------------------------*/
31 #include "error.H"
33 #include "token.H"
34 #include "int.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 //  Print state of ostream.
44 void state(ostream& to, const string& s)
46     state_value osState = state_value(to.rdstate());
48     switch (osState)
49     {
50         case _good:                // Do not anything 'unusual'.
51             break;
53         case _eof:
54             Info
55                 << "Output stream: premature end of stream", s << endl;
56         break;
58         case _fail:
59             SeriousErrorIn("state(ostream& to, const string& s)")
60                 << "Output stream failure (bad format?)", s << endl;
61         break;
63         case (_fail + _eof) :
64          SeriousErrorIn("state(ostream& to, const string& s)")
65              << "Output stream failure and end of stream", s << endl;
66         break;
68         case _bad:
69             SeriousErrorIn("state(ostream& to, const string& s)")
70                 << "Serious output stream failure", s << endl;
71         break;
73         default:
74             SeriousErrorIn("state(ostream& to, const string& s)")
75                 << "Output stream failure of unknown type", s << endl
76                 << "Stream state value = ", osState << endl;
77         break;
78     }
80     return;
84 //  Print state of istream.
85 void state(istream& from, const string& s)
87     state_value isState = state_value(from.rdstate());
89     switch (isState)
90     {
91         case _good:                // Do not anything 'unusual'.
92             break;
94         case _eof:
95             Info
96                 << "Input stream: premature end of stream", s << endl;
97             Info<< "If all else well, possibly a quote mark missing" << endl;
98         break;
100         case _fail:
101             SeriousErrorIn("state(istream& from, const string& s)")
102                 << "Input stream failure (bad format?)", s << endl;
103             Info<< "If all else well, possibly a quote mark missing" << endl;
104         break;
106         case (_fail + _eof) :
107             SeriousErrorIn("state(istream& from, const string& s)")
108                 << "Input stream failure and end of stream", s << endl;
109             Info<< "If all else well, possibly a quote mark missing" << endl;
110         break;
112         case _bad:
113             SeriousErrorIn("state(istream& from, const string& s)")
114                 << "Serious input stream failure", s << endl;
115         break;
117         default:
118             SeriousErrorIn("state(istream& from, const string& s)")
119                 << "Input stream failure of unknown type", s << endl;
120             SeriousErrorIn("state(istream& from, const string& s)")
121                 << "Stream state value = ", isState << endl;
122         break;
123     }
125     return;
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 } // End namespace Foam
133 // ************************************************************************* //