Istream.H
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-2026 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 Class
25  Foam::Istream
26 
27 Description
28  An Istream is an abstract base class for all input systems
29  (streams, files, token lists etc). The basic operations
30  are construct, close, read token, read primitive and read binary
31  block.
32 
33  In addition, version control and line number counting is incorporated.
34  Usually one would use the read primitive member functions, but if one
35  were reading a stream on unknown data sequence one can read token by
36  token, and then analyse.
37 
38 SourceFiles
39  Istream.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Istream_H
44 #define Istream_H
45 
46 #include "IOstream.H"
47 #include "token.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class Istream Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class Istream
59 :
60  public IOstream
61 {
62  // Private Data
63 
64  //- Has a token been put back on the stream?
65  bool putBack_;
66 
67  //- The last token put back on the stream
68  token putBackToken_;
69 
70  //- The line number of the stream before the last token is put back
71  label putBackLineNumber_;
72 
73 
74 public:
75 
76  // Constructors
77 
78  //- Set stream status
79  Istream
80  (
81  const streamFormat format = ASCII,
84  const bool global = false
85  )
86  :
88  putBack_(false)
89  {}
90 
91 
92  //- Destructor
93  virtual ~Istream()
94  {}
95 
96 
97  // Member Functions
98 
99  // Check
100 
101  //- Return true if next operation might succeed
102  bool good() const
103  {
104  return putBack_ || IOstream::good();
105  }
106 
107  //- Return true if end of input seen
108  bool eof() const
109  {
110  return !putBack_ && IOstream::eof();
111  }
112 
113 
114  // Read functions
115 
116  //- Put back token
117  // Only a single put back is permitted
118  void putBack(const token&);
119 
120  //- Get the put back token if there is one and return true.
121  // Return false if no put back token is available.
122  bool getBack(token&);
123 
124  //- Peek at the put back token and return true if available
125  bool peekBack();
126 
127  //- Peek at the put back token without removing it.
128  // Returns false if no put back token is available and set the
129  // token to undefined.
130  bool peekBack(token&);
131 
132  //- Return next token from stream
133  virtual Istream& read(token&) = 0;
134 
135  //- Read a character
136  virtual Istream& read(char&) = 0;
137 
138  //- Read a word
139  virtual Istream& read(word&) = 0;
140 
141  // Read a string (including enclosing double-quotes)
142  virtual Istream& read(string&) = 0;
143 
144  //- Read an int32_t
145  virtual Istream& read(int32_t&) = 0;
146 
147  //- Read an int64_t
148  virtual Istream& read(int64_t&) = 0;
149 
150  //- Read a uint32_t
151  virtual Istream& read(uint32_t&) = 0;
152 
153  //- Read a uint64_t
154  virtual Istream& read(uint64_t&) = 0;
155 
156  //- Read a floatScalar
157  virtual Istream& read(floatScalar&) = 0;
158 
159  //- Read a doubleScalar
160  virtual Istream& read(doubleScalar&) = 0;
161 
162  //- Read a longDoubleScalar
163  virtual Istream& read(longDoubleScalar&) = 0;
164 
165  //- Read binary block
166  virtual Istream& read(char*, std::streamsize) = 0;
167 
168  //- Rewind and return the stream so that it may be read again
169  virtual Istream& rewind() = 0;
170 
171 
172  // Read List punctuation tokens
173 
174  Istream& readBegin(const char* funcName);
175  Istream& readEnd(const char* funcName);
176  Istream& readEndBegin(const char* funcName);
177 
178  char readBeginList(const char* funcName);
179  char readEndList(const char* funcName);
180 
181 
182  // Member Operators
183 
184  //- Return a non-const reference to const Istream
185  // Needed for read-constructors where the stream argument is temporary:
186  // e.g. thing thisThing(IFstream("thingFileName")());
187  Istream& operator()() const;
188 };
189 
190 
191 // --------------------------------------------------------------------
192 // ------ Manipulators (not taking arguments)
193 // --------------------------------------------------------------------
194 
195 typedef Istream& (*IstreamManip)(Istream&);
196 
197 //- operator>> handling for manipulators without arguments
199 {
200  return f(is);
201 }
202 
203 //- operator>> handling for manipulators without arguments
205 {
206  f(is);
207  return is;
208 }
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #ifdef NoRepository
218  #include "HashTable.C"
219 #endif
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 #endif
224 
225 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:72
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
bool global() const
Return global state.
Definition: IOstream.H:438
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Istream & readEnd(const char *funcName)
Definition: Istream.C:123
Istream & readBegin(const char *funcName)
Definition: Istream.C:106
virtual Istream & rewind()=0
Rewind and return the stream so that it may be read again.
virtual ~Istream()
Destructor.
Definition: Istream.H:92
Istream & operator()() const
Return a non-const reference to const Istream.
Definition: Istream.C:189
char readEndList(const char *funcName)
Definition: Istream.C:168
Istream(const streamFormat format=ASCII, const versionNumber version=currentVersion, const compressionType compression=UNCOMPRESSED, const bool global=false)
Set stream status.
Definition: Istream.H:79
virtual Istream & read(token &)=0
Return next token from stream.
bool peekBack()
Peek at the put back token and return true if available.
Definition: Istream.C:85
bool good() const
Return true if next operation might succeed.
Definition: Istream.H:101
char readBeginList(const char *funcName)
Definition: Istream.C:147
void putBack(const token &)
Put back token.
Definition: Istream.C:30
bool eof() const
Return true if end of input seen.
Definition: Istream.H:107
Istream & readEndBegin(const char *funcName)
Definition: Istream.C:140
bool getBack(token &)
Get the put back token if there is one and return true.
Definition: Istream.C:60
A token holds items read from Istream.
Definition: token.H:74
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
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
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
IOstream &(* IOstreamManip)(IOstream &)
Definition: IOstream.H:570
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
Istream &(* IstreamManip)(Istream &)
Definition: Istream.H:194
long double longDoubleScalar
Lang double precision floating point scalar type.
labelList f(nPoints)