FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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