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-2019 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
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 a label
123  virtual Istream& read(label&) = 0;
124 
125  //- Read a floatScalar
126  virtual Istream& read(floatScalar&) = 0;
127 
128  //- Read a doubleScalar
129  virtual Istream& read(doubleScalar&) = 0;
130 
131  //- Read a longDoubleScalar
132  virtual Istream& read(longDoubleScalar&) = 0;
133 
134  //- Read binary block
135  virtual Istream& read(char*, std::streamsize) = 0;
136 
137  //- Rewind and return the stream so that it may be read again
138  virtual Istream& rewind() = 0;
139 
140 
141  // Read List punctuation tokens
142 
143  Istream& readBegin(const char* funcName);
144  Istream& readEnd(const char* funcName);
145  Istream& readEndBegin(const char* funcName);
146 
147  char readBeginList(const char* funcName);
148  char readEndList(const char* funcName);
149 
150 
151  // Member Operators
152 
153  //- Return a non-const reference to const Istream
154  // Needed for read-constructors where the stream argument is temporary:
155  // e.g. thing thisThing(IFstream("thingFileName")());
156  Istream& operator()() const;
157 };
158 
159 
160 // --------------------------------------------------------------------
161 // ------ Manipulators (not taking arguments)
162 // --------------------------------------------------------------------
164 typedef Istream& (*IstreamManip)(Istream&);
165 
166 //- operator>> handling for manipulators without arguments
168 {
169  return f(is);
170 }
171 
172 //- operator>> handling for manipulators without arguments
174 {
175  f(is);
176  return is;
177 }
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace Foam
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #ifdef NoRepository
187  #include "HashTable.C"
188 #endif
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 #endif
193 
194 // ************************************************************************* //
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
bool peekBack(token &)
Peek at the put back token without removing it.
Definition: Istream.C:71
Istream & operator()() const
Return a non-const reference to const Istream.
Definition: Istream.C:169
char readEndList(const char *funcName)
Definition: Istream.C:148
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:72
void putBack(const token &)
Put back token.
Definition: Istream.C:30
virtual Istream & rewind()=0
Rewind and return the stream so that it may be read again.
Istream(streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
Definition: Istream.H:76
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
virtual Istream & read(token &)=0
Return next token from stream.
Istream & readEndBegin(const char *funcName)
Definition: Istream.C:120
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
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
char readBeginList(const char *funcName)
Definition: Istream.C:127
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
labelList f(nPoints)
long double longDoubleScalar
Lang double precision floating point scalar type.
Istream &(* IstreamManip)(Istream &)
Definition: Istream.H:163
virtual ~Istream()
Destructor.
Definition: Istream.H:88
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:413
An IOstream is an abstract base class for all input/output systems; be they streams, files, token lists etc.
Definition: IOstream.H:71
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
bool getBack(token &)
Get the put back token if there is one and return true.
Definition: Istream.C:52
Version number type.
Definition: IOstream.H:96
IOstream &(* IOstreamManip)(IOstream &)
Definition: IOstream.H:546
Namespace for OpenFOAM.