initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOstreams / Sstreams / state.C
blobcff808bf40e4931760a0fd84ea5f1bcd8fa53f11
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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"
32 #include "token.H"
33 #include "int.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 //  Print state of ostream.
38 void Foam::state(ostream& to, const string& s)
40     state_value osState = state_value(to.rdstate());
42     switch (osState)
43     {
44         case _good:                // Do not anything 'unusual'.
45             break;
47         case _eof:
48             Info
49                 << "Output stream: premature end of stream", s << endl;
50         break;
52         case _fail:
53             SeriousErrorIn("state(ostream& to, const string& s)")
54                 << "Output stream failure (bad format?)", s << endl;
55         break;
57         case (_fail + _eof) :
58          SeriousErrorIn("state(ostream& to, const string& s)")
59              << "Output stream failure and end of stream", s << endl;
60         break;
62         case _bad:
63             SeriousErrorIn("state(ostream& to, const string& s)")
64                 << "Serious output stream failure", s << endl;
65         break;
67         default:
68             SeriousErrorIn("state(ostream& to, const string& s)")
69                 << "Output stream failure of unknown type", s << endl
70                 << "Stream state value = ", osState << endl;
71         break;
72     }
74     return;
78 //  Print state of istream.
79 void Foam::state(istream& from, const string& s)
81     state_value isState = state_value(from.rdstate());
83     switch (isState)
84     {
85         case _good:                // Do not anything 'unusual'.
86             break;
88         case _eof:
89             Info
90                 << "Input stream: premature end of stream", s << endl;
91             Info<< "If all else well, possibly a quote mark missing" << endl;
92         break;
94         case _fail:
95             SeriousErrorIn("state(istream& from, const string& s)")
96                 << "Input stream failure (bad format?)", s << endl;
97             Info<< "If all else well, possibly a quote mark missing" << endl;
98         break;
100         case (_fail + _eof) :
101             SeriousErrorIn("state(istream& from, const string& s)")
102                 << "Input stream failure and end of stream", s << endl;
103             Info<< "If all else well, possibly a quote mark missing" << endl;
104         break;
106         case _bad:
107             SeriousErrorIn("state(istream& from, const string& s)")
108                 << "Serious input stream failure", s << endl;
109         break;
111         default:
112             SeriousErrorIn("state(istream& from, const string& s)")
113                 << "Input stream failure of unknown type", s << endl;
114             SeriousErrorIn("state(istream& from, const string& s)")
115                 << "Stream state value = ", isState << endl;
116         break;
117     }
119     return;
123 // ************************************************************************* //