FreeFOAM The Cross-Platform CFD Toolkit
Istream.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 \*---------------------------------------------------------------------------*/
25 
26 #include "Istream.H"
27 #include <OpenFOAM/bool.H>
28 #include <OpenFOAM/token.H>
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 // Set t to the put back token if there is one and return true,
33 // otherwise return false
35 {
36  if (bad())
37  {
38  FatalIOErrorIn("void Istream::getBack(token&)", *this)
39  << "Attempt to get back from bad stream"
40  << exit(FatalIOError);
41 
42  return false;
43  }
44  else if (putBack_)
45  {
46  t = putBackToken_;
47  putBack_ = false;
48  return true;
49  }
50 
51  return false;
52 }
53 
54 
55 // Keep the put back token
57 {
58  if (bad())
59  {
60  FatalIOErrorIn("void Istream::putBack(const token&)", *this)
61  << "Attempt to put back onto bad stream"
62  << exit(FatalIOError);
63  }
64  else if (putBack_)
65  {
66  FatalIOErrorIn("void Istream::putBack(const token&)", *this)
67  << "Attempt to put back another token"
68  << exit(FatalIOError);
69  }
70  else
71  {
72  putBackToken_ = t;
73  putBack_ = true;
74  }
75 }
76 
77 
78 // Functions for reading object delimiters ( ... )
79 
81 {
82  token delimiter(*this);
83  if (delimiter != token::BEGIN_LIST)
84  {
85  setBad();
86  FatalIOErrorIn("Istream::readBegin(const char*)", *this)
87  << "Expected a '" << token::BEGIN_LIST
88  << "' while reading " << funcName
89  << ", found " << delimiter.info()
90  << exit(FatalIOError);
91  }
92 
93  return *this;
94 }
95 
96 
97 Foam::Istream& Foam::Istream::readEnd(const char* funcName)
98 {
99  token delimiter(*this);
100  if (delimiter != token::END_LIST)
101  {
102  setBad();
103  FatalIOErrorIn("Istream::readEnd(const char*)", *this)
104  << "Expected a '" << token::END_LIST
105  << "' while reading " << funcName
106  << ", found " << delimiter.info()
107  << exit(FatalIOError);
108  }
109 
110  return *this;
111 }
112 
113 
115 {
116  readEnd(funcName);
117  return readBegin(funcName);
118 }
119 
120 
121 // Functions for reading List delimiters ( ... ) or { ... }
122 
123 char Foam::Istream::readBeginList(const char* funcName)
124 {
125  token delimiter(*this);
126 
127  if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK)
128  {
129  setBad();
130  FatalIOErrorIn("Istream::readBeginList(const char*)", *this)
131  << "Expected a '" << token::BEGIN_LIST
132  << "' or a '" << token::BEGIN_BLOCK
133  << "' while reading " << funcName
134  << ", found " << delimiter.info()
135  << exit(FatalIOError);
136 
137  return '\0';
138  }
139 
140  return delimiter.pToken();
141 }
142 
143 
144 char Foam::Istream::readEndList(const char* funcName)
145 {
146  token delimiter(*this);
147 
148  if (delimiter != token::END_LIST && delimiter != token::END_BLOCK)
149  {
150  setBad();
151  FatalIOErrorIn("Istream::readEndList(const char*)", *this)
152  << "Expected a '" << token::END_LIST
153  << "' or a '" << token::END_BLOCK
154  << "' while reading " << funcName
155  << ", found " << delimiter.info()
156  << exit(FatalIOError);
157 
158  return '\0';
159  }
160 
161  return delimiter.pToken();
162 }
163 
164 
166 {
167  if (!good())
168  {
169  check("Istream::operator()");
170  FatalIOError.exit();
171  }
172 
173  return const_cast<Istream&>(*this);
174 }
175 
176 
177 // ************************ vim: set sw=4 sts=4 et: ************************ //