OpenFOAM logo
Open Source CFD Toolkit

messageStream.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     messageStream
00027 
00028 Description
00029     Class to handle messaging in a simple, consistent stream-based
00030     manner.  The messageStream class is globaly instantiated with a title string
00031     a given severity, which controls the program termination, and a number
00032     of errors before termination.  Errors, messages and other data are piped
00033     to the messageStream class in the standard manner.
00034 
00035 Usage
00036     messageStream << "message1" << "message2" << FoamDataType << endl;
00037 
00038 SourceFiles
00039     messageStream.C
00040 
00041 \*---------------------------------------------------------------------------*/
00042 
00043 #ifndef messageStream_H
00044 #define messageStream_H
00045 
00046 #include "string.H"
00047 #include "label.H"
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 class IOstream;
00055 class Ostream;
00056 class OSstream;
00057 class OStringStream;
00058 class dictionary;
00059 
00060 /*---------------------------------------------------------------------------*\
00061                            Class messageStream Declaration
00062 \*---------------------------------------------------------------------------*/
00063 
00064 class messageStream
00065 {
00066 
00067 public:
00068 
00069     //- Severity flags
00070     enum errorSeverity
00071     {
00072         INFO,       // Debugging information in event of error
00073         WARNING,    // Warning of possible problem
00074         SERIOUS,    // A serious problem (data corruption?)
00075         FATAL       // Oh bugger!
00076     };
00077 
00078 
00079 protected:
00080 
00081     // Private data
00082 
00083         string title_;
00084         errorSeverity severity_;
00085         int maxErrors_;
00086         int errorCount_;
00087 
00088 
00089 public:
00090 
00091     // Debug switches
00092 
00093         static int level;
00094 
00095 
00096     // Constructors
00097 
00098         //- Construct from components
00099         messageStream
00100         (
00101             const string& title,
00102             errorSeverity sev,
00103             const int maxErrors = 0
00104         );
00105 
00106 
00107         //- Construct from dictionary
00108         messageStream(const dictionary& dict);
00109 
00110 
00111     // Member functions
00112 
00113         //- Return the title of this error type
00114         const string& title() const
00115         {
00116             return title_;
00117         }
00118 
00119         //- Return the maximum number of errors before program termination
00120         int maxErrors() const
00121         {
00122             return maxErrors_;
00123         }
00124 
00125         //- Return non-const access to the maximum number of errors before 
00126         //  program termination to enable user to reset it
00127         int& maxErrors()
00128         {
00129             return maxErrors_;
00130         }
00131 
00132         //- Convert to Ostream
00133         //  Prints basic message and then returns Ostream for further info.
00134         OSstream& operator()
00135         (
00136             const char* functionName,
00137             const char* sourceFileName,
00138             const int sourceFileLineNumber = 0
00139         );
00140 
00141         OSstream& operator()
00142         (
00143             const string& functionName,
00144             const char* sourceFileName,
00145             const int sourceFileLineNumber = 0
00146         );
00147 
00148         //- Convert to Ostream
00149         //  Prints basic message and then returns Ostream for further info.
00150         OSstream& operator()
00151         (
00152             const char* functionName,
00153             const char* sourceFileName,
00154             const int sourceFileLineNumber,
00155             const string& ioFileName,
00156             const label ioStartLineNumber = -1,
00157             const label ioEndLineNumber = -1
00158         );
00159 
00160         //- Convert to Ostream
00161         //  Prints basic message and then returns Ostream for further info.
00162         OSstream& operator()
00163         (
00164             const char* functionName,
00165             const char* sourceFileName,
00166             const int sourceFileLineNumber,
00167             const IOstream&
00168         );
00169 
00170         //- Convert to Ostream
00171         //  Prints basic message and then returns Ostream for further info.
00172         OSstream& operator()
00173         (
00174             const char* functionName,
00175             const char* sourceFileName,
00176             const int sourceFileLineNumber,
00177             const dictionary&
00178         );
00179 
00180         //- Convert to Ostream
00181         //  Prints basic message and then returns Ostream for further info.
00182         operator OSstream&();
00183 };
00184 
00185 
00186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00187 // Global error declarations: defined in messageStream.C
00188 
00189 extern messageStream SeriousError;
00190 extern messageStream Warning;
00191 extern messageStream Info;
00192 
00193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00194 // Convienient macros to add the file name and line number to the function name
00195 
00196 #define SeriousErrorIn(fn) SeriousError(fn, __FILE__, __LINE__)
00197 #define SeriousIOErrorIn(fn, ios) SeriousError(fn, __FILE__, __LINE__, ios)
00198 
00199 #define WarningIn(fn) Warning(fn, __FILE__, __LINE__)
00200 #define IOWarningIn(fn, ios) Warning(fn, __FILE__, __LINE__, ios)
00201 
00202 #define InfoIn(fn) Info(fn, __FILE__, __LINE__)
00203 #define IOInfoIn(fn, ios) Info(fn, __FILE__, __LINE__, ios)
00204 
00205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00206 
00207 } // End namespace Foam
00208 
00209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00210 
00211 #include "OSstream.H"
00212 
00213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00214 
00215 #endif
00216 
00217 // ************************************************************************* //
For further information go to www.openfoam.org