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