All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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,
75  )
76  :
78  tokenList(tokens),
79  name_(name),
80  tokenIndex_(0)
81  {
82  setOpened();
83  setGood();
84  }
85 
86 
87  //- Move construct from components, transferring the tokens
88  ITstream
89  (
90  const string& name,
91  List<token>&& tokens,
94  )
95  :
97  tokenList(move(tokens)),
98  name_(name),
99  tokenIndex_(0)
100  {
101  setOpened();
102  setGood();
103  }
104 
105 
106  //- Copy constructor
107  ITstream(const ITstream& its)
108  :
110  tokenList(its),
111  name_(its.name_),
112  tokenIndex_(0)
113  {
114  setOpened();
115  setGood();
116  }
117 
118 
119  //- Destructor
120  virtual ~ITstream()
121  {}
122 
123 
124  // Member Functions
125 
126  // Inquiry
127 
128  //- Return the name of the stream
129  const fileName& name() const
130  {
131  return name_;
132  }
133 
134  //- Return non-const access to the name of the stream
135  fileName& name()
136  {
137  return name_;
138  }
139 
140  //- Return the current token index
141  label tokenIndex() const
142  {
143  return tokenIndex_;
144  }
145 
146  //- Return non-const access to the current token index
147  label& tokenIndex()
148  {
149  return tokenIndex_;
150  }
151 
152  //- Return the number of remaining tokens
153  label nRemainingTokens() const
154  {
155  return size() - tokenIndex_;
156  }
157 
158  //- Return flags of output stream
159  ios_base::fmtflags flags() const
160  {
161  return ios_base::fmtflags(0);
162  }
163 
164 
165  // Read functions
166 
167  //- Return next token from stream
168  virtual Istream& read(token&);
169 
170  //- Read a character
171  virtual Istream& read(char&);
172 
173  //- Read a word
174  virtual Istream& read(word&);
175 
176  // Read a string (including enclosing double-quotes)
177  virtual Istream& read(string&);
178 
179  //- Read an int32_t
180  virtual Istream& read(int32_t&);
181 
182  //- Read an int64_t
183  virtual Istream& read(int64_t&);
184 
185  //- Read a uint32_t
186  virtual Istream& read(uint32_t&);
187 
188  //- Read a uint64_t
189  virtual Istream& read(uint64_t&);
190 
191  //- Read a floatScalar
192  virtual Istream& read(floatScalar&);
193 
194  //- Read a doubleScalar
195  virtual Istream& read(doubleScalar&);
196 
197  //- Read a longDoubleScalar
198  virtual Istream& read(longDoubleScalar&);
199 
200  //- Read binary block
201  virtual Istream& read(char*, std::streamsize);
202 
203  //- Rewind and return the stream so that it may be read again
204  virtual Istream& rewind();
205 
206 
207  // Edit
208 
209  //- Set flags of stream
210  ios_base::fmtflags flags(const ios_base::fmtflags)
211  {
212  return ios_base::fmtflags(0);
213  }
214 
215 
216  // Print
217 
218  //- Print description of IOstream to Ostream
219  void print(Ostream&) const;
220 
221 
222  // Member Operators
223 
224  //- Assignment operator
225  void operator=(const ITstream& its)
226  {
227  Istream::operator=(its);
229  name_ = its.name_;
230  tokenIndex_ = 0;
231 
232  setOpened();
233  setGood();
234  }
235 };
236 
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 } // End namespace Foam
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 #endif
245 
246 // ************************************************************************* //
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:374
void setGood()
Set stream to be good.
Definition: IOstream.H:254
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
void setOpened()
Set stream opened.
Definition: IOstream.H:236
Input token stream.
Definition: ITstream.H:53
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ITstream.H:158
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:224
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
virtual ~ITstream()
Destructor.
Definition: ITstream.H:119
label nRemainingTokens() const
Return the number of remaining tokens.
Definition: ITstream.H:152
ITstream(const string &name, const UList< token > &tokens, streamFormat format=ASCII, versionNumber version=currentVersion)
Construct from components.
Definition: ITstream.H:69
label tokenIndex() const
Return the current token index.
Definition: ITstream.H:140
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:128
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.