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
00027
00028 #include "IOstream.H"
00029 #include <OpenFOAM/error.H>
00030 #include <sstream>
00031
00032
00033
00034 Foam::fileName Foam::IOstream::name_("IOstream");
00035
00036
00037
00038
00039 Foam::IOstream::streamFormat
00040 Foam::IOstream::formatEnum(const word& format)
00041 {
00042 if (format == "ascii")
00043 {
00044 return IOstream::ASCII;
00045 }
00046 else if (format == "binary")
00047 {
00048 return IOstream::BINARY;
00049 }
00050 else
00051 {
00052 WarningIn("IOstream::formatEnum(const word&)")
00053 << "bad format specifier '" << format << "', using 'ascii'"
00054 << endl;
00055
00056 return IOstream::ASCII;
00057 }
00058 }
00059
00060
00061 Foam::IOstream::compressionType
00062 Foam::IOstream::compressionEnum(const word& compression)
00063 {
00064 if (compression == "uncompressed")
00065 {
00066 return IOstream::UNCOMPRESSED;
00067 }
00068 else if (compression == "compressed")
00069 {
00070 return IOstream::COMPRESSED;
00071 }
00072 else
00073 {
00074 WarningIn("IOstream::compressionEnum(const word&)")
00075 << "bad compression specifier '" << compression
00076 << "', using 'uncompressed'"
00077 << endl;
00078
00079 return IOstream::UNCOMPRESSED;
00080 }
00081 }
00082
00083
00084
00085
00086 bool Foam::IOstream::check(const char* operation) const
00087 {
00088 if (bad())
00089 {
00090 FatalIOErrorIn
00091 (
00092 "IOstream::check(const char*) const", *this
00093 ) << "error in IOstream " << name() << " for operation " << operation
00094 << exit(FatalIOError);
00095 }
00096
00097 return !bad();
00098 }
00099
00100
00101 void Foam::IOstream::fatalCheck(const char* operation) const
00102 {
00103 if (bad())
00104 {
00105 FatalIOErrorIn
00106 (
00107 "IOstream::fatalCheck(const char*) const", *this
00108 ) << "error in IOstream " << name() << " for operation " << operation
00109 << exit(FatalIOError);
00110 }
00111 }
00112
00113
00114 Foam::string Foam::IOstream::versionNumber::str() const
00115 {
00116 std::ostringstream os;
00117 os.precision(1);
00118 os.setf(ios_base::fixed, ios_base::floatfield);
00119 os << versionNumber_;
00120 return os.str();
00121 }
00122
00123
00124 void Foam::IOstream::print(Ostream& os) const
00125 {
00126 os << "IOstream: " << "Version " << version_ << ", format ";
00127
00128 switch (format_)
00129 {
00130 case ASCII:
00131 os << "ASCII";
00132 break;
00133
00134 case BINARY:
00135 os << "BINARY";
00136 break;
00137 }
00138
00139 os << ", line " << lineNumber();
00140
00141 if (opened())
00142 {
00143 os << ", OPENED";
00144 }
00145
00146 if (closed())
00147 {
00148 os << ", CLOSED";
00149 }
00150
00151 if (good())
00152 {
00153 os << ", GOOD";
00154 }
00155
00156 if (eof())
00157 {
00158 os << ", EOF";
00159 }
00160
00161 if (fail())
00162 {
00163 os << ", FAIL";
00164 }
00165
00166 if (bad())
00167 {
00168 os << ", BAD";
00169 }
00170
00171 os << endl;
00172 }
00173
00174
00175 void Foam::IOstream::print(Ostream& os, const int streamState) const
00176 {
00177 if (streamState == ios_base::goodbit)
00178 {
00179 os << "ios_base::goodbit set : the last operation on stream succeeded"
00180 << endl;
00181 }
00182 else if (streamState & ios_base::badbit)
00183 {
00184 os << "ios_base::badbit set : characters possibly lost"
00185 << endl;
00186 }
00187 else if (streamState & ios_base::failbit)
00188 {
00189 os << "ios_base::failbit set : some type of formatting error"
00190 << endl;
00191 }
00192 else if (streamState & ios_base::eofbit)
00193 {
00194 os << "ios_base::eofbit set : at end of stream"
00195 << endl;
00196 }
00197 }
00198
00199
00200
00201
00202 Foam::Ostream& Foam::operator<<(Ostream& os, const IOstream::streamFormat& sf)
00203 {
00204 if (sf == IOstream::ASCII)
00205 {
00206 os << "ascii";
00207 }
00208 else
00209 {
00210 os << "binary";
00211 }
00212
00213 return os;
00214 }
00215
00216
00217 Foam::Ostream& Foam::operator<<(Ostream& os, const IOstream::versionNumber& vn)
00218 {
00219 os << vn.str().c_str();
00220 return os;
00221 }
00222
00223
00224
00225 namespace Foam
00226 {
00227
00228 # if defined (__GNUC__)
00229 template<>
00230 # endif
00231 Ostream& operator<<(Ostream& os, const InfoProxy<IOstream>& ip)
00232 {
00233 ip.t_.print(os);
00234 return os;
00235 }
00236
00237 }
00238
00239
00240