Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / db / IOstreams / Tstreams / ITstream.H
blob1c48d112a6babc8ac23aca9551d96b57e26fc202
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::ITstream
27 Description
28     Input token stream.
30 SourceFiles
31     ITstream.C
33 \*---------------------------------------------------------------------------*/
35 #ifndef ITstream_H
36 #define ITstream_H
38 #include "Istream.H"
39 #include "tokenList.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 /*---------------------------------------------------------------------------*\
47                            Class ITstream Declaration
48 \*---------------------------------------------------------------------------*/
50 class ITstream
52     public Istream,
53     public tokenList
55     // Private data
57         //- Name of ITstream
58         fileName name_;
60         //- Index of token currently being read
61         label tokenIndex_;
64 public:
66     // Constructors
68         //- Construct from components
69         ITstream
70         (
71             const string& name,
72             const tokenList& tokens,
73             streamFormat format = ASCII,
74             versionNumber version = currentVersion
75         )
76         :
77             Istream(format, version),
78             tokenList(tokens),
79             name_(name),
80             tokenIndex_(0)
81         {
82             setOpened();
83             setGood();
84         }
87         //- Construct as copy
88         ITstream(const ITstream& its)
89         :
90             Istream(ASCII, currentVersion),
91             tokenList(its),
92             name_(its.name_),
93             tokenIndex_(0)
94         {
95             setOpened();
96             setGood();
97         }
100     // Destructor
102         virtual ~ITstream()
103         {}
106     // Member functions
108         // Inquiry
110             //- Return the name of the stream
111             const fileName& name() const
112             {
113                 return name_;
114             }
116             //- Return non-const access to the name of the stream
117             fileName& name()
118             {
119                 return name_;
120             }
122             //- Return the current token index
123             label tokenIndex() const
124             {
125                 return tokenIndex_;
126             }
128             //- Return non-const access to the current token index
129             label& tokenIndex()
130             {
131                 return tokenIndex_;
132             }
134             //- Return the number of remaining tokens
135             label nRemainingTokens() const
136             {
137                 return size() - tokenIndex_;
138             }
140             //- Return flags of output stream
141             ios_base::fmtflags flags() const
142             {
143                 return ios_base::fmtflags(0);
144             }
147         // Read functions
149             //- Return next token from stream
150             virtual Istream& read(token&);
152             //- Read a character
153             virtual Istream& read(char&);
155             //- Read a word
156             virtual Istream& read(word&);
158             // Read a string (including enclosing double-quotes)
159             virtual Istream& read(string&);
161             //- Read a label
162             virtual Istream& read(label&);
164             //- Read a floatScalar
165             virtual Istream& read(floatScalar&);
167             //- Read a doubleScalar
168             virtual Istream& read(doubleScalar&);
170             //- Read a longDoubleScalar
171             virtual Istream& read(longDoubleScalar&);
173             //- Read binary block
174             virtual Istream& read(char*, std::streamsize);
176             //- Rewind and return the stream so that it may be read again
177             virtual Istream& rewind();
180         // Edit
182             //- Set flags of stream
183             ios_base::fmtflags flags(const ios_base::fmtflags)
184             {
185                 return ios_base::fmtflags(0);
186             }
189         // Print
191             //- Print description of IOstream to Ostream
192             void print(Ostream&) const;
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 } // End namespace Foam
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 #endif
204 // ************************************************************************* //