OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

ITstream.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::ITstream
00027 
00028 Description
00029     Input token stream.
00030 
00031 SourceFiles
00032     ITstream.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef ITstream_H
00037 #define ITstream_H
00038 
00039 #include "Istream.H"
00040 #include "tokenList.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 /*---------------------------------------------------------------------------*\
00048                            Class ITstream Declaration
00049 \*---------------------------------------------------------------------------*/
00050 
00051 class ITstream
00052 :
00053     public Istream,
00054     public tokenList
00055 {
00056     // Private data
00057 
00058         //- Name of ITstream
00059         fileName name_;
00060 
00061         //- Index of token currently being read
00062         label tokenIndex_;
00063 
00064 
00065 public:
00066 
00067     // Constructors
00068 
00069         //- Construct from components
00070         ITstream
00071         (
00072             const string& name,
00073             const tokenList& tokens,
00074             streamFormat format=ASCII,
00075             versionNumber version=currentVersion
00076         )
00077         :
00078             Istream(format, version),
00079             tokenList(tokens),
00080             name_(name),
00081             tokenIndex_(0)
00082         {
00083             setOpened();
00084             setGood();
00085         }
00086 
00087 
00088         //- Construct as copy
00089         ITstream(const ITstream& its)
00090         :
00091             Istream(ASCII, currentVersion),
00092             tokenList(its),
00093             name_(its.name_),
00094             tokenIndex_(0)
00095         {
00096             setOpened();
00097             setGood();
00098         }
00099 
00100 
00101     // Destructor
00102 
00103         virtual ~ITstream()
00104         {}
00105 
00106 
00107     // Member functions
00108 
00109         // Inquiry
00110 
00111             //- Return the name of the stream
00112             const fileName& name() const
00113             {
00114                 return name_;
00115             }
00116 
00117             //- Return non-const access to the name of the stream
00118             fileName& name()
00119             {
00120                 return name_;
00121             }
00122 
00123             //- Return the current token index
00124             label tokenIndex() const
00125             {
00126                 return tokenIndex_;
00127             }
00128 
00129             //- Return non-const access to the current token index
00130             label& tokenIndex()
00131             {
00132                 return tokenIndex_;
00133             }
00134 
00135             //- Return the number of remaining tokens
00136             label nRemainingTokens() const
00137             {
00138                 return size() - tokenIndex_;
00139             }
00140 
00141             //- Return flags of output stream
00142             ios_base::fmtflags flags() const
00143             {
00144                 return ios_base::fmtflags(0);
00145             }
00146 
00147 
00148         // Read functions
00149 
00150             //- Return next token from stream
00151             virtual Istream& read(token&);
00152 
00153             //- Read a character
00154             virtual Istream& read(char&);
00155 
00156             //- Read a word
00157             virtual Istream& read(word&);
00158 
00159             // Read a string (including enclosing double-quotes)
00160             virtual Istream& read(string&);
00161 
00162             //- Read a label
00163             virtual Istream& read(label&);
00164 
00165             //- Read a floatScalar
00166             virtual Istream& read(floatScalar&);
00167 
00168             //- Read a doubleScalar
00169             virtual Istream& read(doubleScalar&);
00170 
00171             //- Read binary block
00172             virtual Istream& read(char*, std::streamsize);
00173 
00174             //- Rewind and return the stream so that it may be read again
00175             virtual Istream& rewind();
00176 
00177 
00178         // Edit
00179 
00180             //- Set flags of stream
00181             ios_base::fmtflags flags(const ios_base::fmtflags)
00182             {
00183                 return ios_base::fmtflags(0);
00184             }
00185 
00186 
00187         // Print
00188 
00189             //- Print description of IOstream to Ostream
00190             void print(Ostream&) const;
00191 };
00192 
00193 
00194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00195 
00196 } // End namespace Foam
00197 
00198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00199 
00200 #endif
00201 
00202 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd