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

ITstream.C

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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "error.H"
00028 #include "ITstream.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 void Foam::ITstream::print(Ostream& os) const
00033 {
00034     os  << "ITstream : " << name_.c_str();
00035 
00036     if (size())
00037     {
00038         if (begin()->lineNumber() == rbegin()->lineNumber())
00039         {
00040             os  << ", line " << begin()->lineNumber() << ", ";
00041         }
00042         else
00043         {
00044             os  << ", lines " << begin()->lineNumber()
00045                 << '-' << rbegin()->lineNumber() << ", ";
00046         }
00047     }
00048     else
00049     {
00050         os  << ", line " << lineNumber() << ", ";
00051     }
00052 
00053     IOstream::print(os);
00054 }
00055 
00056 
00057 Foam::Istream& Foam::ITstream::read(token& t)
00058 {
00059     // Return the put back token if it exists
00060     if (Istream::getBack(t))
00061     {
00062         lineNumber_ = t.lineNumber();
00063         return *this;
00064     }
00065 
00066     if (tokenIndex_ < size())
00067     {
00068         t = operator[](tokenIndex_++);
00069         lineNumber_ = t.lineNumber();
00070 
00071         if (tokenIndex_ == size())
00072         {
00073             setEof();
00074         }
00075     }
00076     else
00077     {
00078         if (eof())
00079         {
00080             FatalIOErrorIn
00081             (
00082                 "ITstream::read(token& t)",
00083                 *this
00084             )   << "attempt to read beyond EOF"
00085                 << exit(FatalIOError);
00086 
00087             setBad();
00088         }
00089         else
00090         {
00091             setEof();
00092         }
00093 
00094         if (size())
00095         {
00096             token::undefinedToken.lineNumber()
00097                 = operator[](size() - 1).lineNumber();
00098         }
00099         else
00100         {
00101             token::undefinedToken.lineNumber() = lineNumber();
00102         }
00103 
00104         t = token::undefinedToken;
00105     }
00106 
00107     return *this;
00108 }
00109 
00110 
00111 Foam::Istream& Foam::ITstream::read(char&)
00112 {
00113     notImplemented("Istream& ITstream::read(char& c)");
00114     return *this;
00115 }
00116 
00117 
00118 Foam::Istream& Foam::ITstream::read(word&)
00119 {
00120     notImplemented("Istream& ITstream::read(word&)");
00121     return *this;
00122 }
00123 
00124 
00125 Foam::Istream& Foam::ITstream::read(string&)
00126 {
00127     notImplemented("Istream& ITstream::read(string&)");
00128     return *this;
00129 }
00130 
00131 
00132 Foam::Istream& Foam::ITstream::read(label&)
00133 {
00134     notImplemented("Istream& ITstream::read(label&)");
00135     return *this;
00136 }
00137 
00138 
00139 Foam::Istream& Foam::ITstream::read(floatScalar&)
00140 {
00141     notImplemented("Istream& ITstream::read(floatScalar&)");
00142     return *this;
00143 }
00144 
00145 
00146 Foam::Istream& Foam::ITstream::read(doubleScalar&)
00147 {
00148     notImplemented("Istream& ITstream::read(doubleScalar&)");
00149     return *this;
00150 }
00151 
00152 
00153 Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
00154 {
00155     notImplemented("Istream& ITstream::read(char*, std::streamsize)");
00156     return *this;
00157 }
00158 
00159 
00160 // Rewind the token stream so that it may be read again
00161 Foam::Istream& Foam::ITstream::rewind()
00162 {
00163     tokenIndex_ = 0;
00164 
00165     if (size())
00166     {
00167         lineNumber_ = operator[](0).lineNumber();
00168     }
00169 
00170     setGood();
00171 
00172     return *this;
00173 }
00174 
00175 
00176 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd