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-2020 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  //- Read a verbatim string (excluding block delimiters).
67  Istream& readVerbatim(verbatimString&);
68 
69  //- Read a variable name into a string
70  Istream& readVariable(string&);
71 
72  //- Read a delimited set of characters into a string
73  Istream& readDelimited(string&, const char begin, const char end);
74 
75  //- Read a work token
76  void readWordToken(token&);
77 
78 
79 public:
80 
81  // Constructors
82 
83  //- Construct as wrapper around istream
84  inline ISstream
85  (
86  istream& is,
87  const string& name,
91  );
92 
93 
94  //- Destructor
95  virtual ~ISstream()
96  {}
97 
98 
99  // Member Functions
100 
101  // Inquiry
102 
103  //- Return the name of the stream
104  // Useful for Fstream to return the filename
105  virtual const fileName& name() const
106  {
107  return name_;
108  }
109 
110  //- Return non-const access to the name of the stream
111  // Useful to alter the stream name
112  virtual fileName& name()
113  {
114  return name_;
115  }
116 
117  //- Return flags of output stream
118  virtual ios_base::fmtflags flags() const;
119 
120 
121  // Read functions
122 
123  //- Low-level get character function.
124  inline ISstream& get(char&);
125 
126  //- Low-level peek function.
127  // Does not remove the character from the stream.
128  // Returns the next character in the stream or EOF if the
129  // end of file is read.
130  inline int peek();
131 
132  //- Low-level putback character function.
133  inline ISstream& putback(const char&);
134 
135  //- Read line into a string
136  ISstream& getLine(string&);
137 
138  //- Read a '(...)' delimited set of characters into a string
139  Istream& readList(string&);
140 
141  //- Read a '{...}' delimited set of characters into a string
142  Istream& readBlock(string&);
143 
144  //- Return next token from stream
145  virtual Istream& read(token&);
146 
147  //- Read a character
148  virtual Istream& read(char&);
149 
150  //- Read a word
151  virtual Istream& read(word&);
152 
153  //- Read a string (including enclosing double-quotes).
154  // Backslashes are retained, except when escaping double-quotes
155  // and an embedded newline character.
156  virtual Istream& read(string&);
157 
158  //- Read a label
159  virtual Istream& read(label&);
160 
161  //- Read a floatScalar
162  virtual Istream& read(floatScalar&);
163 
164  //- Read a doubleScalar
165  virtual Istream& read(doubleScalar&);
166 
167  //- Read a longDoubleScalar
168  virtual Istream& read(longDoubleScalar&);
169 
170  //- Read binary block
171  virtual Istream& read(char*, std::streamsize);
172 
173  //- Rewind and return the stream so that it may be read again
174  virtual Istream& rewind();
175 
176 
177  // Stream state functions
178 
179  //- Set flags of output stream
180  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
181 
182 
183  // STL stream
184 
185  //- Access to underlying std::istream
186  virtual istream& stdStream()
187  {
188  return is_;
189  }
190 
191  //- Const access to underlying std::istream
192  virtual const istream& stdStream() const
193  {
194  return is_;
195  }
196 
197 
198  // Print
199 
200  //- Print description of IOstream to Ostream
201  virtual void print(Ostream&) const;
202 
203 
204  // Member Operators
205 
206  //- Disallow default bitwise assignment
207  void operator=(const ISstream&) = delete;
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #include "ISstreamI.H"
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #endif
222 
223 // ************************************************************************* //
A class for handling verbatimStrings, derived from string.
Istream & readList(string &)
Read a &#39;(...)&#39; delimited set of characters into a string.
Definition: ISstream.C:835
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:104
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:72
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:133
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ISstream.C:909
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ISstream.C:898
A class for handling words, derived from string.
Definition: word.H:59
int peek()
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
Istream & readBlock(string &)
Read a &#39;{...}&#39; delimited set of characters into a string.
Definition: ISstream.C:841
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:54
virtual istream & stdStream()
Access to underlying std::istream.
Definition: ISstream.H:185
long double longDoubleScalar
Lang double precision floating point scalar type.
ISstream & putback(const char &)
Low-level putback character function.
Definition: ISstreamI.H:77
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:94
ISstream & getLine(string &)
Read line into a string.
Definition: ISstream.C:772