ITstream.C
Go to the documentation of this file.
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.
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  "ITstream::read(token&)",
82  *this
83  ) << "attempt to read beyond EOF"
84  << exit(FatalIOError);
85 
86  setBad();
87  }
88  else
89  {
90  setEof();
91  }
92 
94 
95  if (size())
96  {
97  t.lineNumber() = tokenList::last().lineNumber();
98  }
99  else
100  {
101  t.lineNumber() = lineNumber();
102  }
103  }
104 
105  return *this;
106 }
107 
108 
110 {
111  notImplemented("Istream& ITstream::read(char&)");
112  return *this;
113 }
114 
115 
117 {
118  notImplemented("Istream& ITstream::read(word&)");
119  return *this;
120 }
121 
122 
124 {
125  notImplemented("Istream& ITstream::read(string&)");
126  return *this;
127 }
128 
129 
131 {
132  notImplemented("Istream& ITstream::read(label&)");
133  return *this;
134 }
135 
136 
138 {
139  notImplemented("Istream& ITstream::read(floatScalar&)");
140  return *this;
141 }
142 
143 
145 {
146  notImplemented("Istream& ITstream::read(doubleScalar&)");
147  return *this;
148 }
149 
150 
151 Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
152 {
153  notImplemented("Istream& ITstream::read(char*, std::streamsize)");
154  return *this;
155 }
156 
157 
159 {
160  tokenIndex_ = 0;
161 
162  if (size())
163  {
164  lineNumber_ = tokenList::first().lineNumber();
165  }
166 
167  setGood();
168 
169  return *this;
170 }
171 
172 
173 // ************************************************************************* //
void setEof()
Set stream to have reached eof.
Definition: IOstream.H:475
static token undefinedToken
Static undefined token.
Definition: token.H:241
label lineNumber_
Definition: IOstream.H:231
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:49
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ITstream.C:158
T & last()
Return the last element of the list.
Definition: UListI.H:131
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
bool getBack(token &)
Get the put back token if there is one and return true.
Definition: Istream.C:52
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
T & first()
Return the first element of the list.
Definition: UListI.H:117
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
T & operator[](const label)
Return element of UList.
Definition: UListI.H:163
IOerror FatalIOError
label lineNumber() const
Definition: tokenI.H:381
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: IOstream.C:130
A token holds items read from Istream.
Definition: token.H:67
reverse_iterator rbegin()
Return reverse_iterator to begin reverse traversing the UList.
Definition: UListI.H:258
label lineNumber() const
Return current stream line number.
Definition: IOstream.H:438
void setBad()
Set stream to be bad.
Definition: IOstream.H:487
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: ITstream.C:31
label size() const
Return the number of elements in the UList.
Definition: ListI.H:83
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:49
#define notImplemented(functionName)
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:356
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
void setGood()
Set stream to be good.
Definition: IOstream.H:257