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-2020 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
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
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 a label
180  virtual Istream& read(label&);
181 
182  //- Read a floatScalar
183  virtual Istream& read(floatScalar&);
184 
185  //- Read a doubleScalar
186  virtual Istream& read(doubleScalar&);
187 
188  //- Read a longDoubleScalar
189  virtual Istream& read(longDoubleScalar&);
190 
191  //- Read binary block
192  virtual Istream& read(char*, std::streamsize);
193 
194  //- Rewind and return the stream so that it may be read again
195  virtual Istream& rewind();
196 
197 
198  // Edit
199 
200  //- Set flags of stream
201  ios_base::fmtflags flags(const ios_base::fmtflags)
202  {
203  return ios_base::fmtflags(0);
204  }
205 
206 
207  // Print
208 
209  //- Print description of IOstream to Ostream
210  void print(Ostream&) const;
211 
212 
213  // Member Operators
214 
215  //- Assignment operator
216  void operator=(const ITstream& its)
217  {
218  Istream::operator=(its);
220  name_ = its.name_;
221  tokenIndex_ = 0;
222 
223  setOpened();
224  setGood();
225  }
226 };
227 
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 } // End namespace Foam
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #endif
236 
237 // ************************************************************************* //
const fileName & name() const
Return the name of the stream.
Definition: ITstream.H:128
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
A class for handling file names.
Definition: fileName.H:79
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ITstream.C:164
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void setGood()
Set stream to be good.
Definition: IOstream.H:254
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:72
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
A class for handling words, derived from string.
Definition: word.H:59
label tokenIndex() const
Return the current token index.
Definition: ITstream.H:140
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
ITstream(const string &name, const UList< token > &tokens, streamFormat format=ASCII, versionNumber version=currentVersion)
Construct from components.
Definition: ITstream.H:69
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:52
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual ~ITstream()
Destructor.
Definition: ITstream.H:119
void operator=(const ITstream &its)
Assignment operator.
Definition: ITstream.H:215
long double longDoubleScalar
Lang double precision floating point scalar type.
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
Definition: List.C:376
label nRemainingTokens() const
Return the number of remaining tokens.
Definition: ITstream.H:152
void setOpened()
Set stream opened.
Definition: IOstream.H:236
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: ITstream.C:31
Version number type.
Definition: IOstream.H:96
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
Input token stream.
Definition: ITstream.H:49
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ITstream.H:158
Namespace for OpenFOAM.