ware/WareException.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   \file WareException.hpp
00035   \brief Header of ...
00036 
00037   \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00038  */
00039 
00040 
00041 #ifndef __WAREEXCEPTION_HPP__
00042 #define __WAREEXCEPTION_HPP__
00043 
00044 #include <openfluid/base/Exception.hpp>
00045 #include <openfluid/base/SimulationStatus.hpp>
00046 #include <openfluid/ware/WareSignature.hpp>
00047 #include <openfluid/ware/PluggableWare.hpp>
00048 #include <openfluid/dllexport.hpp>
00049 
00050 namespace openfluid { namespace ware {
00051 
00052 
00053 class DLLEXPORT WareException : public openfluid::base::Exception
00054 {
00055   protected:
00056 
00057     PluggableWare::WareType m_WareType;
00058 
00059     openfluid::base::SimulationStatus::SimulationStage m_Stage;
00060 
00061     openfluid::core::TimeIndex_t m_TimeIndex;
00062 
00063     bool m_IsTimeIndexed;
00064 
00065     void buildFullMessage()
00066     {
00067       if (m_Source.empty())
00068         m_Source = "unknown source";
00069 
00070       m_FullMessage = m_Message;
00071 
00072       m_FullMessage += " (sent by " + m_Sender;
00073       if (m_WareType == PluggableWare::SIMULATOR)
00074         m_FullMessage += " simulator";
00075       if (m_WareType == PluggableWare::OBSERVER)
00076         m_FullMessage += " observer";
00077 
00078       if (m_Source != "")
00079         m_FullMessage += ", from " + m_Source;
00080 
00081       if (m_IsTimeIndexed)
00082       {
00083         std::stringstream StrStream;
00084         StrStream << m_TimeIndex;
00085         m_FullMessage += ", at time index #" + StrStream.str();
00086       }
00087 
00088       m_FullMessage += ")";
00089     }
00090 
00091 
00092 
00093   public:
00094 
00095     static void updateSourceInfo(const PluggableWare::WareType& WType,
00096                                  const openfluid::base::SimulationStatus::SimulationStage& Stage,
00097                                  std::string& SourceStr)
00098     {
00099       SourceStr = "unknown source";
00100 
00101       if (WType == PluggableWare::OBSERVER)
00102       {
00103         switch (Stage)
00104         {
00105           case openfluid::base::SimulationStatus::INITPARAMS : SourceStr = "initParams"; break;
00106           case openfluid::base::SimulationStatus::PREPAREDATA : SourceStr = "onPrepared"; break;
00107           case openfluid::base::SimulationStatus::CHECKCONSISTENCY : SourceStr = "onPrepared"; break;
00108           case openfluid::base::SimulationStatus::INITIALIZERUN : SourceStr = "onInitializedRun"; break;
00109           case openfluid::base::SimulationStatus::RUNSTEP : SourceStr = "onStepCompleted"; break;
00110           case openfluid::base::SimulationStatus::FINALIZERUN : SourceStr = "onFinalizedRun"; break;
00111           default : break;
00112         }
00113       }
00114       else if (WType == PluggableWare::SIMULATOR)
00115       {
00116         switch (Stage)
00117         {
00118           case openfluid::base::SimulationStatus::INITPARAMS : SourceStr = "initParams"; break;
00119           case openfluid::base::SimulationStatus::PREPAREDATA : SourceStr = "prepareData"; break;
00120           case openfluid::base::SimulationStatus::CHECKCONSISTENCY : SourceStr = "checkConsistency"; break;
00121           case openfluid::base::SimulationStatus::INITIALIZERUN : SourceStr = "initializeRun"; break;
00122           case openfluid::base::SimulationStatus::RUNSTEP : SourceStr = "runStep"; break;
00123           case openfluid::base::SimulationStatus::FINALIZERUN : SourceStr = "finalizeRun"; break;
00124           default : break;
00125         }
00126       }
00127     }
00128 
00129 
00130     WareException(const WareID_t& ID,
00131                   const PluggableWare::WareType& WType,
00132                   const std::string& Source,
00133                   const std::string& Msg) :
00134       openfluid::base::Exception(ID,Msg), m_WareType(WType), m_Stage(openfluid::base::SimulationStatus::UNKNOWN),
00135       m_TimeIndex(0), m_IsTimeIndexed(false)
00136     {
00137       m_Source = Source;
00138       buildFullMessage();
00139     }
00140 
00141 
00142     WareException(const WareID_t& ID,
00143                   const PluggableWare::WareType& WType,
00144                   const openfluid::base::SimulationStatus::SimulationStage& Stage,
00145                   const std::string& Msg) :
00146       openfluid::base::Exception(ID,Msg), m_WareType(WType), m_Stage(Stage), m_TimeIndex(0), m_IsTimeIndexed(false)
00147     {
00148       updateSourceInfo(WType,Stage,m_Source);
00149       buildFullMessage();
00150     }
00151 
00152 
00153     WareException(const WareID_t& ID,
00154                   const PluggableWare::WareType& WType,
00155                   const std::string& Source,
00156                   const openfluid::core::TimeIndex_t& TimeIndex,
00157                   const std::string& Msg) :
00158       openfluid::base::Exception(ID,Msg), m_WareType(WType), m_Stage(openfluid::base::SimulationStatus::UNKNOWN),
00159       m_TimeIndex(TimeIndex), m_IsTimeIndexed(true)
00160     {
00161       m_Source = Source;
00162       buildFullMessage();
00163     }
00164 
00165 
00166     WareException(const WareID_t& ID,
00167                   const PluggableWare::WareType& WType,
00168                   const openfluid::base::SimulationStatus::SimulationStage& Stage,
00169                   const openfluid::core::TimeIndex_t& TimeIndex,
00170                   const std::string& Msg) :
00171       openfluid::base::Exception(ID,Msg), m_WareType(WType), m_Stage(Stage),
00172       m_TimeIndex(TimeIndex), m_IsTimeIndexed(true)
00173     {
00174       updateSourceInfo(WType,Stage,m_Source);
00175       buildFullMessage();
00176     }
00177 
00178 };
00179 
00180 
00181 } } // namespaces
00182 
00183 
00184 
00185 
00186 #endif /* __WAREEXCEPTION_HPP__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines