Loading...
Searching...
No Matches
ISstream.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2012,2024 OpenFOAM Foundation
9 Copyright (C) 2017-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::ISstream
29
30Description
31 Generic input stream using a standard (STL) stream.
32
33SourceFiles
34 ISstreamI.H
35 ISstream.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_ISstream_H
40#define Foam_ISstream_H
41
42#include "Istream.H"
43#include "fileName.H"
44#include <limits>
45#include <iostream>
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
52/*---------------------------------------------------------------------------*\
53 Class ISstream Declaration
54\*---------------------------------------------------------------------------*/
55
56class ISstream
57:
58 public Istream
59{
60 // Private Data
61
62 //- The input stream path
63 fileName name_;
64
65 //- The input stream
66 std::istream& is_;
67
68
69 // Private Member Functions
70
71 //- Get the next valid (non-whitespace) character,
72 //- after skipping any C/C++ comments.
73 char nextValid();
74
75 //- Read into compound token (assumed to be a known type)
76 virtual bool readCompoundToken(token& tok, const word& compoundType);
77
78 //- No copy assignment
79 void operator=(const ISstream&) = delete;
80
81
82public:
83
84 // Constructors
85
86 //- Construct wrapper around std::istream, set stream status
87 // Default stream options (ASCII, uncompressed)
88 inline ISstream
89 (
90 std::istream& is,
91 const string& streamName,
92 IOstreamOption streamOpt = IOstreamOption()
93 );
94
95 //- Construct wrapper around std::istream, set stream status
97 (
98 std::istream& is,
99 const string& streamName,
102 )
103 :
104 ISstream(is, streamName, IOstreamOption(fmt, cmp))
105 {}
107 //- Construct wrapper around std::istream, set stream status
109 (
110 std::istream& is,
111 const string& streamName,
115 )
116 :
117 ISstream(is, streamName, IOstreamOption(fmt, ver, cmp))
118 {}
119
121 //- Destructor
122 virtual ~ISstream() = default;
123
124
125 // Member Functions
126
127 // Characteristics
128
129 //- The name of the input serial stream.
130 //- (eg, the name of the Fstream file name)
131 virtual const fileName& name() const override { return name_; }
132
133 //- The name of the input serial stream, for modification.
134 // Use with caution since some classes (eg, Fstream)
135 // also use this for filesystem information!
136 virtual fileName& name() { return name_; }
137
138
139 // STL stream
140
141 //- Const access to underlying std::istream
142 virtual const std::istream& stdStream() const { return is_; }
143
144 //- Access to underlying std::istream
145 virtual std::istream& stdStream() { return is_; }
146
148 // Stream State
149
150 //- Return current stream flags
151 virtual std::ios_base::fmtflags flags() const override
152 {
153 return is_.flags();
154 }
156 //- Set stream flags, return old stream flags
157 virtual std::ios_base::fmtflags flags
158 (
159 std::ios_base::fmtflags f
160 ) override
161 {
162 return is_.flags(f);
164
165 //- Set stream state to match that of the std::istream
166 void syncState()
167 {
168 setState(is_.rdstate());
169 }
170
171
172 // Special-purpose Functions
173
174 //- Discard until end of C-style comment '*/'
175 // \return False if stream exhausted before finding the comment end
177
178 //- Raw, low-level get into a string.
179 //- Continues reading \b after an initial left-brace until it finds
180 //- the matching closing right-brace.
181 // Tracks balanced pairs, trims out leading/trailing whitespace.
182 //
183 // \return False if stream exhausted before finding closing brace
185 (
186 std::string& str,
187 const bool stripComments = true
188 );
189
190
191 // Serial-stream functions
192
193 //- Raw, low-level get character function.
194 inline ISstream& get(char& c);
196 //- Raw, low-level peek function.
197 // Does not remove the character from the stream.
198 // Returns the next character in the stream or EOF if the
199 // end of file is read.
200 inline int peek();
201
202 //- Raw, low-level getline (until delimiter) into a string.
203 inline ISstream& getLine(std::string& str, char delim = '\n');
204
205 //- Low-level discard until delimiter
206 // \return the number of characters extracted
207 inline std::streamsize getLine(std::nullptr_t, char delim = '\n');
208
209 //- Raw, low-level putback character function.
210 inline ISstream& putback(const char c);
211
212
213 // Read Functions
214
215 //- Return next token from stream
216 virtual Istream& read(token& t) override;
217
218 //- Read a character
219 virtual Istream& read(char& c) override;
220
221 //- Read a word
222 virtual Istream& read(word& str) override;
223
224 //- Read a string (including enclosing double-quotes).
225 // Backslashes are retained, except when escaping double-quotes
226 // and an embedded newline character.
227 virtual Istream& read(string& str) override;
228
229 //- Read int32_t
230 virtual Istream& read(int32_t& val) override;
231
232 //- Read int64_t
233 virtual Istream& read(int64_t& val) override;
234
235 //- Read uint32_t
236 virtual Istream& read(uint32_t& val) override;
237
238 //- Read uint64_t
239 virtual Istream& read(uint64_t& val) override;
240
241 //- Read a float
242 virtual Istream& read(float& val) override;
243
244 //- Read a double
245 virtual Istream& read(double& val) override;
246
247 //- Read binary block (with any possible block delimiters).
248 //- Reading into a null pointer behaves like a forward seek of
249 //- count characters.
250 virtual Istream& read(char* data, std::streamsize count) override;
251
252 //- Low-level raw binary read (without possible block delimiters).
253 //- Reading into a null pointer behaves like a forward seek of
254 //- count characters.
255 virtual Istream& readRaw
256 (
257 char* data,
258 std::streamsize count
259 ) override;
260
261 //- Start of low-level raw binary read
262 virtual bool beginRawRead() override;
263
264 //- End of low-level raw binary read
265 virtual bool endRawRead() override;
266
267 //- Rewind the stream so that it may be read again
268 virtual void rewind() override;
269
270
271 // Print
272
273 //- Print stream description to Ostream
274 virtual void print(Ostream& os) const override;
275};
276
277
278// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279
280} // End namespace Foam
281
282// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283
284#include "ISstreamI.H"
285
286// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287
288#endif
289
290// ************************************************************************* //
label n
Representation of a major/minor version number.
A simple container for options an IOstream can normally have.
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Default construct (ASCII, UNCOMPRESSED, currentVersion) or construct with format, compression.
streamFormat
Data format (ascii | binary | coherent).
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED).
@ UNCOMPRESSED
compression = false
void setState(std::ios_base::iostate state) noexcept
Set stream state.
Definition IOstream.H:166
virtual const fileName & name() const override
The name of the input serial stream. (eg, the name of the Fstream file name).
Definition ISstream.H:147
virtual std::ios_base::fmtflags flags() const override
Return current stream flags.
Definition ISstream.H:176
ISstream & get(char &c)
Raw, low-level get character function.
Definition ISstreamI.H:49
virtual fileName & name()
The name of the input serial stream, for modification.
Definition ISstream.H:155
virtual void rewind() override
Rewind the stream so that it may be read again.
Definition ISstream.C:1170
virtual std::ios_base::fmtflags flags(std::ios_base::fmtflags f) override
Set stream flags, return old stream flags.
Definition ISstream.H:185
virtual std::istream & stdStream()
Access to underlying std::istream.
Definition ISstream.H:168
ISstream & putback(const char c)
Raw, low-level putback character function.
Definition ISstreamI.H:99
virtual bool endRawRead() override
End of low-level raw binary read.
Definition ISstream.C:1162
virtual void print(Ostream &os) const override
Print stream description to Ostream.
ISstream(std::istream &is, const string &streamName, IOstreamOption::streamFormat fmt, IOstreamOption::versionNumber ver, IOstreamOption::compressionType cmp=IOstreamOption::UNCOMPRESSED)
Construct wrapper around std::istream, set stream status.
Definition ISstream.H:121
virtual ~ISstream()=default
Destructor.
int peek()
Raw, low-level peek function.
Definition ISstreamI.H:63
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition ISstreamI.H:69
void syncState()
Set stream state to match that of the std::istream.
Definition ISstream.H:195
virtual bool beginRawRead() override
Start of low-level raw binary read.
Definition ISstream.C:1147
**return False if stream exhausted before finding the comment end *bool seekCommentEnd_Cstyle()
Discard until end of C-style comment '.
Definition ISstream.C:84
ISstream(std::istream &is, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct wrapper around std::istream, set stream status.
Definition ISstreamI.H:25
virtual Istream & read(token &t) override
Return next token from stream.
Definition ISstream.C:535
bool continueReadUntilRightBrace(std::string &str, const bool stripComments=true)
Raw, low-level get into a string. Continues reading after an initial left-brace until it finds the ma...
Definition ISstream.C:518
virtual Istream & readRaw(char *data, std::streamsize count) override
Low-level raw binary read (without possible block delimiters). Reading into a null pointer behaves li...
Definition ISstream.C:1129
ISstream(std::istream &is, const string &streamName, IOstreamOption::streamFormat fmt, IOstreamOption::compressionType cmp=IOstreamOption::UNCOMPRESSED)
Construct wrapper around std::istream, set stream status.
Definition ISstream.H:107
virtual const std::istream & stdStream() const
Const access to underlying std::istream.
Definition ISstream.H:163
Istream(const Istream &)=default
Copy construct.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A class for handling file names.
Definition fileName.H:75
A token holds an item read from Istream.
Definition token.H:70
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
labelList f(nPoints)