initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOstreams / Tstreams / ITstream.C
blobca11e5e2b9947bb93e768992b5cb2657670c900e
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 "error.H"
28 #include "ITstream.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 void Foam::ITstream::print(Ostream& os) const
34     os  << "ITstream : " << name_.c_str();
36     if (size())
37     {
38         if (begin()->lineNumber() == rbegin()->lineNumber())
39         {
40             os  << ", line " << begin()->lineNumber() << ", ";
41         }
42         else
43         {
44             os  << ", lines " << begin()->lineNumber()
45                 << '-' << rbegin()->lineNumber() << ", ";
46         }
47     }
48     else
49     {
50         os  << ", line " << lineNumber() << ", ";
51     }
53     IOstream::print(os);
57 Foam::Istream& Foam::ITstream::read(token& t)
59     // Return the put back token if it exists
60     if (Istream::getBack(t))
61     {
62         lineNumber_ = t.lineNumber();
63         return *this;
64     }
66     if (tokenIndex_ < size())
67     {
68         t = operator[](tokenIndex_++);
69         lineNumber_ = t.lineNumber();
71         if (tokenIndex_ == size())
72         {
73             setEof();
74         }
75     }
76     else
77     {
78         if (eof())
79         {
80             FatalIOErrorIn
81             (
82                 "ITstream::read(token& t)",
83                 *this
84             )   << "attempt to read beyond EOF"
85                 << exit(FatalIOError);
87             setBad();
88         }
89         else
90         {
91             setEof();
92         }
94         if (size())
95         {
96             token::undefinedToken.lineNumber()
97                 = operator[](size() - 1).lineNumber();
98         }
99         else
100         {
101             token::undefinedToken.lineNumber() = lineNumber();
102         }
104         t = token::undefinedToken;
105     }
107     return *this;
111 Foam::Istream& Foam::ITstream::read(char&)
113     notImplemented("Istream& ITstream::read(char& c)");
114     return *this;
118 Foam::Istream& Foam::ITstream::read(word&)
120     notImplemented("Istream& ITstream::read(word&)");
121     return *this;
125 Foam::Istream& Foam::ITstream::read(string&)
127     notImplemented("Istream& ITstream::read(string&)");
128     return *this;
132 Foam::Istream& Foam::ITstream::read(label&)
134     notImplemented("Istream& ITstream::read(label&)");
135     return *this;
139 Foam::Istream& Foam::ITstream::read(floatScalar&)
141     notImplemented("Istream& ITstream::read(floatScalar&)");
142     return *this;
146 Foam::Istream& Foam::ITstream::read(doubleScalar&)
148     notImplemented("Istream& ITstream::read(doubleScalar&)");
149     return *this;
153 Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
155     notImplemented("Istream& ITstream::read(char*, std::streamsize)");
156     return *this;
160 // Rewind the token stream so that it may be read again
161 Foam::Istream& Foam::ITstream::rewind()
163     tokenIndex_ = 0;
165     if (size())
166     {
167         lineNumber_ = operator[](0).lineNumber();
168     }
170     setGood();
172     return *this;
176 // ************************************************************************* //