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  (
78  const streamFormat format = ASCII,
81  const bool global = false
82  )
83  :
85  putBack_(false)
86  {}
87 
88 
89  //- Destructor
90  virtual ~Istream()
91  {}
92 
93 
94  // Member Functions
95 
96  // Read functions
97 
98  //- Put back token
99  // Only a single put back is permitted
100  void putBack(const token&);
101 
102  //- Get the put back token if there is one and return true.
103  // Return false if no put back token is available.
104  bool getBack(token&);
105 
106  //- Peek at the put back token without removing it.
107  // Returns false if no put back token is available and set the
108  // token to undefined.
109  bool peekBack(token&);
110 
111  //- Return next token from stream
112  virtual Istream& read(token&) = 0;
113 
114  //- Read a character
115  virtual Istream& read(char&) = 0;
116 
117  //- Read a word
118  virtual Istream& read(word&) = 0;
119 
120  // Read a string (including enclosing double-quotes)
121  virtual Istream& read(string&) = 0;
122 
123  //- Read an int32_t
124  virtual Istream& read(int32_t&) = 0;
125 
126  //- Read an int64_t
127  virtual Istream& read(int64_t&) = 0;
128 
129  //- Read a uint32_t
130  virtual Istream& read(uint32_t&) = 0;
131 
132  //- Read a uint64_t
133  virtual Istream& read(uint64_t&) = 0;
134 
135  //- Read a floatScalar
136  virtual Istream& read(floatScalar&) = 0;
137 
138  //- Read a doubleScalar
139  virtual Istream& read(doubleScalar&) = 0;
140 
141  //- Read a longDoubleScalar
142  virtual Istream& read(longDoubleScalar&) = 0;
143 
144  //- Read binary block
145  virtual Istream& read(char*, std::streamsize) = 0;
146 
147  //- Rewind and return the stream so that it may be read again
148  virtual Istream& rewind() = 0;
149 
150 
151  // Read List punctuation tokens
152 
153  Istream& readBegin(const char* funcName);
154  Istream& readEnd(const char* funcName);
155  Istream& readEndBegin(const char* funcName);
156 
157  char readBeginList(const char* funcName);
158  char readEndList(const char* funcName);
159 
160 
161  // Member Operators
162 
163  //- Return a non-const reference to const Istream
164  // Needed for read-constructors where the stream argument is temporary:
165  // e.g. thing thisThing(IFstream("thingFileName")());
166  Istream& operator()() const;
167 };
168 
169 
170 // --------------------------------------------------------------------
171 // ------ Manipulators (not taking arguments)
172 // --------------------------------------------------------------------
173 
174 typedef Istream& (*IstreamManip)(Istream&);
175 
176 //- operator>> handling for manipulators without arguments
178 {
179  return f(is);
180 }
181 
182 //- operator>> handling for manipulators without arguments
184 {
185  f(is);
186  return is;
187 }
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #ifdef NoRepository
197  #include "HashTable.C"
198 #endif
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #endif
203 
204 // ************************************************************************* //
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:377
bool global() const
Return global state.
Definition: IOstream.H:438
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
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:89
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
Istream(const streamFormat format=ASCII, const versionNumber version=currentVersion, const compressionType compression=UNCOMPRESSED, const bool global=false)
Set stream status.
Definition: Istream.H:76
virtual Istream & read(token &)=0
Return next token from stream.
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:561
Istream & operator>>(Istream &, pistonPointEdgeData &)
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
Istream &(* IstreamManip)(Istream &)
Definition: Istream.H:173
long double longDoubleScalar
Lang double precision floating point scalar type.
labelList f(nPoints)