FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/Istream.H>
39 #include <OpenFOAM/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 tokenList& tokens,
75  )
76  :
78  tokenList(tokens),
79  name_(name),
80  tokenIndex_(0)
81  {
82  setOpened();
83  setGood();
84  }
85 
86 
87  //- Construct as copy
88  ITstream(const ITstream& its)
89  :
91  tokenList(its),
92  name_(its.name_),
93  tokenIndex_(0)
94  {
95  setOpened();
96  setGood();
97  }
98 
99 
100  // Destructor
101 
102  virtual ~ITstream()
103  {}
104 
105 
106  // Member functions
107 
108  // Inquiry
109 
110  //- Return the name of the stream
111  const fileName& name() const
112  {
113  return name_;
114  }
115 
116  //- Return non-const access to the name of the stream
118  {
119  return name_;
120  }
121 
122  //- Return the current token index
123  label tokenIndex() const
124  {
125  return tokenIndex_;
126  }
127 
128  //- Return non-const access to the current token index
129  label& tokenIndex()
130  {
131  return tokenIndex_;
132  }
133 
134  //- Return the number of remaining tokens
135  label nRemainingTokens() const
136  {
137  return size() - tokenIndex_;
138  }
139 
140  //- Return flags of output stream
141  ios_base::fmtflags flags() const
142  {
143  return ios_base::fmtflags(0);
144  }
145 
146 
147  // Read functions
148 
149  //- Return next token from stream
150  virtual Istream& read(token&);
151 
152  //- Read a character
153  virtual Istream& read(char&);
154 
155  //- Read a word
156  virtual Istream& read(word&);
157 
158  // Read a string (including enclosing double-quotes)
159  virtual Istream& read(string&);
160 
161  //- Read a label
162  virtual Istream& read(label&);
163 
164  //- Read a floatScalar
165  virtual Istream& read(floatScalar&);
166 
167  //- Read a doubleScalar
168  virtual Istream& read(doubleScalar&);
169 
170  //- Read binary block
171  virtual Istream& read(char*, std::streamsize);
172 
173  //- Rewind and return the stream so that it may be read again
174  virtual Istream& rewind();
175 
176 
177  // Edit
178 
179  //- Set flags of stream
180  ios_base::fmtflags flags(const ios_base::fmtflags)
181  {
182  return ios_base::fmtflags(0);
183  }
184 
185 
186  // Print
187 
188  //- Print description of IOstream to Ostream
189  void print(Ostream&) const;
190 };
191 
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 } // End namespace Foam
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 #endif
200 
201 // ************************ vim: set sw=4 sts=4 et: ************************ //