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 | Copyright (C) 2011-2012 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  //- Disallow default bitwise assignment
78  void operator=(const ISstream&);
79 
80 
81 public:
82 
83  // Constructors
84 
85  //- Construct as wrapper around istream
86  inline ISstream
87  (
88  istream& is,
89  const string& name,
93  );
94 
95 
96  //- Destructor
97  virtual ~ISstream()
98  {}
99 
100 
101  // Member functions
102 
103  // Inquiry
104 
105  //- Return the name of the stream
106  // Useful for Fstream to return the filename
107  virtual const fileName& name() const
108  {
109  return name_;
110  }
111 
112  //- Return non-const access to the name of the stream
113  // Useful to alter the stream name
114  virtual fileName& name()
115  {
116  return name_;
117  }
118 
119  //- Return flags of output stream
120  virtual ios_base::fmtflags flags() const;
121 
122 
123  // Read functions
124 
125  //- Raw, low-level get character function.
126  inline ISstream& get(char&);
127 
128  //- Raw, low-level peek function.
129  // Does not remove the character from the stream.
130  // Returns the next character in the stream or EOF if the
131  // end of file is read.
132  inline int peek();
133 
134  //- Raw, low-level getline into a string function.
135  inline ISstream& getLine(string&);
136 
137  //- Raw, low-level putback character function.
138  inline ISstream& putback(const char&);
139 
140  //- Return next token from stream
141  virtual Istream& read(token&);
142 
143  //- Read a character
144  virtual Istream& read(char&);
145 
146  //- Read a word
147  virtual Istream& read(word&);
148 
149  //- Read a string (including enclosing double-quotes).
150  // Backslashes are retained, except when escaping double-quotes
151  // and an embedded newline character.
152  virtual Istream& read(string&);
153 
154  //- Read a label
155  virtual Istream& read(label&);
156 
157  //- Read a floatScalar
158  virtual Istream& read(floatScalar&);
159 
160  //- Read a doubleScalar
161  virtual Istream& read(doubleScalar&);
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 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace Foam
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 #include "ISstreamI.H"
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #endif
209 
210 // ************************************************************************* //
ISstream(istream &is, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct as wrapper around istream.
Definition: ISstreamI.H:31
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
virtual Istream & read(token &)
Return next token from stream.
Definition: ISstream.C:132
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:49
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
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
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ISstream.C:812
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:34
virtual istream & stdStream()
Access to underlying std::istream.
Definition: ISstream.H:178
virtual ~ISstream()
Destructor.
Definition: ISstream.H:96
Namespace for OpenFOAM.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
Generic input stream.
Definition: ISstream.H:51
A token holds items read from Istream.
Definition: token.H:67
ISstream & getLine(string &)
Raw, low-level getline into a string function.
Definition: ISstreamI.H:77
int peek()
Raw, low-level peek function.
Definition: ISstreamI.H:71
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
virtual const fileName & name() const
Return the name of the stream.
Definition: ISstream.H:106
A class for handling file names.
Definition: fileName.H:69
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:49
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ISstream.C:801
Version number type.
Definition: IOstream.H:96
ISstream & putback(const char &)
Raw, low-level putback character function.
Definition: ISstreamI.H:87
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206