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-2019 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 standard (STL) streams.
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 <iostream>
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class ISstream Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class ISstream
56 :
57  public Istream
58 {
59  // Private Data
60 
61  fileName name_;
62 
63  std::istream& is_;
64 
65 
66  // Private Member Functions
67 
68  //- Get the next valid character
69  char nextValid();
70 
71  //- Get a word token
72  void readWordToken(token& t);
73 
74  //- Read a verbatim string (excluding block delimiters).
75  // The leading "#{" has been removed prior to calling,
76  // continues until the closing "#}" has been found.
77  Istream& readVerbatim(std::string& str);
78 
79  //- Read a variable name starting with '$'.
80  // Handles "$var" and "${var}" forms, permits '/' scoping character.
81  Istream& readVariable(std::string& str);
82 
83  //- No copy assignment
84  void operator=(const ISstream&) = delete;
85 
86 
87 public:
88 
89  // Constructors
90 
91  //- Construct as wrapper around std::istream
92  inline ISstream
93  (
94  std::istream& is,
95  const string& name,
99  );
100 
101 
102  //- Destructor
103  virtual ~ISstream() = default;
104 
105 
106  // Member Functions
107 
108  // Inquiry
109 
110  //- Return the name of the stream
111  // Useful for Fstream to return the filename
112  virtual const fileName& name() const
113  {
114  return name_;
115  }
116 
117  //- Return non-const access to the name of the stream
118  // Useful to alter the stream name
119  virtual fileName& name()
120  {
121  return name_;
122  }
123 
124  //- Return flags of output stream
125  virtual ios_base::fmtflags flags() const;
126 
127 
128  // Read Functions
129 
130  //- Raw, low-level get character function.
131  inline ISstream& get(char& c);
132 
133  //- Raw, low-level peek function.
134  // Does not remove the character from the stream.
135  // Returns the next character in the stream or EOF if the
136  // end of file is read.
137  inline int peek();
138 
139  //- Raw, low-level getline into a string function.
140  inline ISstream& getLine(std::string& str, char delim = '\n');
141 
142  //- Raw, low-level putback character function.
143  inline ISstream& putback(const char c);
144 
145  //- Return next token from stream
146  virtual Istream& read(token& t);
147 
148  //- Read a character
149  virtual Istream& read(char& c);
150 
151  //- Read a word
152  virtual Istream& read(word& str);
153 
154  //- Read a string (including enclosing double-quotes).
155  // Backslashes are retained, except when escaping double-quotes
156  // and an embedded newline character.
157  virtual Istream& read(string& str);
158 
159  //- Read a label
160  virtual Istream& read(label& val);
161 
162  //- Read a floatScalar
163  virtual Istream& read(floatScalar& val);
164 
165  //- Read a doubleScalar
166  virtual Istream& read(doubleScalar& val);
167 
168  //- Read binary block
169  virtual Istream& read(char* buf, std::streamsize count);
170 
171  //- Low-level raw binary read
172  virtual Istream& readRaw(char* data, std::streamsize count);
173 
174  //- Start of low-level raw binary read
175  virtual bool beginRawRead();
176 
177  //- End of low-level raw binary read
178  virtual bool endRawRead();
179 
180  //- Rewind the stream so that it may be read again
181  virtual void rewind();
182 
183 
184  // Stream state functions
185 
186  //- Set stream flags
187  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
188 
189 
190  // STL stream
191 
192  //- Access to underlying std::istream
193  virtual std::istream& stdStream()
194  {
195  return is_;
196  }
197 
198  //- Const access to underlying std::istream
199  virtual const std::istream& stdStream() const
200  {
201  return is_;
202  }
203 
204 
205  // Print
206 
207  //- Print description of IOstream to Ostream
208  virtual void print(Ostream& os) const;
209 };
210 
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 } // End namespace Foam
215 
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 
218 #include "ISstreamI.H"
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 #endif
223 
224 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:73
Foam::ISstream::peek
int peek()
Raw, low-level peek function.
Definition: ISstreamI.H:72
Foam::ISstream::print
virtual void print(Ostream &os) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:36
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::doubleScalar
double doubleScalar
Floating-point double precision scalar type.
Definition: doubleScalar.H:52
Foam::ISstream::ISstream
ISstream(std::istream &is, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct as wrapper around std::istream.
Definition: ISstreamI.H:32
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 into a string function.
Definition: ISstreamI.H:78
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::floatScalar
float floatScalar
Floating-point single precision scalar type.
Definition: floatScalar.H:52
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:273
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::ISstream
Generic input stream using standard (STL) streams.
Definition: ISstream.H:54
Foam::token
A token holds an item read from Istream.
Definition: token.H:69
Foam::ISstream::rewind
virtual void rewind()
Rewind the stream so that it may be read again.
Definition: ISstream.C:852
Foam::ISstream::readRaw
virtual Istream & readRaw(char *data, std::streamsize count)
Low-level raw binary read.
Definition: ISstream.C:818
Foam::ISstream::get
ISstream & get(char &c)
Raw, low-level get character function.
Definition: ISstreamI.H:58
Foam::label
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:62
Foam::ISstream::endRawRead
virtual bool endRawRead()
End of low-level raw binary read.
Definition: ISstream.C:843
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
fileName.H
Istream.H
ISstreamI.H
Foam::ISstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: ISstream.H:111
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:321
Foam::ISstream::putback
ISstream & putback(const char c)
Raw, low-level putback character function.
Definition: ISstreamI.H:92
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::ISstream::stdStream
virtual const std::istream & stdStream() const
Const access to underlying std::istream.
Definition: ISstream.H:198
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ISstream::stdStream
virtual std::istream & stdStream()
Access to underlying std::istream.
Definition: ISstream.H:192
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
Foam::ISstream::flags
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ISstream.C:866
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:71
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:827
Foam::IOstreamOption::compression
compressionType compression() const noexcept
Get the stream compression.
Definition: IOstreamOption.H:297
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54