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-2021 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 (non-whitespace) character,
70  //- after skipping any C/C++ comments.
71  char nextValid();
72 
73  //- No copy assignment
74  void operator=(const ISstream&) = delete;
75 
76 
77 public:
78 
79  // Constructors
80 
81  //- Construct wrapper around std::istream, set stream status
82  // Default stream options (ASCII, uncompressed)
83  inline ISstream
84  (
85  std::istream& is,
86  const string& streamName,
87  IOstreamOption streamOpt = IOstreamOption()
88  );
89 
90  //- Construct wrapper around std::istream, set stream status
92  (
93  std::istream& is,
94  const string& streamName,
98  )
99  :
100  ISstream(is, streamName, IOstreamOption(fmt, ver, cmp))
101  {}
102 
103 
104  //- Destructor
105  virtual ~ISstream() = default;
106 
107 
108  // Member Functions
109 
110  // Characteristics
111 
112  //- Return the name of the stream.
113  // Useful for Fstream to return the filename
114  virtual const fileName& name() const
115  {
116  return name_;
117  }
118 
119  //- Return stream name for modification
120  virtual fileName& name()
121  {
122  return name_;
123  }
124 
125  //- Return flags of output stream
126  virtual ios_base::fmtflags flags() const;
127 
128 
129  // Special-purpose Functions
130 
131  //- Discard until end of C-style comment '*/'
132  // \return False if stream exhausted before finding the comment end
133  bool seekCommentEnd_Cstyle();
134 
135  //- Raw, low-level get into a string.
136  //- Continues reading \b after an initial left-brace until it finds
137  //- the matching closing right-brace.
138  // Tracks balanced pairs, trims out leading/trailing whitespace.
139  //
140  // \return False if stream exhausted before finding closing brace
142  (
143  std::string& str,
144  const bool stripComments = true
145  );
146 
147 
148  // Read Functions
149 
150  //- Raw, low-level get character function.
151  inline ISstream& get(char& c);
152 
153  //- Raw, low-level peek function.
154  // Does not remove the character from the stream.
155  // Returns the next character in the stream or EOF if the
156  // end of file is read.
157  inline int peek();
158 
159  //- Raw, low-level getline (until delimiter) into a string.
160  inline ISstream& getLine(std::string& str, char delim = '\n');
161 
162  //- Low-level discard until delimiter
163  // \return the number of characters extracted
164  inline std::streamsize getLine(std::nullptr_t, char delim = '\n');
165 
166  //- Raw, low-level putback character function.
167  inline ISstream& putback(const char c);
168 
169  //- Return next token from stream
170  virtual Istream& read(token& t);
171 
172  //- Read a character
173  virtual Istream& read(char& c);
174 
175  //- Read a word
176  virtual Istream& read(word& str);
177 
178  //- Read a string (including enclosing double-quotes).
179  // Backslashes are retained, except when escaping double-quotes
180  // and an embedded newline character.
181  virtual Istream& read(string& str);
182 
183  //- Read a label
184  virtual Istream& read(label& val);
185 
186  //- Read a floatScalar
187  virtual Istream& read(floatScalar& val);
188 
189  //- Read a doubleScalar
190  virtual Istream& read(doubleScalar& val);
191 
192  //- Read binary block
193  virtual Istream& read(char* buf, std::streamsize count);
194 
195  //- Low-level raw binary read
196  virtual Istream& readRaw(char* data, std::streamsize count);
197 
198  //- Start of low-level raw binary read
199  virtual bool beginRawRead();
200 
201  //- End of low-level raw binary read
202  virtual bool endRawRead();
203 
204  //- Rewind the stream so that it may be read again
205  virtual void rewind();
206 
207 
208  // Stream state functions
209 
210  //- Set stream flags
211  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
212 
213 
214  // STL stream
215 
216  //- Access to underlying std::istream
217  virtual std::istream& stdStream()
218  {
219  return is_;
220  }
221 
222  //- Const access to underlying std::istream
223  virtual const std::istream& stdStream() const
224  {
225  return is_;
226  }
227 
228 
229  // Print
230 
231  //- Print stream description to Ostream
232  virtual void print(Ostream& os) const;
233 };
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #include "ISstreamI.H"
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 #endif
247 
248 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:79
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:65
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:73
Foam::IOstreamOption::IOstreamOption
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Definition: IOstreamOption.H:193
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:165
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:1064
Foam::ISstream::readRaw
virtual Istream & readRaw(char *data, std::streamsize count)
Low-level raw binary read.
Definition: ISstream.C:1030
Foam::ISstream::name
virtual fileName & name()
Return stream name for modification.
Definition: ISstream.H:119
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:1055
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::ISstream::seekCommentEnd_Cstyle
bool seekCommentEnd_Cstyle()
Discard until end of C-style comment '*‍/'.
Definition: ISstream.C:79
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:113
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
os
OBJstream os(runTime.globalPath()/outputName)
Foam::ISstream::stdStream
virtual const std::istream & stdStream() const
Const access to underlying std::istream.
Definition: ISstream.H:222
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:216
Foam::ISstream::continueReadUntilRightBrace
bool continueReadUntilRightBrace(std::string &str, const bool stripComments=true)
Definition: ISstream.C:513
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:1078
Foam::ISstream::read
virtual Istream & read(token &t)
Return next token from stream.
Definition: ISstream.C:530
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:1039
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55