All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2021 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 "DynamicList.H"
42 #include <iostream>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class ISstream Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class ISstream
54 :
55  public Istream
56 {
57  // Private Static Data
58 
59  //- Initial capacity of the character buffer
60  static const int bufInitialCapacity = 1024;
61 
62  //- Amount of the buffer used in error messages. Less than the buffer
63  // length to facilitate readability.
64  static const int bufErrorLength = 80;
65 
66 
67  // Private Data
68 
69  //- The name of this stream
70  fileName name_;
71 
72  //- Reference to the standard stream
73  istream& is_;
74 
75  //- Character buffer
76  DynamicList<char> buf_;
77 
78 
79  // Private Member Functions
80 
81  char nextValid();
82 
83  //- Read a verbatim string (excluding block delimiters).
84  Istream& readVerbatim(verbatimString&);
85 
86  //- Read a variable name into a string
87  Istream& readVariable(string&);
88 
89  //- Read a delimited set of characters into a string
90  Istream& readDelimited(string&, const char begin, const char end);
91 
92  //- Read a work token
93  void readWordToken(token&);
94 
95 
96 public:
97 
98  // Constructors
99 
100  //- Construct as wrapper around istream
101  inline ISstream
102  (
103  istream& is,
104  const string& name,
108  );
109 
110 
111  //- Destructor
112  virtual ~ISstream()
113  {}
114 
115 
116  // Member Functions
117 
118  // Inquiry
119 
120  //- Return the name of the stream
121  // Useful for Fstream to return the filename
122  virtual const fileName& name() const
123  {
124  return name_;
125  }
126 
127  //- Return non-const access to the name of the stream
128  // Useful to alter the stream name
129  virtual fileName& name()
130  {
131  return name_;
132  }
133 
134  //- Return flags of output stream
135  virtual ios_base::fmtflags flags() const;
136 
137 
138  // Read functions
139 
140  //- Low-level get character function.
141  inline ISstream& get(char&);
142 
143  //- Low-level peek function.
144  // Does not remove the character from the stream.
145  // Returns the next character in the stream or EOF if the
146  // end of file is read.
147  inline int peek();
148 
149  //- Low-level putback character function.
150  inline ISstream& putback(const char&);
151 
152  //- Read line into a string
153  // with optional support for continuation lines
154  ISstream& getLine(string&, const bool continuation = true);
155 
156  //- Read a '(...)' delimited set of characters into a string
157  Istream& readList(string&);
158 
159  //- Read a '{...}' delimited set of characters into a string
160  Istream& readBlock(string&);
161 
162  //- Return next token from stream
163  virtual Istream& read(token&);
164 
165  //- Read a character
166  virtual Istream& read(char&);
167 
168  //- Read a word
169  virtual Istream& read(word&);
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&);
175 
176  //- Read a label
177  virtual Istream& read(label&);
178 
179  //- Read a floatScalar
180  virtual Istream& read(floatScalar&);
181 
182  //- Read a doubleScalar
183  virtual Istream& read(doubleScalar&);
184 
185  //- Read a longDoubleScalar
186  virtual Istream& read(longDoubleScalar&);
187 
188  //- Read binary block
189  virtual Istream& read(char*, std::streamsize);
190 
191  //- Rewind and return the stream so that it may be read again
192  virtual Istream& rewind();
193 
194 
195  // Stream state functions
196 
197  //- Set flags of output stream
198  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
199 
200 
201  // STL stream
202 
203  //- Access to underlying std::istream
204  virtual istream& stdStream()
205  {
206  return is_;
207  }
208 
209  //- Const access to underlying std::istream
210  virtual const istream& stdStream() const
211  {
212  return is_;
213  }
214 
215 
216  // Print
217 
218  //- Print description of IOstream to Ostream
219  virtual void print(Ostream&) const;
220 
221 
222  // Member Operators
223 
224  //- Disallow default bitwise assignment
225  void operator=(const ISstream&) = delete;
226 };
227 
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 } // End namespace Foam
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #include "ISstreamI.H"
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 #endif
240 
241 // ************************************************************************* //
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:758
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:121
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:396
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:832
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ISstream.C:821
A class for handling words, derived from string.
Definition: word.H:59
int peek()
Low-level peek function.
Definition: ISstreamI.H:72
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:374
Istream & readBlock(string &)
Read a &#39;{...}&#39; delimited set of characters into a string.
Definition: ISstream.C:764
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:203
long double longDoubleScalar
Lang double precision floating point scalar type.
ISstream & putback(const char &)
Low-level putback character function.
Definition: ISstreamI.H:78
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:413
ISstream & getLine(string &, const bool continuation=true)
Read line into a string.
Definition: ISstream.C:692
Generic input stream.
Definition: ISstream.H:52
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
Version number type.
Definition: IOstream.H:96
Namespace for OpenFOAM.
virtual ~ISstream()
Destructor.
Definition: ISstream.H:111