ITstream.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-2025 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::ITstream
26 
27 Description
28  Input token stream.
29 
30 SourceFiles
31  ITstream.C
32 
33 See also
34  Foam::OTstream
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef ITstream_H
39 #define ITstream_H
40 
41 #include "Istream.H"
42 #include "tokenList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class ITstream Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class ITstream
54 :
55  public Istream,
56  public tokenList
57 {
58  // Private Data
59 
60  //- Name of ITstream
61  fileName name_;
62 
63  //- Index of token currently being read
64  label tokenIndex_;
65 
66 
67 public:
68 
69  // Constructors
70 
71  //- Construct from components
72  ITstream
73  (
74  const string& name,
75  const streamFormat format = ASCII,
77  const bool global = false
78  )
79  :
81  name_(name),
82  tokenIndex_(0)
83  {
84  setOpened();
85  setGood();
86  }
87 
88  //- Construct from components and token
89  ITstream
90  (
91  const string& name,
92  const token& t,
93  const streamFormat format = ASCII,
95  const bool global = false
96  )
97  :
99  tokenList(1, t),
100  name_(name),
101  tokenIndex_(0)
102  {
103  setOpened();
104  setGood();
105  }
106 
107  //- Construct from components and token list
108  ITstream
109  (
110  const string& name,
111  const UList<token>& tokens,
112  const streamFormat format = ASCII,
114  const bool global = false
115  )
116  :
118  tokenList(tokens),
119  name_(name),
120  tokenIndex_(0)
121  {
122  setOpened();
123  setGood();
124  }
125 
126 
127  //- Move construct from components, transferring the token list
128  ITstream
129  (
130  const string& name,
131  List<token>&& tokens,
132  const streamFormat format = ASCII,
134  const bool global = false
135  )
136  :
138  tokenList(move(tokens)),
139  name_(name),
140  tokenIndex_(0)
141  {
142  setOpened();
143  setGood();
144  }
145 
146 
147  //- Copy constructor
148  ITstream(const ITstream& its)
149  :
151  tokenList(its),
152  name_(its.name_),
153  tokenIndex_(0)
154  {
155  setOpened();
156  setGood();
157  }
158 
159 
160  //- Destructor
161  virtual ~ITstream()
162  {}
163 
164 
165  // Member Functions
166 
167  // Inquiry
168 
169  //- Return the name of the stream
170  const fileName& name() const
171  {
172  return name_;
173  }
174 
175  //- Return non-const access to the name of the stream
176  fileName& name()
177  {
178  return name_;
179  }
180 
181  //- Return the current token index
182  label tokenIndex() const
183  {
184  return tokenIndex_;
185  }
186 
187  //- Return non-const access to the current token index
188  label& tokenIndex()
189  {
190  return tokenIndex_;
191  }
192 
193  //- Return the number of remaining tokens
194  label nRemainingTokens() const
195  {
196  return size() - tokenIndex_;
197  }
198 
199  //- Return flags of output stream
200  ios_base::fmtflags flags() const
201  {
202  return ios_base::fmtflags(0);
203  }
204 
205 
206  // Read functions
207 
208  //- Return next token from stream
209  virtual Istream& read(token&);
210 
211  //- Read a character
212  virtual Istream& read(char&);
213 
214  //- Read a word
215  virtual Istream& read(word&);
216 
217  // Read a string (including enclosing double-quotes)
218  virtual Istream& read(string&);
219 
220  //- Read an int32_t
221  virtual Istream& read(int32_t&);
222 
223  //- Read an int64_t
224  virtual Istream& read(int64_t&);
225 
226  //- Read a uint32_t
227  virtual Istream& read(uint32_t&);
228 
229  //- Read a uint64_t
230  virtual Istream& read(uint64_t&);
231 
232  //- Read a floatScalar
233  virtual Istream& read(floatScalar&);
234 
235  //- Read a doubleScalar
236  virtual Istream& read(doubleScalar&);
237 
238  //- Read a longDoubleScalar
239  virtual Istream& read(longDoubleScalar&);
240 
241  //- Read binary block
242  virtual Istream& read(char*, std::streamsize);
243 
244  //- Rewind and return the stream so that it may be read again
245  virtual Istream& rewind();
246 
247 
248  // Edit
249 
250  //- Set flags of stream
251  ios_base::fmtflags flags(const ios_base::fmtflags)
252  {
253  return ios_base::fmtflags(0);
254  }
255 
256 
257  // Print
258 
259  //- Print description of IOstream to Ostream
260  void print(Ostream&) const;
261 
262 
263  // Member Operators
264 
265  //- Assignment operator
266  void operator=(const ITstream& its)
267  {
268  Istream::operator=(its);
270  name_ = its.name_;
271  tokenIndex_ = 0;
272 
273  setOpened();
274  setGood();
275  }
276 };
277 
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 } // End namespace Foam
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 #endif
286 
287 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
void setGood()
Set stream to be good.
Definition: IOstream.H:255
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
void setOpened()
Set stream opened.
Definition: IOstream.H:237
Input token stream.
Definition: ITstream.H:56
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ITstream.H:199
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ITstream.C:185
void operator=(const ITstream &its)
Assignment operator.
Definition: ITstream.H:265
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
ITstream(const string &name, const streamFormat format=ASCII, const versionNumber version=currentVersion, const bool global=false)
Construct from components.
Definition: ITstream.H:72
virtual ~ITstream()
Destructor.
Definition: ITstream.H:160
label nRemainingTokens() const
Return the number of remaining tokens.
Definition: ITstream.H:193
label tokenIndex() const
Return the current token index.
Definition: ITstream.H:181
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: ITstream.C:31
const fileName & name() const
Return the name of the stream.
Definition: ITstream.H:169
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
Definition: List.C:376
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
A class for handling file names.
Definition: fileName.H:82
A token holds items read from Istream.
Definition: token.H:74
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
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
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
long double longDoubleScalar
Lang double precision floating point scalar type.