initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOstreams / IOstreams / Istream.C
blob4717894b792b16e209feb83e304499d6ba4f0d0c
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 \*---------------------------------------------------------------------------*/
27 #include "Istream.H"
28 #include "bool.H"
29 #include "token.H"
31 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
33 // Set t to the put back token if there is one and return true,
34 // otherwise return false
35 bool Foam::Istream::getBack(token& t)
37     if (bad())
38     {
39         FatalIOErrorIn("void Istream::getBack(token&)", *this)
40             << "Attempt to get back from bad stream"
41             << exit(FatalIOError);
43         return false;
44     }
45     else if (putBack_)
46     {
47         t = putBackToken_;
48         putBack_ = false;
49         return true;
50     }
52     return false;
56 // Keep the put back token
57 void Foam::Istream::putBack(const token& t)
59     if (bad())
60     {
61         FatalIOErrorIn("void Istream::putBack(const token&)", *this)
62             << "Attempt to put back onto bad stream"
63             << exit(FatalIOError);
64     }
65     else if (putBack_)
66     {
67         FatalIOErrorIn("void Istream::putBack(const token&)", *this)
68             << "Attempt to put back another token"
69             << exit(FatalIOError);
70     }
71     else
72     {
73         putBackToken_ = t;
74         putBack_ = true;
75     }
79 // Functions for reading object delimiters ( ... )
81 Foam::Istream& Foam::Istream::readBegin(const char* funcName)
83     token delimiter(*this);
84     if (delimiter != token::BEGIN_LIST)
85     {
86         setBad();
87         FatalIOErrorIn("Istream::readBegin(const char*)", *this)
88             << "Expected a '" << token::BEGIN_LIST
89             << "' while reading " << funcName
90             << ", found " << delimiter.info()
91             << exit(FatalIOError);
92     }
94     return *this;
98 Foam::Istream& Foam::Istream::readEnd(const char* funcName)
100     token delimiter(*this);
101     if (delimiter != token::END_LIST)
102     {
103         setBad();
104         FatalIOErrorIn("Istream::readEnd(const char*)", *this)
105             << "Expected a '" << token::END_LIST
106             << "' while reading " << funcName
107             << ", found " << delimiter.info()
108             << exit(FatalIOError);
109     }
111     return *this;
115 Foam::Istream& Foam::Istream::readEndBegin(const char* funcName)
117     readEnd(funcName);
118     return readBegin(funcName);
122 // Functions for reading List delimiters ( ... ) or { ... }
124 char Foam::Istream::readBeginList(const char* funcName)
126     token delimiter(*this);
128     if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK)
129     {
130         setBad();
131         FatalIOErrorIn("Istream::readBeginList(const char*)", *this)
132             << "Expected a '" << token::BEGIN_LIST
133             << "' or a '" << token::BEGIN_BLOCK
134             << "' while reading " << funcName
135             << ", found " << delimiter.info()
136             << exit(FatalIOError);
138         return '\0';
139     }
141     return delimiter.pToken();
145 char Foam::Istream::readEndList(const char* funcName)
147     token delimiter(*this);
149     if (delimiter != token::END_LIST && delimiter != token::END_BLOCK)
150     {
151         setBad();
152         FatalIOErrorIn("Istream::readEndList(const char*)", *this)
153             << "Expected a '" << token::END_LIST
154             << "' or a '" << token::END_BLOCK
155             << "' while reading " << funcName
156             << ", found " << delimiter.info()
157             << exit(FatalIOError);
159         return '\0';
160     }
162     return delimiter.pToken();
166 Foam::Istream& Foam::Istream::operator()() const
168     if (!good())
169     {
170         check("Istream::operator()");
171         FatalIOError.exit();
172     }
174     return const_cast<Istream&>(*this);
178 // ************************************************************************* //