ITstream.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 "error.H"
27 #include "ITstream.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
32 {
33  os << "ITstream : " << name_.c_str();
34 
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  }
51 
52  IOstream::print(os);
53 }
54 
55 
57 {
58  // Return the put back token if it exists
59  if (Istream::getBack(t))
60  {
61  lineNumber_ = t.lineNumber();
62  return *this;
63  }
64 
65  if (tokenIndex_ < size())
66  {
67  t = operator[](tokenIndex_++);
68  lineNumber_ = t.lineNumber();
69 
70  if (tokenIndex_ == size())
71  {
72  setEof();
73  }
74  }
75  else
76  {
77  if (eof())
78  {
80  (
81  *this
82  ) << "attempt to read beyond EOF"
83  << exit(FatalIOError);
84 
85  setBad();
86  }
87  else
88  {
89  setEof();
90  }
91 
93 
94  if (size())
95  {
96  t.lineNumber() = tokenList::last().lineNumber();
97  }
98  else
99  {
100  t.lineNumber() = lineNumber();
101  }
102  }
103 
104  return *this;
105 }
106 
107 
109 {
111  return *this;
112 }
113 
114 
116 {
118  return *this;
119 }
120 
121 
123 {
125  return *this;
126 }
127 
128 
130 {
132  return *this;
133 }
134 
135 
137 {
139  return *this;
140 }
141 
142 
144 {
146  return *this;
147 }
148 
149 
151 {
153  return *this;
154 }
155 
156 
157 Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
158 {
160  return *this;
161 }
162 
163 
165 {
166  tokenIndex_ = 0;
167 
168  if (size())
169  {
170  lineNumber_ = tokenList::first().lineNumber();
171  }
172 
173  setGood();
174 
175  return *this;
176 }
177 
178 
179 // ************************************************************************* //
label lineNumber_
Definition: IOstream.H:228
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ITstream.C:164
void setGood()
Set stream to be good.
Definition: IOstream.H:254
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:72
label lineNumber() const
Return current stream line number.
Definition: IOstream.H:435
T & first()
Return the first element of the list.
Definition: UListI.H:114
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
reverse_iterator rbegin()
Return reverse_iterator to begin reverse traversing the UList.
Definition: UListI.H:264
void setBad()
Set stream to be bad.
Definition: IOstream.H:484
A class for handling words, derived from string.
Definition: word.H:59
static token undefinedToken
Static undefined token.
Definition: token.H:237
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
label lineNumber() const
Definition: tokenI.H:539
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:336
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
long double longDoubleScalar
Lang double precision floating point scalar type.
void setEof()
Set stream to have reached eof.
Definition: IOstream.H:472
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
bool getBack(token &)
Get the put back token if there is one and return true.
Definition: Istream.C:52
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: ITstream.C:31
T & last()
Return the last element of the list.
Definition: UListI.H:128
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: IOstream.C:126
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
IOerror FatalIOError