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 OpenFOAM Foundation
9  Copyright (C) 2017-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::ISstream
29 
30 Description
31  Generic input stream using a standard (STL) stream.
32 
33 SourceFiles
34  ISstreamI.H
35  ISstream.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef ISstream_H
40 #define ISstream_H
41 
42 #include "Istream.H"
43 #include "fileName.H"
44 #include <limits>
45 #include <iostream>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class ISstream Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class ISstream
57 :
58  public Istream
59 {
60  // Private Data
61 
62  fileName name_;
63 
64  std::istream& is_;
65 
66 
67  // Private Member Functions
68 
69  //- Get the next valid character
70  char nextValid();
71 
72  //- Read a word token
73  void readWordToken(token& t);
74 
75  //- Read a verbatim string (excluding block delimiters).
76  // The leading "#{" has been removed prior to calling,
77  // continues until the closing "#}" has been found.
78  Istream& readVerbatim(std::string& str);
79 
80  //- Read a variable name starting with '$'.
81  // Handles "$var" and "${var}" forms, permits '/' scoping character.
82  Istream& readVariable(std::string& str);
83 
84  //- No copy assignment
85  void operator=(const ISstream&) = delete;
86 
87 
88 public:
89 
90  // Constructors
91 
92  //- Construct wrapper around std::istream, set stream status
93  // Default stream options (ASCII, uncompressed)
94  inline ISstream
95  (
96  std::istream& is,
97  const string& streamName,
98  IOstreamOption streamOpt = IOstreamOption()
99  );
100 
101  //- Construct wrapper around std::istream, set stream status
103  (
104  std::istream& is,
105  const string& streamName,
106  streamFormat fmt,
108  compressionType comp = compressionType::UNCOMPRESSED
109  )
110  :
111  ISstream(is, streamName, IOstreamOption(fmt, comp, ver))
112  {}
113 
114 
115  //- Destructor
116  virtual ~ISstream() = default;
117 
118 
119  // Member Functions
120 
121  // Inquiry
122 
123  //- Return the name of the stream
124  // Useful for Fstream to return the filename
125  virtual const fileName& name() const
126  {
127  return name_;
128  }
129 
130  //- Return non-const access to the name of the stream
131  // Useful to alter the stream name
132  virtual fileName& name()
133  {
134  return name_;
135  }
136 
137  //- Return flags of output stream
138  virtual ios_base::fmtflags flags() const;
139 
140 
141  // Read Functions
142 
143  //- Raw, low-level get character function.
144  inline ISstream& get(char& c);
145 
146  //- Raw, low-level peek function.
147  // Does not remove the character from the stream.
148  // Returns the next character in the stream or EOF if the
149  // end of file is read.
150  inline int peek();
151 
152  //- Raw, low-level getline (until delimiter) into a string.
153  inline ISstream& getLine(std::string& str, char delim = '\n');
154 
155  //- Low-level discard until delimiter
156  // \return the number of characters extracted
157  inline std::streamsize getLine(std::nullptr_t, char delim = '\n');
158 
159  //- Raw, low-level putback character function.
160  inline ISstream& putback(const char c);
161 
162  //- Return next token from stream
163  virtual Istream& read(token& t);
164 
165  //- Read a character
166  virtual Istream& read(char& c);
167 
168  //- Read a word
169  virtual Istream& read(word& str);
170 
171  //- Read a string (including enclosing double-quotes).
172  // Backslashes are retained, except when escaping double-quotes
173  // and an embedded newline character.
174  virtual Istream& read(string& str);
175 
176  //- Read a label
177  virtual Istream& read(label& val);
178 
179  //- Read a floatScalar
180  virtual Istream& read(floatScalar& val);
181 
182  //- Read a doubleScalar
183  virtual Istream& read(doubleScalar& val);
184 
185  //- Read binary block
186  virtual Istream& read(char* buf, std::streamsize count);
187 
188  //- Low-level raw binary read
189  virtual Istream& readRaw(char* data, std::streamsize count);
190 
191  //- Start of low-level raw binary read
192  virtual bool beginRawRead();
193 
194  //- End of low-level raw binary read
195  virtual bool endRawRead();
196 
197  //- Rewind the stream so that it may be read again
198  virtual void rewind();
199 
200 
201  // Stream state functions
202 
203  //- Set stream flags
204  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
205 
206 
207  // STL stream
208 
209  //- Access to underlying std::istream
210  virtual std::istream& stdStream()
211  {
212  return is_;
213  }
214 
215  //- Const access to underlying std::istream
216  virtual const std::istream& stdStream() const
217  {
218  return is_;
219  }
220 
221 
222  // Print
223 
224  //- Print stream description to Ostream
225  virtual void print(Ostream& os) const;
226 };
227 
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 } // End namespace Foam
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #include "ISstreamI.H"
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 #endif
240 
241 // ************************************************************************* //
Foam::ISstream::peek
int peek()
Raw, low-level peek function.
Definition: ISstreamI.H:70
Foam::ISstream::print
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: SstreamsPrint.C:36
Foam::doubleScalar
double doubleScalar
A typedef for double.
Definition: scalarFwd.H:48
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::ISstream::getLine
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:76
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOstreamOption::IOstreamOption
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Definition: IOstreamOption.H:196
Foam::Istream::Istream
Istream(const Istream &)=default
Copy construct.
Foam::floatScalar
float floatScalar
A typedef for float.
Definition: scalarFwd.H:45
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:168
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::ISstream::rewind
virtual void rewind()
Rewind the stream so that it may be read again.
Definition: ISstream.C:874
Foam::ISstream::readRaw
virtual Istream & readRaw(char *data, std::streamsize count)
Low-level raw binary read.
Definition: ISstream.C:840
Foam::ISstream::get
ISstream & get(char &c)
Raw, low-level get character function.
Definition: ISstreamI.H:56
Foam::ISstream::endRawRead
virtual bool endRawRead()
End of low-level raw binary read.
Definition: ISstream.C:865
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
fileName.H
Istream.H
ISstreamI.H
Foam::ISstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: ISstream.H:124
Foam::ISstream::putback
ISstream & putback(const char c)
Raw, low-level putback character function.
Definition: ISstreamI.H:106
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::ISstream::stdStream
virtual const std::istream & stdStream() const
Const access to underlying std::istream.
Definition: ISstream.H:215
Foam::ISstream::ISstream
ISstream(std::istream &is, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct wrapper around std::istream, set stream status.
Definition: ISstreamI.H:32
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ISstream::stdStream
virtual std::istream & stdStream()
Access to underlying std::istream.
Definition: ISstream.H:209
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::ISstream::flags
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ISstream.C:888
Foam::ISstream::read
virtual Istream & read(token &t)
Return next token from stream.
Definition: ISstream.C:158
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:77
Foam::ISstream::~ISstream
virtual ~ISstream()=default
Destructor.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::ISstream::beginRawRead
virtual bool beginRawRead()
Start of low-level raw binary read.
Definition: ISstream.C:849
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55