BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / error / messageStream.C
blob8f5f6cbffa22c86c36b967f11fc6850fa0bcdc06
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "error.H"
27 #include "dictionary.H"
28 #include "Pstream.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 int Foam::messageStream::level(Foam::debug::debugSwitch("level", 2));
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 Foam::messageStream::messageStream
39     const string& title,
40     errorSeverity sev,
41     const int maxErrors
44     title_(title),
45     severity_(sev),
46     maxErrors_(maxErrors),
47     errorCount_(0)
51 Foam::messageStream::messageStream(const dictionary& dict)
53     title_(dict.lookup("title")),
54     severity_(FATAL),
55     maxErrors_(0),
56     errorCount_(0)
60 Foam::OSstream& Foam::messageStream::operator()
62     const char* functionName,
63     const char* sourceFileName,
64     const int sourceFileLineNumber
67     OSstream& os = operator OSstream&();
69     os  << endl
70         << "    From function " << functionName << endl
71         << "    in file " << sourceFileName
72         << " at line " << sourceFileLineNumber << endl
73         << "    ";
75     return os;
79 Foam::OSstream& Foam::messageStream::operator()
81     const string& functionName,
82     const char* sourceFileName,
83     const int sourceFileLineNumber
86     return operator()
87     (
88         functionName.c_str(),
89         sourceFileName,
90         sourceFileLineNumber
91     );
95 Foam::OSstream& Foam::messageStream::operator()
97     const char* functionName,
98     const char* sourceFileName,
99     const int sourceFileLineNumber,
100     const string& ioFileName,
101     const label ioStartLineNumber,
102     const label ioEndLineNumber
105     OSstream& os = operator OSstream&();
107     os  << endl
108         << "    From function " << functionName << endl
109         << "    in file " << sourceFileName
110         << " at line " << sourceFileLineNumber << endl
111         << "    Reading " << ioFileName;
113     if (ioStartLineNumber >= 0 && ioEndLineNumber >= 0)
114     {
115         os  << " from line " << ioStartLineNumber
116             << " to line " << ioEndLineNumber;
117     }
118     else if (ioStartLineNumber >= 0)
119     {
120         os  << " at line " << ioStartLineNumber;
121     }
123     os << endl  << "    ";
125     return os;
129 Foam::OSstream& Foam::messageStream::operator()
131     const char* functionName,
132     const char* sourceFileName,
133     const int sourceFileLineNumber,
134     const IOstream& ioStream
137     return operator()
138     (
139         functionName,
140         sourceFileName,
141         sourceFileLineNumber,
142         ioStream.name(),
143         ioStream.lineNumber(),
144         -1
145     );
149 Foam::OSstream& Foam::messageStream::operator()
151     const char* functionName,
152     const char* sourceFileName,
153     const int sourceFileLineNumber,
154     const dictionary& dict
157     return operator()
158     (
159         functionName,
160         sourceFileName,
161         sourceFileLineNumber,
162         dict.name(),
163         dict.startLineNumber(),
164         dict.endLineNumber()
165     );
169 Foam::messageStream::operator Foam::OSstream&()
171     if (level)
172     {
173         bool collect = (severity_ == INFO || severity_ == WARNING);
175         // Report the error
176         if (!Pstream::master() && collect)
177         {
178             return Snull;
179         }
180         else
181         {
182             if (title().size())
183             {
184                 if (Pstream::parRun() && !collect)
185                 {
186                     Pout<< title().c_str();
187                 }
188                 else
189                 {
190                     Sout<< title().c_str();
191                 }
192             }
194             if (maxErrors_)
195             {
196                 errorCount_++;
198                 if (errorCount_ >= maxErrors_)
199                 {
200                     FatalErrorIn("messageStream::operator OSstream&()")
201                         << "Too many errors"
202                         << abort(FatalError);
203                 }
204             }
206             if (Pstream::parRun() && !collect)
207             {
208                 return Pout;
209             }
210             else
211             {
212                 return Sout;
213             }
214         }
215     }
217     return Snull;
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 // Global messageStream definitions
224 Foam::messageStream Foam::SeriousError
226     "--> FOAM Serious Error : ",
227     messageStream::SERIOUS,
228     100
231 Foam::messageStream Foam::Warning
233     "--> FOAM Warning : ",
234     messageStream::WARNING
237 Foam::messageStream Foam::Info("", messageStream::INFO);
240 // ************************************************************************* //