OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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     Foam::messageStream
00027 
00028 Description
00029     Class to handle messaging in a simple, consistent stream-based
00030     manner.
00031 
00032     The messageStream class is globaly instantiated with a title string a
00033     given severity, which controls the program termination, and a number of
00034     errors before termination.  Errors, messages and other data are piped to
00035     the messageStream class in the standard manner.
00036 
00037 Usage
00038     @code
00039         messageStream << "message1" << "message2" << FoamDataType << endl;
00040     @endcode
00041 
00042 SourceFiles
00043     messageStream.C
00044 
00045 \*---------------------------------------------------------------------------*/
00046 
00047 #ifndef messageStream_H
00048 #define messageStream_H
00049 
00050 #include "label.H"
00051 #include "string.H"
00052 
00053 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00054 
00055 namespace Foam
00056 {
00057 
00058 class IOstream;
00059 class Ostream;
00060 class OSstream;
00061 class OStringStream;
00062 class dictionary;
00063 
00064 /*---------------------------------------------------------------------------*\
00065                            Class messageStream Declaration
00066 \*---------------------------------------------------------------------------*/
00067 
00068 class messageStream
00069 {
00070 
00071 public:
00072 
00073     //- Severity flags
00074     enum errorSeverity
00075     {
00076         INFO,       // Debugging information in event of error
00077         WARNING,    // Warning of possible problem
00078         SERIOUS,    // A serious problem (data corruption?)
00079         FATAL       // Oh bugger!
00080     };
00081 
00082 
00083 protected:
00084 
00085     // Private data
00086 
00087         string title_;
00088         errorSeverity severity_;
00089         int maxErrors_;
00090         int errorCount_;
00091 
00092 
00093 public:
00094 
00095     // Debug switches
00096 
00097         static int level;
00098 
00099 
00100     // Constructors
00101 
00102         //- Construct from components
00103         messageStream
00104         (
00105             const string& title,
00106             errorSeverity sev,
00107             const int maxErrors = 0
00108         );
00109 
00110 
00111         //- Construct from dictionary
00112         messageStream(const dictionary& dict);
00113 
00114 
00115     // Member functions
00116 
00117         //- Return the title of this error type
00118         const string& title() const
00119         {
00120             return title_;
00121         }
00122 
00123         //- Return the maximum number of errors before program termination
00124         int maxErrors() const
00125         {
00126             return maxErrors_;
00127         }
00128 
00129         //- Return non-const access to the maximum number of errors before
00130         //  program termination to enable user to reset it
00131         int& maxErrors()
00132         {
00133             return maxErrors_;
00134         }
00135 
00136         //- Convert to Ostream
00137         //  Prints basic message and then returns Ostream for further info.
00138         OSstream& operator()
00139         (
00140             const char* functionName,
00141             const char* sourceFileName,
00142             const int sourceFileLineNumber = 0
00143         );
00144 
00145         OSstream& operator()
00146         (
00147             const string& functionName,
00148             const char* sourceFileName,
00149             const int sourceFileLineNumber = 0
00150         );
00151 
00152         //- Convert to Ostream
00153         //  Prints basic message and then returns Ostream for further info.
00154         OSstream& operator()
00155         (
00156             const char* functionName,
00157             const char* sourceFileName,
00158             const int sourceFileLineNumber,
00159             const string& ioFileName,
00160             const label ioStartLineNumber = -1,
00161             const label ioEndLineNumber = -1
00162         );
00163 
00164         //- Convert to Ostream
00165         //  Prints basic message and then returns Ostream for further info.
00166         OSstream& operator()
00167         (
00168             const char* functionName,
00169             const char* sourceFileName,
00170             const int sourceFileLineNumber,
00171             const IOstream&
00172         );
00173 
00174         //- Convert to Ostream
00175         //  Prints basic message and then returns Ostream for further info.
00176         OSstream& operator()
00177         (
00178             const char* functionName,
00179             const char* sourceFileName,
00180             const int sourceFileLineNumber,
00181             const dictionary&
00182         );
00183 
00184         //- Convert to Ostream for << operations
00185         operator OSstream&();
00186 
00187         //- Explicitly convert to Ostream for << operations
00188         OSstream& operator()()
00189         {
00190             return operator OSstream&();
00191         }
00192 };
00193 
00194 
00195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00196 // Global error declarations: defined in messageStream.C
00197 
00198 extern messageStream SeriousError;
00199 extern messageStream Warning;
00200 extern messageStream Info;
00201 
00202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00203 // Convienient macros to add the file name and line number to the function name
00204 
00205 #define SeriousErrorIn(fn) SeriousError(fn, __FILE__, __LINE__)
00206 #define SeriousIOErrorIn(fn, ios) SeriousError(fn, __FILE__, __LINE__, ios)
00207 
00208 #define WarningIn(fn) Warning(fn, __FILE__, __LINE__)
00209 #define IOWarningIn(fn, ios) Warning(fn, __FILE__, __LINE__, ios)
00210 
00211 #define InfoIn(fn) Info(fn, __FILE__, __LINE__)
00212 #define IOInfoIn(fn, ios) Info(fn, __FILE__, __LINE__, ios)
00213 
00214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00215 
00216 } // End namespace Foam
00217 
00218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00219 
00220 #include "OSstream.H"
00221 
00222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00223 
00224 #endif
00225 
00226 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd