1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
26 Read token and binary block from ISstream
28 \*---------------------------------------------------------------------------*/
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 Istream& ISstream::read(char& c)
48 Istream& ISstream::read(word& w)
50 static const int MAX_WORD = 1024;
51 static char wordBuffer[MAX_WORD];
57 while (get(c) && word::valid(c))
67 wordBuffer[MAX_WORD-1] = '\0';
70 FatalIOErrorIn("ISstream::read(word&)", *this)
71 << "problem while reading word '" << wordBuffer << '\''
72 << exit(FatalIOError);
79 wordBuffer[MAX_WORD-1] = '\0';
81 FatalIOErrorIn("ISstream::read(word&)", *this)
82 << "word " << wordBuffer << " too long" << endl
83 << " maximum number of characters allowed = " << MAX_WORD
84 << exit(FatalIOError);
89 if (c == token::BEGIN_LIST)
93 else if (c == token::END_LIST)
108 FatalIOErrorIn("ISstream::read(word&)", *this)
109 << "invalid first character found : " << c
110 << exit(FatalIOError);
113 wordBuffer[i] = '\0'; // Terminator.
121 Istream& ISstream::read(string& s)
123 static const int MAX_STR = 1024;
124 static const int MAX_ERROR_STR = 80;
125 static char stringBuffer[MAX_STR];
131 stringBuffer[0] = '\0';
133 FatalIOErrorIn("ISstream::read(string& s)", *this)
134 << "cannot read start of string"
135 << exit(FatalIOError);
140 if (c != token::BEGIN_STRING)
142 stringBuffer[0] = '\0';
144 FatalIOErrorIn("ISstream::read(string& s)", *this)
145 << "Incorrect start of string character"
146 << exit(FatalIOError);
157 if (c == token::END_STRING && !escape)
159 stringBuffer[i] = '\0';
164 if (c == '\n' && !escape)
166 stringBuffer[i] = '\0';
167 stringBuffer[MAX_ERROR_STR] = '\0';
169 FatalIOErrorIn("ISstream::read(string& s)", *this)
170 << "found a '\\n' while reading string \""
171 << stringBuffer << '"'
172 << exit(FatalIOError);
185 stringBuffer[MAX_STR - 1] = '\0';
187 FatalIOErrorIn("ISstream::read(string& s)", *this)
188 << " string " << stringBuffer << "is too long" << endl
189 << " maximum number of characters allowed = " << MAX_STR
190 << exit(FatalIOError);
201 stringBuffer[i] = '\0';
202 stringBuffer[MAX_ERROR_STR] = '\0';
204 FatalIOErrorIn("ISstream::read(string& s)", *this)
205 << "problem while reading string \"" << stringBuffer << "...\""
206 << exit(FatalIOError);
212 Istream& ISstream::read(label& l)
215 setState(is_.rdstate());
220 Istream& ISstream::read(floatScalar& s)
223 setState(is_.rdstate());
228 Istream& ISstream::read(doubleScalar& s)
231 setState(is_.rdstate());
237 Istream& ISstream::read(char* buf, std::streamsize count)
239 if (format() != BINARY)
241 FatalIOErrorIn("ISstream::read(char*, std::streamsize)", *this)
242 << "stream format not binary"
243 << exit(FatalIOError);
246 readBegin("binaryBlock");
247 is_.read(buf, count);
248 readEnd("binaryBlock");
250 setState(is_.rdstate());
256 //- Rewind the ISstream so that it may be read again
257 Istream& ISstream::rewind()
259 stream().rdbuf()->pubseekpos(0);
265 // Set flags of output stream
266 ios_base::fmtflags ISstream::flags() const
272 // Set flags of given field of output stream
273 ios_base::fmtflags ISstream::flags(const ios_base::fmtflags f)
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 } // End namespace Foam
283 // ************************************************************************* //