base/SimulationLogger.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 
00033 
00034 /**
00035   @file
00036 
00037   @author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00038 */
00039 
00040 
00041 #ifndef __SIMULATIONLOGGER_HPP__
00042 #define __SIMULATIONLOGGER_HPP__
00043 
00044 #include <string>
00045 #include <fstream>
00046 
00047 #include <openfluid/dllexport.hpp>
00048 #include <openfluid/core/TypeDefs.hpp>
00049 #include <openfluid/core/DateTime.hpp>
00050 
00051 #include <openfluid/tools/SwissTools.hpp>
00052 
00053 
00054 namespace openfluid { namespace base {
00055 
00056 /**
00057   Class for managing messages during execution
00058 
00059   @author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00060 */
00061 class DLLEXPORT SimulationLogger
00062 {
00063 
00064   private:
00065 
00066     std::ofstream m_LogFile;
00067 
00068     bool m_WarningFlag;
00069 
00070     unsigned int m_RealWarningsCount;
00071 
00072     void addLog(const std::string& Prefix,
00073                     const std::string& Sender,
00074                     const std::string& Source,
00075                     const openfluid::core::TimeIndex_t& TimeIndex,
00076                     const std::string& Msg);
00077 
00078     void addLog(const std::string& Prefix,
00079                     const std::string& Sender,
00080                     const openfluid::core::TimeIndex_t& TimeIndex,
00081                     const std::string& Msg);
00082 
00083     void addLog(const std::string& Prefix,
00084                     const std::string& Sender,
00085                     const std::string& Source,
00086                     const std::string& Msg);
00087 
00088     void addLog(const std::string& Prefix,
00089                     const std::string& Sender,
00090                     const std::string& Msg);
00091 
00092     void addLog(const std::string& Prefix,
00093                     const std::string& Msg);
00094 
00095 
00096   public:
00097 
00098     SimulationLogger(const std::string& LogFilePath);
00099 
00100 
00101     ~SimulationLogger();
00102 
00103 
00104     void addWarning(const std::string& Sender, const std::string& Source, const openfluid::core::TimeIndex_t& TimeIndex, const std::string& Msg)
00105     { addLog("[Warning]",Sender,Source, TimeIndex, Msg); m_WarningFlag = true; m_RealWarningsCount++; };
00106 
00107 
00108     void addWarning(const std::string& Sender, const openfluid::core::TimeIndex_t& TimeIndex, const std::string& Msg)
00109     { addLog("[Warning]",Sender,TimeIndex, Msg); m_WarningFlag = true; m_RealWarningsCount++; };
00110 
00111 
00112     void addWarning(const std::string& Sender, const std::string& Source, const std::string& Msg)
00113     { addLog("[Warning]",Sender,Source,Msg); m_WarningFlag = true; m_RealWarningsCount++; };
00114 
00115 
00116     void addWarning(const std::string& Sender, const std::string& Msg)
00117     { addLog("[Warning]",Sender,Msg); m_WarningFlag = true; m_RealWarningsCount++; };
00118 
00119 
00120     void addMessage(const std::string& Sender, const std::string& Source, const openfluid::core::TimeIndex_t& TimeIndex, const std::string& Msg)
00121     { addLog("[Message]",Sender,Source, TimeIndex, Msg); };
00122 
00123 
00124     void addMessage(const std::string& Sender, const openfluid::core::TimeIndex_t& TimeIndex, const std::string& Msg)
00125     { addLog("[Message]",Sender, TimeIndex, Msg); };
00126 
00127 
00128     void addMessage(const std::string& Sender, const std::string& Source, const std::string& Msg)
00129     { addLog("[Message]",Sender,Source, Msg); };
00130 
00131 
00132     void addMessage(const std::string& Sender, const std::string& Msg)
00133     { addLog("[Message]",Sender,Msg); };
00134 
00135 
00136     void addInfo(const std::string& Sender, const std::string& Msg)
00137     { addLog("[Info]",Sender,Msg); };
00138 
00139 
00140     void addInfo(const std::string& Msg)
00141     { addLog("[Info]",Msg); };
00142 
00143 
00144     inline void resetWarningFlag() { m_WarningFlag = false; };
00145 
00146 
00147     inline bool isWarningFlag() const { return m_WarningFlag; };
00148 
00149 
00150     inline unsigned int getWarningsCount() const { return m_RealWarningsCount; };
00151 
00152 };
00153 
00154 
00155 } } // namespaces
00156 
00157 
00158 #endif /*__SIMULATIONLOGGER_HPP__*/
00159 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines