Istream.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-2024 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::Istream
26 
27 Description
28  An Istream is an abstract base class for all input systems
29  (streams, files, token lists etc). The basic operations
30  are construct, close, read token, read primitive and read binary
31  block.
32 
33  In addition, version control and line number counting is incorporated.
34  Usually one would use the read primitive member functions, but if one
35  were reading a stream on unknown data sequence one can read token by
36  token, and then analyse.
37 
38 SourceFiles
39  Istream.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Istream_H
44 #define Istream_H
45 
46 #include "IOstream.H"
47 #include "token.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class Istream Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class Istream
59 :
60  public IOstream
61 {
62  // Private Data
63 
64  //- Has a token been put back on the stream?
65  bool putBack_;
66 
67  //- The last token put back on the stream
68  token putBackToken_;
69 
70 
71 public:
72 
73  // Constructors
74 
75  //- Set stream status
76  Istream
77  (
81  )
82  :
84  putBack_(false)
85  {}
86 
87 
88  //- Destructor
89  virtual ~Istream()
90  {}
91 
92 
93  // Member Functions
94 
95  // Read functions
96 
97  //- Put back token
98  // Only a single put back is permitted
99  void putBack(const token&);
100 
101  //- Get the put back token if there is one and return true.
102  // Return false if no put back token is available.
103  bool getBack(token&);
104 
105  //- Peek at the put back token without removing it.
106  // Returns false if no put back token is available and set the
107  // token to undefined.
108  bool peekBack(token&);
109 
110  //- Return next token from stream
111  virtual Istream& read(token&) = 0;
112 
113  //- Read a character
114  virtual Istream& read(char&) = 0;
115 
116  //- Read a word
117  virtual Istream& read(word&) = 0;
118 
119  // Read a string (including enclosing double-quotes)
120  virtual Istream& read(string&) = 0;
121 
122  //- Read an int32_t
123  virtual Istream& read(int32_t&) = 0;
124 
125  //- Read an int64_t
126  virtual Istream& read(int64_t&) = 0;
127 
128  //- Read a uint32_t
129  virtual Istream& read(uint32_t&) = 0;
130 
131  //- Read a uint64_t
132  virtual Istream& read(uint64_t&) = 0;
133 
134  //- Read a floatScalar
135  virtual Istream& read(floatScalar&) = 0;
136 
137  //- Read a doubleScalar
138  virtual Istream& read(doubleScalar&) = 0;
139 
140  //- Read a longDoubleScalar
141  virtual Istream& read(longDoubleScalar&) = 0;
142 
143  //- Read binary block
144  virtual Istream& read(char*, std::streamsize) = 0;
145 
146  //- Rewind and return the stream so that it may be read again
147  virtual Istream& rewind() = 0;
148 
149 
150  // Read List punctuation tokens
151 
152  Istream& readBegin(const char* funcName);
153  Istream& readEnd(const char* funcName);
154  Istream& readEndBegin(const char* funcName);
155 
156  char readBeginList(const char* funcName);
157  char readEndList(const char* funcName);
158 
159 
160  // Member Operators
161 
162  //- Return a non-const reference to const Istream
163  // Needed for read-constructors where the stream argument is temporary:
164  // e.g. thing thisThing(IFstream("thingFileName")());
165  Istream& operator()() const;
166 };
167 
168 
169 // --------------------------------------------------------------------
170 // ------ Manipulators (not taking arguments)
171 // --------------------------------------------------------------------
172 
173 typedef Istream& (*IstreamManip)(Istream&);
174 
175 //- operator>> handling for manipulators without arguments
177 {
178  return f(is);
179 }
180 
181 //- operator>> handling for manipulators without arguments
183 {
184  f(is);
185  return is;
186 }
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #ifdef NoRepository
196  #include "HashTable.C"
197 #endif
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 #endif
202 
203 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:72
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:413
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
virtual Istream & rewind()=0
Rewind and return the stream so that it may be read again.
virtual ~Istream()
Destructor.
Definition: Istream.H:88
Istream & operator()() const
Return a non-const reference to const Istream.
Definition: Istream.C:169
char readEndList(const char *funcName)
Definition: Istream.C:148
bool peekBack(token &)
Peek at the put back token without removing it.
Definition: Istream.C:71
virtual Istream & read(token &)=0
Return next token from stream.
Istream(streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
Definition: Istream.H:76
char readBeginList(const char *funcName)
Definition: Istream.C:127
void putBack(const token &)
Put back token.
Definition: Istream.C:30
Istream & readEndBegin(const char *funcName)
Definition: Istream.C:120
bool getBack(token &)
Get the put back token if there is one and return true.
Definition: Istream.C:52
A token holds items read from Istream.
Definition: token.H:73
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
IOstream &(* IOstreamManip)(IOstream &)
Definition: IOstream.H:546
Istream & operator>>(Istream &, pistonPointEdgeData &)
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
Istream &(* IstreamManip)(Istream &)
Definition: Istream.H:172
long double longDoubleScalar
Lang double precision floating point scalar type.
labelList f(nPoints)