ITstream.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) 2011 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  //- Construct from components, transferring the tokens
89  (
90  const string& name,
91  const Xfer<List<token> >& tokens,
94  )
95  :
97  tokenList(tokens),
98  name_(name),
99  tokenIndex_(0)
100  {
101  setOpened();
102  setGood();
103  }
104 
105 
106  //- Construct as copy
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 binary block
189  virtual Istream& read(char*, std::streamsize);
190 
191  //- Rewind and return the stream so that it may be read again
192  virtual Istream& rewind();
193 
194 
195  // Edit
196 
197  //- Set flags of stream
198  ios_base::fmtflags flags(const ios_base::fmtflags)
199  {
200  return ios_base::fmtflags(0);
201  }
202 
203 
204  // Print
205 
206  //- Print description of IOstream to Ostream
207  void print(Ostream&) const;
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #endif
218 
219 // ************************************************************************* //
void setOpened()
Set stream opened.
Definition: IOstream.H:239
virtual ~ITstream()
Destructor.
Definition: ITstream.H:119
Input token stream.
Definition: ITstream.H:49
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
ITstream(const string &name, const UList< token > &tokens, streamFormat format=ASCII, versionNumber version=currentVersion)
Construct from components.
Definition: ITstream.H:69
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:49
virtual Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: ITstream.C:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
A class for handling words, derived from string.
Definition: word.H:59
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
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: ITstream.H:158
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
Namespace for OpenFOAM.
const fileName & name() const
Return the name of the stream.
Definition: ITstream.H:128
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
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
A token holds items read from Istream.
Definition: token.H:67
label tokenIndex() const
Return the current token index.
Definition: ITstream.H:140
label nRemainingTokens() const
Return the number of remaining tokens.
Definition: ITstream.H:152
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: ITstream.C:31
A class for handling file names.
Definition: fileName.H:69
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
label size() const
Return the number of elements in the UList.
Definition: ListI.H:83
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:49
Version number type.
Definition: IOstream.H:96
void setGood()
Set stream to be good.
Definition: IOstream.H:257
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206