FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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