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-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::ITstream
26 
27 Description
28  Input token stream.
29 
30 SourceFiles
31  ITstream.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef ITstream_H
36 #define ITstream_H
37 
38 #include "Istream.H"
39 #include "tokenList.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class ITstream Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class ITstream
51 :
52  public Istream,
53  public tokenList
54 {
55  // Private Data
56 
57  //- Name of ITstream
58  fileName name_;
59 
60  //- Index of token currently being read
61  label tokenIndex_;
62 
63 
64 public:
65 
66  // Constructors
67 
68  //- Construct from components
69  ITstream
70  (
71  const string& name,
72  const UList<token>& tokens,
73  const streamFormat format = ASCII,
75  const bool global = false
76  )
77  :
79  tokenList(tokens),
80  name_(name),
81  tokenIndex_(0)
82  {
83  setOpened();
84  setGood();
85  }
86 
87 
88  //- Move construct from components, transferring the tokens
89  ITstream
90  (
91  const string& name,
92  List<token>&& tokens,
93  const streamFormat format = ASCII,
95  const bool global = false
96  )
97  :
99  tokenList(move(tokens)),
100  name_(name),
101  tokenIndex_(0)
102  {
103  setOpened();
104  setGood();
105  }
106 
107 
108  //- Copy constructor
109  ITstream(const ITstream& its)
110  :
112  tokenList(its),
113  name_(its.name_),
114  tokenIndex_(0)
115  {
116  setOpened();
117  setGood();
118  }
119 
120 
121  //- Destructor
122  virtual ~ITstream()
123  {}
124 
125 
126  // Member Functions
127 
128  // Inquiry
129 
130  //- Return the name of the stream
131  const fileName& name() const
132  {
133  return name_;
134  }
135 
136  //- Return non-const access to the name of the stream
137  fileName& name()
138  {
139  return name_;
140  }
141 
142  //- Return the current token index
143  label tokenIndex() const
144  {
145  return tokenIndex_;
146  }
147 
148  //- Return non-const access to the current token index
149  label& tokenIndex()
150  {
151  return tokenIndex_;
152  }
153 
154  //- Return the number of remaining tokens
155  label nRemainingTokens() const
156  {
157  return size() - tokenIndex_;
158  }
159 
160  //- Return flags of output stream
161  ios_base::fmtflags flags() const
162  {
163  return ios_base::fmtflags(0);
164  }
165 
166 
167  // Read functions
168 
169  //- Return next token from stream
170  virtual Istream& read(token&);
171 
172  //- Read a character
173  virtual Istream& read(char&);
174 
175  //- Read a word
176  virtual Istream& read(word&);
177 
178  // Read a string (including enclosing double-quotes)
179  virtual Istream& read(string&);
180 
181  //- Read an int32_t
182  virtual Istream& read(int32_t&);
183 
184  //- Read an int64_t
185  virtual Istream& read(int64_t&);
186 
187  //- Read a uint32_t
188  virtual Istream& read(uint32_t&);
189 
190  //- Read a uint64_t
191  virtual Istream& read(uint64_t&);
192 
193  //- Read a floatScalar
194  virtual Istream& read(floatScalar&);
195 
196  //- Read a doubleScalar
197  virtual Istream& read(doubleScalar&);
198 
199  //- Read a longDoubleScalar
200  virtual Istream& read(longDoubleScalar&);
201 
202  //- Read binary block
203  virtual Istream& read(char*, std::streamsize);
204 
205  //- Rewind and return the stream so that it may be read again
206  virtual Istream& rewind();
207 
208 
209  // Edit
210 
211  //- Set flags of stream
212  ios_base::fmtflags flags(const ios_base::fmtflags)
213  {
214  return ios_base::fmtflags(0);
215  }
216 
217 
218  // Print
219 
220  //- Print description of IOstream to Ostream
221  void print(Ostream&) const;
222 
223 
224  // Member Operators
225 
226  //- Assignment operator
227  void operator=(const ITstream& its)
228  {
229  Istream::operator=(its);
231  name_ = its.name_;
232  tokenIndex_ = 0;
233 
234  setOpened();
235  setGood();
236  }
237 };
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 } // End namespace Foam
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 #endif
247 
248 // ************************************************************************* //
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:53
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ITstream.H:160
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:226
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
virtual ~ITstream()
Destructor.
Definition: ITstream.H:121
label nRemainingTokens() const
Return the number of remaining tokens.
Definition: ITstream.H:154
label tokenIndex() const
Return the current token index.
Definition: ITstream.H:142
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: ITstream.C:31
ITstream(const string &name, const UList< token > &tokens, const streamFormat format=ASCII, const versionNumber version=currentVersion, const bool global=false)
Construct from components.
Definition: ITstream.H:69
const fileName & name() const
Return the name of the stream.
Definition: ITstream.H:130
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:73
A class for handling words, derived from string.
Definition: word.H:62
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.