Transferred copyright to the OpenFOAM Foundation
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / IOstreams / Tstreams / ITstream.C
blob49a278e588c7ade4ae11dc0a81ff77d19f752599
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "error.H"
27 #include "ITstream.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 void Foam::ITstream::print(Ostream& os) const
33     os  << "ITstream : " << name_.c_str();
35     if (size())
36     {
37         if (begin()->lineNumber() == rbegin()->lineNumber())
38         {
39             os  << ", line " << begin()->lineNumber() << ", ";
40         }
41         else
42         {
43             os  << ", lines " << begin()->lineNumber()
44                 << '-' << rbegin()->lineNumber() << ", ";
45         }
46     }
47     else
48     {
49         os  << ", line " << lineNumber() << ", ";
50     }
52     IOstream::print(os);
56 Foam::Istream& Foam::ITstream::read(token& t)
58     // Return the put back token if it exists
59     if (Istream::getBack(t))
60     {
61         lineNumber_ = t.lineNumber();
62         return *this;
63     }
65     if (tokenIndex_ < size())
66     {
67         t = operator[](tokenIndex_++);
68         lineNumber_ = t.lineNumber();
70         if (tokenIndex_ == size())
71         {
72             setEof();
73         }
74     }
75     else
76     {
77         if (eof())
78         {
79             FatalIOErrorIn
80             (
81                 "ITstream::read(token&)",
82                 *this
83             )   << "attempt to read beyond EOF"
84                 << exit(FatalIOError);
86             setBad();
87         }
88         else
89         {
90             setEof();
91         }
93         t = token::undefinedToken;
95         if (size())
96         {
97             t.lineNumber() = tokenList::last().lineNumber();
98         }
99         else
100         {
101             t.lineNumber() = lineNumber();
102         }
103     }
105     return *this;
109 Foam::Istream& Foam::ITstream::read(char&)
111     notImplemented("Istream& ITstream::read(char&)");
112     return *this;
116 Foam::Istream& Foam::ITstream::read(word&)
118     notImplemented("Istream& ITstream::read(word&)");
119     return *this;
123 Foam::Istream& Foam::ITstream::read(string&)
125     notImplemented("Istream& ITstream::read(string&)");
126     return *this;
130 Foam::Istream& Foam::ITstream::read(label&)
132     notImplemented("Istream& ITstream::read(label&)");
133     return *this;
137 Foam::Istream& Foam::ITstream::read(floatScalar&)
139     notImplemented("Istream& ITstream::read(floatScalar&)");
140     return *this;
144 Foam::Istream& Foam::ITstream::read(doubleScalar&)
146     notImplemented("Istream& ITstream::read(doubleScalar&)");
147     return *this;
151 Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
153     notImplemented("Istream& ITstream::read(char*, std::streamsize)");
154     return *this;
158 Foam::Istream& Foam::ITstream::rewind()
160     tokenIndex_ = 0;
162     if (size())
163     {
164         lineNumber_ = tokenList::first().lineNumber();
165     }
167     setGood();
169     return *this;
173 // ************************************************************************* //