FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/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 
90  virtual ~Istream()
91  {}
92 
93 
94  // Member functions
95 
96  // Read functions
97 
98  //- Put back token
99  void putBack(const token&);
100 
101  //- Get the put back token
102  bool getBack(token&);
103 
104  //- Return next token from stream
105  virtual Istream& read(token&) = 0;
106 
107  //- Read a character
108  virtual Istream& read(char&) = 0;
109 
110  //- Read a word
111  virtual Istream& read(word&) = 0;
112 
113  // Read a string (including enclosing double-quotes)
114  virtual Istream& read(string&) = 0;
115 
116  //- Read a label
117  virtual Istream& read(label&) = 0;
118 
119  //- Read a floatScalar
120  virtual Istream& read(floatScalar&) = 0;
121 
122  //- Read a doubleScalar
123  virtual Istream& read(doubleScalar&) = 0;
124 
125  //- Read binary block
126  virtual Istream& read(char*, std::streamsize) = 0;
127 
128  //- Rewind and return the stream so that it may be read again
129  virtual Istream& rewind() = 0;
130 
131 
132  // Read List punctuation tokens
133 
134  Istream& readBegin(const char* funcName);
135  Istream& readEnd(const char* funcName);
136  Istream& readEndBegin(const char* funcName);
137 
138  char readBeginList(const char* funcName);
139  char readEndList(const char* funcName);
140 
141 
142  // Member operators
143 
144  //- Return a non-const reference to const Istream
145  // Needed for read-constructors where the stream argument is temporary:
146  // e.g. thing thisThing(IFstream("thingFileName")());
147  Istream& operator()() const;
148 };
149 
150 
151 // --------------------------------------------------------------------
152 // ------ Manipulators (not taking arguments)
153 // --------------------------------------------------------------------
154 
155 typedef Istream& (*IstreamManip)(Istream&);
156 
157 //- operator>> handling for manipulators without arguments
159 {
160  return f(is);
161 }
162 
163 //- operator>> handling for manipulators without arguments
165 {
166  f(is);
167  return is;
168 }
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 } // End namespace Foam
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #ifdef NoRepository
178 # include <OpenFOAM/HashTable.C>
179 #endif
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #endif
184 
185 // ************************ vim: set sw=4 sts=4 et: ************************ //