All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WareException.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  \file WareException.hpp
35  \brief Header of ...
36 
37  \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __WAREEXCEPTION_HPP__
42 #define __WAREEXCEPTION_HPP__
43 
48 #include <openfluid/dllexport.hpp>
49 
50 namespace openfluid { namespace ware {
51 
52 
54 {
55  protected:
56 
58 
60 
62 
64 
66  {
67  if (m_Source.empty())
68  m_Source = "unknown source";
69 
70  m_FullMessage = m_Message;
71 
72  m_FullMessage += " (sent by " + m_Sender;
73  if (m_WareType == PluggableWare::SIMULATOR)
74  m_FullMessage += " simulator";
75  if (m_WareType == PluggableWare::OBSERVER)
76  m_FullMessage += " observer";
77 
78  if (m_Source != "")
79  m_FullMessage += ", from " + m_Source;
80 
81  if (m_IsTimeIndexed)
82  {
83  std::stringstream StrStream;
84  StrStream << m_TimeIndex;
85  m_FullMessage += ", at time index #" + StrStream.str();
86  }
87 
88  m_FullMessage += ")";
89  }
90 
91 
92 
93  public:
94 
95  static void updateSourceInfo(const PluggableWare::WareType& WType,
97  std::string& SourceStr)
98  {
99  SourceStr = "unknown source";
100 
101  if (WType == PluggableWare::OBSERVER)
102  {
103  switch (Stage)
104  {
105  case openfluid::base::SimulationStatus::INITPARAMS : SourceStr = "initParams"; break;
106  case openfluid::base::SimulationStatus::PREPAREDATA : SourceStr = "onPrepared"; break;
107  case openfluid::base::SimulationStatus::CHECKCONSISTENCY : SourceStr = "onPrepared"; break;
108  case openfluid::base::SimulationStatus::INITIALIZERUN : SourceStr = "onInitializedRun"; break;
109  case openfluid::base::SimulationStatus::RUNSTEP : SourceStr = "onStepCompleted"; break;
110  case openfluid::base::SimulationStatus::FINALIZERUN : SourceStr = "onFinalizedRun"; break;
111  default : break;
112  }
113  }
114  else if (WType == PluggableWare::SIMULATOR)
115  {
116  switch (Stage)
117  {
118  case openfluid::base::SimulationStatus::INITPARAMS : SourceStr = "initParams"; break;
119  case openfluid::base::SimulationStatus::PREPAREDATA : SourceStr = "prepareData"; break;
120  case openfluid::base::SimulationStatus::CHECKCONSISTENCY : SourceStr = "checkConsistency"; break;
121  case openfluid::base::SimulationStatus::INITIALIZERUN : SourceStr = "initializeRun"; break;
122  case openfluid::base::SimulationStatus::RUNSTEP : SourceStr = "runStep"; break;
123  case openfluid::base::SimulationStatus::FINALIZERUN : SourceStr = "finalizeRun"; break;
124  default : break;
125  }
126  }
127  }
128 
129 
131  const PluggableWare::WareType& WType,
132  const std::string& Source,
133  const std::string& Msg) :
134  openfluid::base::Exception(ID,Msg), m_WareType(WType), m_Stage(openfluid::base::SimulationStatus::UNKNOWN),
135  m_TimeIndex(0), m_IsTimeIndexed(false)
136  {
137  m_Source = Source;
138  buildFullMessage();
139  }
140 
141 
143  const PluggableWare::WareType& WType,
145  const std::string& Msg) :
146  openfluid::base::Exception(ID,Msg), m_WareType(WType), m_Stage(Stage), m_TimeIndex(0), m_IsTimeIndexed(false)
147  {
148  updateSourceInfo(WType,Stage,m_Source);
149  buildFullMessage();
150  }
151 
152 
154  const PluggableWare::WareType& WType,
155  const std::string& Source,
156  const openfluid::core::TimeIndex_t& TimeIndex,
157  const std::string& Msg) :
158  openfluid::base::Exception(ID,Msg), m_WareType(WType), m_Stage(openfluid::base::SimulationStatus::UNKNOWN),
159  m_TimeIndex(TimeIndex), m_IsTimeIndexed(true)
160  {
161  m_Source = Source;
162  buildFullMessage();
163  }
164 
165 
167  const PluggableWare::WareType& WType,
169  const openfluid::core::TimeIndex_t& TimeIndex,
170  const std::string& Msg) :
171  openfluid::base::Exception(ID,Msg), m_WareType(WType), m_Stage(Stage),
172  m_TimeIndex(TimeIndex), m_IsTimeIndexed(true)
173  {
174  updateSourceInfo(WType,Stage,m_Source);
175  buildFullMessage();
176  }
177 
178 };
179 
180 
181 } } // namespaces
182 
183 
184 
185 
186 #endif /* __WAREEXCEPTION_HPP__ */
unsigned long long TimeIndex_t
Definition: DateTime.hpp:62
Definition: SimulationStatus.hpp:60
WareException(const WareID_t &ID, const PluggableWare::WareType &WType, const openfluid::base::SimulationStatus::SimulationStage &Stage, const openfluid::core::TimeIndex_t &TimeIndex, const std::string &Msg)
Definition: WareException.hpp:166
Definition: Exception.hpp:52
Header of ...
Definition: SimulationStatus.hpp:60
openfluid::base::SimulationStatus::SimulationStage m_Stage
Definition: WareException.hpp:59
Definition: PluggableWare.hpp:93
Definition: PluggableWare.hpp:93
bool m_IsTimeIndexed
Definition: WareException.hpp:63
WareType
Definition: PluggableWare.hpp:93
static void updateSourceInfo(const PluggableWare::WareType &WType, const openfluid::base::SimulationStatus::SimulationStage &Stage, std::string &SourceStr)
Definition: WareException.hpp:95
WareException(const WareID_t &ID, const PluggableWare::WareType &WType, const std::string &Source, const openfluid::core::TimeIndex_t &TimeIndex, const std::string &Msg)
Definition: WareException.hpp:153
Definition: SimulationStatus.hpp:60
void buildFullMessage()
Definition: WareException.hpp:65
Definition: SimulationStatus.hpp:60
WareException(const WareID_t &ID, const PluggableWare::WareType &WType, const openfluid::base::SimulationStatus::SimulationStage &Stage, const std::string &Msg)
Definition: WareException.hpp:142
std::string WareID_t
Definition: WareSignature.hpp:86
PluggableWare::WareType m_WareType
Definition: WareException.hpp:57
Definition: SimulationStatus.hpp:60
Definition: SimulationStatus.hpp:60
openfluid::core::TimeIndex_t m_TimeIndex
Definition: WareException.hpp:61
Header of ...
SimulationStage
Definition: SimulationStatus.hpp:60
WareException(const WareID_t &ID, const PluggableWare::WareType &WType, const std::string &Source, const std::string &Msg)
Definition: WareException.hpp:130
Header of ...
#define DLLEXPORT
Definition: dllexport.hpp:51
Definition: WareException.hpp:53