messageStream.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 #include "error.H"
00028 #include "dictionary.H"
00029 #include "Pstream.H"
00030
00031
00032
00033 int Foam::messageStream::level(Foam::debug::debugSwitch("level", 2));
00034
00035
00036
00037
00038
00039 Foam::messageStream::messageStream
00040 (
00041 const string& title,
00042 errorSeverity sev,
00043 const int maxErrors
00044 )
00045 :
00046 title_(title),
00047 severity_(sev),
00048 maxErrors_(maxErrors),
00049 errorCount_(0)
00050 {}
00051
00052
00053
00054 Foam::messageStream::messageStream(const dictionary& dict)
00055 :
00056 title_(dict.lookup("title")),
00057 severity_(FATAL),
00058 maxErrors_(0),
00059 errorCount_(0)
00060 {}
00061
00062
00063 Foam::OSstream& Foam::messageStream::operator()
00064 (
00065 const char* functionName,
00066 const char* sourceFileName,
00067 const int sourceFileLineNumber
00068 )
00069 {
00070 OSstream& os = operator OSstream&();
00071
00072 os << endl
00073 << " From function " << functionName << endl
00074 << " in file " << sourceFileName
00075 << " at line " << sourceFileLineNumber << endl
00076 << " ";
00077
00078 return os;
00079 }
00080
00081
00082 Foam::OSstream& Foam::messageStream::operator()
00083 (
00084 const string& functionName,
00085 const char* sourceFileName,
00086 const int sourceFileLineNumber
00087 )
00088 {
00089 return operator()
00090 (
00091 functionName.c_str(),
00092 sourceFileName,
00093 sourceFileLineNumber
00094 );
00095 }
00096
00097
00098 Foam::OSstream& Foam::messageStream::operator()
00099 (
00100 const char* functionName,
00101 const char* sourceFileName,
00102 const int sourceFileLineNumber,
00103 const string& ioFileName,
00104 const label ioStartLineNumber,
00105 const label ioEndLineNumber
00106 )
00107 {
00108 OSstream& os = operator OSstream&();
00109
00110 os << endl
00111 << " From function " << functionName << endl
00112 << " in file " << sourceFileName
00113 << " at line " << sourceFileLineNumber << endl
00114 << " Reading " << ioFileName;
00115
00116 if (ioStartLineNumber >= 0 && ioEndLineNumber >= 0)
00117 {
00118 os << " from line " << ioStartLineNumber
00119 << " to line " << ioEndLineNumber;
00120 }
00121 else if (ioStartLineNumber >= 0)
00122 {
00123 os << " at line " << ioStartLineNumber;
00124 }
00125
00126 os << endl << " ";
00127
00128 return os;
00129 }
00130
00131
00132 Foam::OSstream& Foam::messageStream::operator()
00133 (
00134 const char* functionName,
00135 const char* sourceFileName,
00136 const int sourceFileLineNumber,
00137 const IOstream& ioStream
00138 )
00139 {
00140 return operator()
00141 (
00142 functionName,
00143 sourceFileName,
00144 sourceFileLineNumber,
00145 ioStream.name(),
00146 ioStream.lineNumber(),
00147 -1
00148 );
00149 }
00150
00151
00152 Foam::OSstream& Foam::messageStream::operator()
00153 (
00154 const char* functionName,
00155 const char* sourceFileName,
00156 const int sourceFileLineNumber,
00157 const dictionary& dict
00158 )
00159 {
00160 return operator()
00161 (
00162 functionName,
00163 sourceFileName,
00164 sourceFileLineNumber,
00165 dict.name(),
00166 dict.startLineNumber(),
00167 dict.endLineNumber()
00168 );
00169 }
00170
00171
00172 Foam::messageStream::operator Foam::OSstream&()
00173 {
00174 if (level)
00175 {
00176 bool collect = (severity_ == INFO || severity_ == WARNING);
00177
00178
00179 if (!Pstream::master() && collect)
00180 {
00181 return Snull;
00182 }
00183 else
00184 {
00185 if (title().size())
00186 {
00187 if (Pstream::parRun() && !collect)
00188 {
00189 Pout<< title().c_str();
00190 }
00191 else
00192 {
00193 Sout<< title().c_str();
00194 }
00195 }
00196
00197 if (maxErrors_)
00198 {
00199 errorCount_++;
00200
00201 if (errorCount_ >= maxErrors_)
00202 {
00203 FatalErrorIn("messageStream::operator OSstream&()")
00204 << "Too many errors"
00205 << abort(FatalError);
00206 }
00207 }
00208
00209 if (Pstream::parRun() && !collect)
00210 {
00211 return Pout;
00212 }
00213 else
00214 {
00215 return Sout;
00216 }
00217 }
00218 }
00219
00220 return Snull;
00221 }
00222
00223
00224
00225
00226
00227 Foam::messageStream Foam::SeriousError
00228 (
00229 "--> FOAM Serious Error : ",
00230 messageStream::SERIOUS,
00231 100
00232 );
00233
00234 Foam::messageStream Foam::Warning
00235 (
00236 "--> FOAM Warning : ",
00237 messageStream::WARNING
00238 );
00239
00240 Foam::messageStream Foam::Info("", messageStream::INFO);
00241
00242
00243
Copyright © 2000-2009 OpenCFD Ltd