ISstream.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-2019 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::ISstream
26 
27 Description
28  Generic input stream.
29 
30 SourceFiles
31  ISstreamI.H
32  ISstream.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef ISstream_H
37 #define ISstream_H
38 
39 #include "Istream.H"
40 #include "fileName.H"
41 #include <iostream>
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class ISstream Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class ISstream
53 :
54  public Istream
55 {
56  // Private Data
57 
58  fileName name_;
59  istream& is_;
60 
61 
62  // Private Member Functions
63 
64  char nextValid();
65 
66  void readWordToken(token&);
67 
68  // Private Member Functions
69 
70 
71  //- Read a verbatim string (excluding block delimiters).
72  Istream& readVerbatim(string&);
73 
74  //- Read a variable name (includes '{')
75  Istream& readVariable(string&);
76 
77 
78 public:
79 
80  // Constructors
81 
82  //- Construct as wrapper around istream
83  inline ISstream
84  (
85  istream& is,
86  const string& name,
90  );
91 
92 
93  //- Destructor
94  virtual ~ISstream()
95  {}
96 
97 
98  // Member Functions
99 
100  // Inquiry
101 
102  //- Return the name of the stream
103  // Useful for Fstream to return the filename
104  virtual const fileName& name() const
105  {
106  return name_;
107  }
108 
109  //- Return non-const access to the name of the stream
110  // Useful to alter the stream name
111  virtual fileName& name()
112  {
113  return name_;
114  }
115 
116  //- Return flags of output stream
117  virtual ios_base::fmtflags flags() const;
118 
119 
120  // Read functions
121 
122  //- Raw, low-level get character function.
123  inline ISstream& get(char&);
124 
125  //- Raw, low-level peek function.
126  // Does not remove the character from the stream.
127  // Returns the next character in the stream or EOF if the
128  // end of file is read.
129  inline int peek();
130 
131  //- Raw, low-level getline into a string function.
132  inline ISstream& getLine(string&);
133 
134  //- Raw, low-level putback character function.
135  inline ISstream& putback(const char&);
136 
137  //- Return next token from stream
138  virtual Istream& read(token&);
139 
140  //- Read a character
141  virtual Istream& read(char&);
142 
143  //- Read a word
144  virtual Istream& read(word&);
145 
146  //- Read a string (including enclosing double-quotes).
147  // Backslashes are retained, except when escaping double-quotes
148  // and an embedded newline character.
149  virtual Istream& read(string&);
150 
151  //- Read a label
152  virtual Istream& read(label&);
153 
154  //- Read a floatScalar
155  virtual Istream& read(floatScalar&);
156 
157  //- Read a doubleScalar
158  virtual Istream& read(doubleScalar&);
159 
160  //- Read a longDoubleScalar
161  virtual Istream& read(longDoubleScalar&);
162 
163  //- Read binary block
164  virtual Istream& read(char*, std::streamsize);
165 
166  //- Rewind and return the stream so that it may be read again
167  virtual Istream& rewind();
168 
169 
170  // Stream state functions
171 
172  //- Set flags of output stream
173  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
174 
175 
176  // STL stream
177 
178  //- Access to underlying std::istream
179  virtual istream& stdStream()
180  {
181  return is_;
182  }
183 
184  //- Const access to underlying std::istream
185  virtual const istream& stdStream() const
186  {
187  return is_;
188  }
189 
190 
191  // Print
192 
193  //- Print description of IOstream to Ostream
194  virtual void print(Ostream&) const;
195 
196 
197  // Member Operators
198 
199  //- Disallow default bitwise assignment
200  void operator=(const ISstream&) = delete;
201 };
202 
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 } // End namespace Foam
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 #include "ISstreamI.H"
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #endif
215 
216 // ************************************************************************* //
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
A class for handling file names.
Definition: fileName.H:79
virtual const fileName & name() const
Return the name of the stream.
Definition: ISstream.H:103
ISstream(istream &is, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct as wrapper around istream.
Definition: ISstreamI.H:31
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:34
A token holds items read from Istream.
Definition: token.H:69
void operator=(const ISstream &)=delete
Disallow default bitwise assignment.
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
virtual Istream & read(token &)
Return next token from stream.
Definition: ISstream.C:132
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ISstream.C:819
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ISstream.C:808
A class for handling words, derived from string.
Definition: word.H:59
int peek()
Raw, low-level peek function.
Definition: ISstreamI.H:71
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual istream & stdStream()
Access to underlying std::istream.
Definition: ISstream.H:178
long double longDoubleScalar
Lang double precision floating point scalar type.
ISstream & putback(const char &)
Raw, low-level putback character function.
Definition: ISstreamI.H:87
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
Generic input stream.
Definition: ISstream.H:51
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
Version number type.
Definition: IOstream.H:96
Namespace for OpenFOAM.
virtual ~ISstream()
Destructor.
Definition: ISstream.H:93
ISstream & getLine(string &)
Raw, low-level getline into a string function.
Definition: ISstreamI.H:77