Istream.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-2016 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 binary block
132  virtual Istream& read(char*, std::streamsize) = 0;
133 
134  //- Rewind and return the stream so that it may be read again
135  virtual Istream& rewind() = 0;
136 
137 
138  // Read List punctuation tokens
139 
140  Istream& readBegin(const char* funcName);
141  Istream& readEnd(const char* funcName);
142  Istream& readEndBegin(const char* funcName);
143 
144  char readBeginList(const char* funcName);
145  char readEndList(const char* funcName);
146 
147 
148  // Member operators
149 
150  //- Return a non-const reference to const Istream
151  // Needed for read-constructors where the stream argument is temporary:
152  // e.g. thing thisThing(IFstream("thingFileName")());
153  Istream& operator()() const;
154 };
155 
156 
157 // --------------------------------------------------------------------
158 // ------ Manipulators (not taking arguments)
159 // --------------------------------------------------------------------
161 typedef Istream& (*IstreamManip)(Istream&);
162 
163 //- operator>> handling for manipulators without arguments
165 {
166  return f(is);
167 }
168 
169 //- operator>> handling for manipulators without arguments
171 {
172  f(is);
173  return is;
174 }
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #ifdef NoRepository
184  #include "HashTable.C"
185 #endif
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
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
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
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:69
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:399
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:49
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:49
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
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)
Istream &(* IstreamManip)(Istream &)
Definition: Istream.H:160
virtual ~Istream()
Destructor.
Definition: Istream.H:88
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
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:206
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:549
Namespace for OpenFOAM.