Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "Istream.H"
00027 #include <OpenFOAM/bool.H>
00028 #include <OpenFOAM/token.H>
00029
00030
00031
00032
00033
00034 bool Foam::Istream::getBack(token& t)
00035 {
00036 if (bad())
00037 {
00038 FatalIOErrorIn("void Istream::getBack(token&)", *this)
00039 << "Attempt to get back from bad stream"
00040 << exit(FatalIOError);
00041
00042 return false;
00043 }
00044 else if (putBack_)
00045 {
00046 t = putBackToken_;
00047 putBack_ = false;
00048 return true;
00049 }
00050
00051 return false;
00052 }
00053
00054
00055
00056 void Foam::Istream::putBack(const token& t)
00057 {
00058 if (bad())
00059 {
00060 FatalIOErrorIn("void Istream::putBack(const token&)", *this)
00061 << "Attempt to put back onto bad stream"
00062 << exit(FatalIOError);
00063 }
00064 else if (putBack_)
00065 {
00066 FatalIOErrorIn("void Istream::putBack(const token&)", *this)
00067 << "Attempt to put back another token"
00068 << exit(FatalIOError);
00069 }
00070 else
00071 {
00072 putBackToken_ = t;
00073 putBack_ = true;
00074 }
00075 }
00076
00077
00078
00079
00080 Foam::Istream& Foam::Istream::readBegin(const char* funcName)
00081 {
00082 token delimiter(*this);
00083 if (delimiter != token::BEGIN_LIST)
00084 {
00085 setBad();
00086 FatalIOErrorIn("Istream::readBegin(const char*)", *this)
00087 << "Expected a '" << token::BEGIN_LIST
00088 << "' while reading " << funcName
00089 << ", found " << delimiter.info()
00090 << exit(FatalIOError);
00091 }
00092
00093 return *this;
00094 }
00095
00096
00097 Foam::Istream& Foam::Istream::readEnd(const char* funcName)
00098 {
00099 token delimiter(*this);
00100 if (delimiter != token::END_LIST)
00101 {
00102 setBad();
00103 FatalIOErrorIn("Istream::readEnd(const char*)", *this)
00104 << "Expected a '" << token::END_LIST
00105 << "' while reading " << funcName
00106 << ", found " << delimiter.info()
00107 << exit(FatalIOError);
00108 }
00109
00110 return *this;
00111 }
00112
00113
00114 Foam::Istream& Foam::Istream::readEndBegin(const char* funcName)
00115 {
00116 readEnd(funcName);
00117 return readBegin(funcName);
00118 }
00119
00120
00121
00122
00123 char Foam::Istream::readBeginList(const char* funcName)
00124 {
00125 token delimiter(*this);
00126
00127 if (delimiter != token::BEGIN_LIST && delimiter != token::BEGIN_BLOCK)
00128 {
00129 setBad();
00130 FatalIOErrorIn("Istream::readBeginList(const char*)", *this)
00131 << "Expected a '" << token::BEGIN_LIST
00132 << "' or a '" << token::BEGIN_BLOCK
00133 << "' while reading " << funcName
00134 << ", found " << delimiter.info()
00135 << exit(FatalIOError);
00136
00137 return '\0';
00138 }
00139
00140 return delimiter.pToken();
00141 }
00142
00143
00144 char Foam::Istream::readEndList(const char* funcName)
00145 {
00146 token delimiter(*this);
00147
00148 if (delimiter != token::END_LIST && delimiter != token::END_BLOCK)
00149 {
00150 setBad();
00151 FatalIOErrorIn("Istream::readEndList(const char*)", *this)
00152 << "Expected a '" << token::END_LIST
00153 << "' or a '" << token::END_BLOCK
00154 << "' while reading " << funcName
00155 << ", found " << delimiter.info()
00156 << exit(FatalIOError);
00157
00158 return '\0';
00159 }
00160
00161 return delimiter.pToken();
00162 }
00163
00164
00165 Foam::Istream& Foam::Istream::operator()() const
00166 {
00167 if (!good())
00168 {
00169 check("Istream::operator()");
00170 FatalIOError.exit();
00171 }
00172
00173 return const_cast<Istream&>(*this);
00174 }
00175
00176
00177