FreeFOAM The Cross-Platform CFD Toolkit
state.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Implementation of parser: test the state of either an istream or an
26  ostream. Report an error if there is one.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include <OpenFOAM/error.H>
31 #include <OpenFOAM/token.H>
32 #include <OpenFOAM/int.H>
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // Print state of ostream.
36 
37 void Foam::state(ostream& to, const string& s)
38 {
39  state_value osState = state_value(to.rdstate());
40 
41  switch (osState)
42  {
43  case _good: // Do not anything 'unusual'.
44  break;
45 
46  case _eof:
47  Info
48  << "Output stream: premature end of stream", s << endl;
49  break;
50 
51  case _fail:
52  SeriousErrorIn("state(ostream& to, const string& s)")
53  << "Output stream failure (bad format?)", s << endl;
54  break;
55 
56  case (_fail + _eof) :
57  SeriousErrorIn("state(ostream& to, const string& s)")
58  << "Output stream failure and end of stream", s << endl;
59  break;
60 
61  case _bad:
62  SeriousErrorIn("state(ostream& to, const string& s)")
63  << "Serious output stream failure", s << endl;
64  break;
65 
66  default:
67  SeriousErrorIn("state(ostream& to, const string& s)")
68  << "Output stream failure of unknown type", s << endl
69  << "Stream state value = ", osState << endl;
70  break;
71  }
72 
73  return;
74 }
75 
76 
77 // Print state of istream.
78 void Foam::state(istream& from, const string& s)
79 {
80  state_value isState = state_value(from.rdstate());
81 
82  switch (isState)
83  {
84  case _good: // Do not anything 'unusual'.
85  break;
86 
87  case _eof:
88  Info
89  << "Input stream: premature end of stream", s << endl;
90  Info<< "If all else well, possibly a quote mark missing" << endl;
91  break;
92 
93  case _fail:
94  SeriousErrorIn("state(istream& from, const string& s)")
95  << "Input stream failure (bad format?)", s << endl;
96  Info<< "If all else well, possibly a quote mark missing" << endl;
97  break;
98 
99  case (_fail + _eof) :
100  SeriousErrorIn("state(istream& from, const string& s)")
101  << "Input stream failure and end of stream", s << endl;
102  Info<< "If all else well, possibly a quote mark missing" << endl;
103  break;
104 
105  case _bad:
106  SeriousErrorIn("state(istream& from, const string& s)")
107  << "Serious input stream failure", s << endl;
108  break;
109 
110  default:
111  SeriousErrorIn("state(istream& from, const string& s)")
112  << "Input stream failure of unknown type", s << endl;
113  SeriousErrorIn("state(istream& from, const string& s)")
114  << "Stream state value = ", isState << endl;
115  break;
116  }
117 
118  return;
119 }
120 
121 
122 // ************************ vim: set sw=4 sts=4 et: ************************ //