GCBM
cbmmodulebase.h
Go to the documentation of this file.
1 
9 #ifndef MOJA_MODULES_CBM_CBMMODULEBASE_H_
10 #define MOJA_MODULES_CBM_CBMMODULEBASE_H_
11 
12 #include "moja/flint/modulebase.h"
13 #include "moja/flint/flintexceptions.h"
14 #include "moja/exception.h"
15 
16 #include <boost/exception_ptr.hpp>
17 
18 namespace moja {
19 namespace modules {
20 namespace cbm {
21 
22 class CBMModuleBase : public flint::ModuleBase {
23 public:
24  virtual ~CBMModuleBase() = default;
25  void onSystemInit() override { doWithHandling([this]() { this->doSystemInit(); }); }
26  void onSystemShutdown() override { doWithHandling([this]() { this->doSystemShutdown(); }); }
27  void onLocalDomainInit() override { doWithHandling([this]() { this->doLocalDomainInit(); }); }
28  void onLocalDomainShutdown() override { doWithHandling([this]() { this->doLocalDomainShutdown(); }); }
31  void onPreTimingSequence() override { doWithHandling([this]() { this->doPreTimingSequence(); }); }
32  void onTimingInit() override { doWithHandling([this]() { this->doTimingInit(); }); }
33  void onTimingPrePostInit() override { doWithHandling([this]() { this->doTimingPrePostInit(); }); }
34  void onTimingPostInit() override { doWithHandling([this]() { this->doTimingPostInit(); }); }
35  void onTimingPostInit2() override { doWithHandling([this]() { this->doTimingPostInit2(); }); }
36  void onTimingShutdown() override { doWithHandling([this]() { this->doTimingShutdown(); }); }
37  void onTimingStep() override { doWithHandling([this]() { this->doTimingStep(); }); }
38  void onTimingPreEndStep() override { doWithHandling([this]() { this->doTimingPreEndStep(); }); }
39  void onTimingEndStep() override { doWithHandling([this]() { this->doTimingEndStep(); }); }
40  void onTimingPostStep() override { doWithHandling([this]() { this->doTimingPostStep(); }); }
41  void onOutputStep() override { doWithHandling([this]() { this->doOutputStep(); }); }
42  void onPrePostDisturbanceEvent() override { doWithHandling([this]() { this->doPrePostDisturbanceEvent(); }); }
43  void onPostDisturbanceEvent() override { doWithHandling([this]() { this->doPostDisturbanceEvent(); }); }
44  void onPostDisturbanceEvent2() override { doWithHandling([this]() { this->doPostDisturbanceEvent2(); }); }
45  void onError(std::string msg) override { doWithHandling([this, msg]() { this->doError(msg); }); }
46  void onDisturbanceEvent(DynamicVar e) override { doWithHandling([this, e]() { this->doDisturbanceEvent(e); }); }
47  void onPostNotification(short preMessageSignal) override { doWithHandling([this, preMessageSignal]() { this->doPostNotification(preMessageSignal); }); }
48 
49  virtual void doSystemInit() {}
50  virtual void doSystemShutdown() {}
51  virtual void doLocalDomainInit() {}
52  virtual void doLocalDomainShutdown() {}
55  virtual void doPreTimingSequence() {}
56  virtual void doTimingInit() {}
57  virtual void doTimingPrePostInit() {}
58  virtual void doTimingPostInit() {}
59  virtual void doTimingPostInit2() {}
60  virtual void doTimingShutdown() {}
61  virtual void doTimingStep() {}
62  virtual void doTimingPreEndStep() {}
63  virtual void doTimingEndStep() {}
64  virtual void doTimingPostStep() {}
65  virtual void doOutputStep() {}
66  virtual void doError(std::string msg) {}
67  virtual void doDisturbanceEvent(DynamicVar) {}
68  virtual void doPrePostDisturbanceEvent() {}
69  virtual void doPostDisturbanceEvent() {}
70  virtual void doPostDisturbanceEvent2() {}
71  virtual void doPostNotification(short preMessageSignal) {}
72 
73 private:
74  void doWithHandling(const std::function<void()>& fn) {
75  try {
76  fn();
77  }
78  catch (flint::SimulationError&) { throw; }
79  catch (moja::Exception& e) { raiseModuleError(e); }
80  catch (boost::exception& e) { raiseModuleError(e); }
81  catch (std::exception& e) { raiseModuleError(e); }
82  }
83 
84  void raiseModuleError(moja::Exception& e) {
85  BOOST_THROW_EXCEPTION(flint::SimulationError()
86  << flint::Details(e.displayText())
87  << flint::LibraryName("moja.modules.cbm")
88  << flint::ModuleName(metaData().moduleName)
89  << flint::ErrorCode(0));
90  }
91 
92  void raiseModuleError(boost::exception& e) {
93  BOOST_THROW_EXCEPTION(flint::SimulationError()
94  << flint::Details(boost::diagnostic_information(e))
95  << flint::LibraryName("moja.modules.cbm")
96  << flint::ModuleName(metaData().moduleName)
97  << flint::ErrorCode(0));
98  }
99 
100  void raiseModuleError(std::exception& e) {
101  BOOST_THROW_EXCEPTION(flint::SimulationError()
102  << flint::Details(e.what())
103  << flint::LibraryName("moja.modules.cbm")
104  << flint::ModuleName(metaData().moduleName)
105  << flint::ErrorCode(0));
106  }
107 };
108 
109 }}} // namespace moja::Modules::cbm
110 #endif // MOJA_MODULES_CBM_CBMMODULEBASE_H_
moja::modules::cbm::CBMModuleBase::doTimingPreEndStep
virtual void doTimingPreEndStep()
Definition: cbmmodulebase.h:62
moja::modules::cbm::CBMModuleBase::doSystemInit
virtual void doSystemInit()
Definition: cbmmodulebase.h:49
moja::modules::cbm::CBMModuleBase::doTimingPostInit
virtual void doTimingPostInit()
Definition: cbmmodulebase.h:58
moja::modules::cbm
Definition: ageclasshelper.cpp:12
moja::modules::cbm::CBMModuleBase::raiseModuleError
void raiseModuleError(moja::Exception &e)
Definition: cbmmodulebase.h:84
moja::modules::cbm::CBMModuleBase::doSystemShutdown
virtual void doSystemShutdown()
Definition: cbmmodulebase.h:50
moja::modules::cbm::CBMModuleBase::onTimingInit
void onTimingInit() override
Definition: cbmmodulebase.h:32
moja::modules::cbm::CBMModuleBase::doLocalDomainShutdown
virtual void doLocalDomainShutdown()
Definition: cbmmodulebase.h:52
moja::modules::cbm::CBMModuleBase
Definition: cbmmodulebase.h:22
moja::modules::cbm::CBMModuleBase::doLocalDomainInit
virtual void doLocalDomainInit()
Definition: cbmmodulebase.h:51
moja::modules::cbm::CBMModuleBase::onTimingEndStep
void onTimingEndStep() override
Definition: cbmmodulebase.h:39
moja::modules::cbm::CBMModuleBase::onTimingPostStep
void onTimingPostStep() override
Definition: cbmmodulebase.h:40
moja::modules::cbm::CBMModuleBase::raiseModuleError
void raiseModuleError(std::exception &e)
Definition: cbmmodulebase.h:100
moja::modules::cbm::CBMModuleBase::doLocalDomainProcessingUnitInit
virtual void doLocalDomainProcessingUnitInit()
Definition: cbmmodulebase.h:53
moja::modules::cbm::CBMModuleBase::doPostDisturbanceEvent2
virtual void doPostDisturbanceEvent2()
Definition: cbmmodulebase.h:70
moja::modules::cbm::CBMModuleBase::doTimingPostInit2
virtual void doTimingPostInit2()
Definition: cbmmodulebase.h:59
moja::modules::cbm::CBMModuleBase::onError
void onError(std::string msg) override
Definition: cbmmodulebase.h:45
moja::modules::cbm::CBMModuleBase::~CBMModuleBase
virtual ~CBMModuleBase()=default
moja::modules::cbm::CBMModuleBase::doDisturbanceEvent
virtual void doDisturbanceEvent(DynamicVar)
Definition: cbmmodulebase.h:67
moja::modules::cbm::CBMModuleBase::doTimingPrePostInit
virtual void doTimingPrePostInit()
Definition: cbmmodulebase.h:57
moja::modules::cbm::CBMModuleBase::doTimingStep
virtual void doTimingStep()
Definition: cbmmodulebase.h:61
moja::modules::cbm::CBMModuleBase::doTimingShutdown
virtual void doTimingShutdown()
Definition: cbmmodulebase.h:60
moja::modules::cbm::CBMModuleBase::doWithHandling
void doWithHandling(const std::function< void()> &fn)
Definition: cbmmodulebase.h:74
moja::modules::cbm::CBMModuleBase::onDisturbanceEvent
void onDisturbanceEvent(DynamicVar e) override
Definition: cbmmodulebase.h:46
moja::modules::cbm::CBMModuleBase::onOutputStep
void onOutputStep() override
Definition: cbmmodulebase.h:41
moja::modules::cbm::CBMModuleBase::doPrePostDisturbanceEvent
virtual void doPrePostDisturbanceEvent()
Definition: cbmmodulebase.h:68
moja::modules::cbm::CBMModuleBase::doPreTimingSequence
virtual void doPreTimingSequence()
Definition: cbmmodulebase.h:55
moja::modules::cbm::CBMModuleBase::onLocalDomainProcessingUnitShutdown
void onLocalDomainProcessingUnitShutdown() override
Definition: cbmmodulebase.h:30
moja::modules::cbm::CBMModuleBase::onTimingPostInit2
void onTimingPostInit2() override
Definition: cbmmodulebase.h:35
moja::modules::cbm::CBMModuleBase::doTimingEndStep
virtual void doTimingEndStep()
Definition: cbmmodulebase.h:63
moja::modules::cbm::CBMModuleBase::onTimingStep
void onTimingStep() override
Definition: cbmmodulebase.h:37
moja::modules::cbm::CBMModuleBase::onLocalDomainProcessingUnitInit
void onLocalDomainProcessingUnitInit() override
Definition: cbmmodulebase.h:29
moja::modules::cbm::CBMModuleBase::doTimingPostStep
virtual void doTimingPostStep()
Definition: cbmmodulebase.h:64
moja::modules::cbm::CBMModuleBase::doPostNotification
virtual void doPostNotification(short preMessageSignal)
Definition: cbmmodulebase.h:71
moja::modules::cbm::CBMModuleBase::onPostNotification
void onPostNotification(short preMessageSignal) override
Definition: cbmmodulebase.h:47
moja::modules::cbm::CBMModuleBase::doLocalDomainProcessingUnitShutdown
virtual void doLocalDomainProcessingUnitShutdown()
Definition: cbmmodulebase.h:54
moja::modules::cbm::CBMModuleBase::onPrePostDisturbanceEvent
void onPrePostDisturbanceEvent() override
Definition: cbmmodulebase.h:42
moja::modules::cbm::CBMModuleBase::raiseModuleError
void raiseModuleError(boost::exception &e)
Definition: cbmmodulebase.h:92
moja::modules::cbm::CBMModuleBase::onLocalDomainShutdown
void onLocalDomainShutdown() override
Definition: cbmmodulebase.h:28
moja::modules::cbm::CBMModuleBase::onPostDisturbanceEvent
void onPostDisturbanceEvent() override
Definition: cbmmodulebase.h:43
moja::modules::cbm::CBMModuleBase::onPreTimingSequence
void onPreTimingSequence() override
Definition: cbmmodulebase.h:31
moja::modules::cbm::CBMModuleBase::onSystemShutdown
void onSystemShutdown() override
Definition: cbmmodulebase.h:26
moja::modules::cbm::CBMModuleBase::onLocalDomainInit
void onLocalDomainInit() override
Definition: cbmmodulebase.h:27
moja::modules::cbm::CBMModuleBase::onTimingPrePostInit
void onTimingPrePostInit() override
Definition: cbmmodulebase.h:33
moja::modules::cbm::CBMModuleBase::doError
virtual void doError(std::string msg)
Definition: cbmmodulebase.h:66
moja::modules::cbm::CBMModuleBase::onTimingPreEndStep
void onTimingPreEndStep() override
Definition: cbmmodulebase.h:38
moja::modules::cbm::CBMModuleBase::doOutputStep
virtual void doOutputStep()
Definition: cbmmodulebase.h:65
moja::modules::cbm::CBMModuleBase::onTimingShutdown
void onTimingShutdown() override
Definition: cbmmodulebase.h:36
moja::modules::cbm::CBMModuleBase::onSystemInit
void onSystemInit() override
Definition: cbmmodulebase.h:25
moja::modules::cbm::CBMModuleBase::onPostDisturbanceEvent2
void onPostDisturbanceEvent2() override
Definition: cbmmodulebase.h:44
moja::modules::cbm::CBMModuleBase::doPostDisturbanceEvent
virtual void doPostDisturbanceEvent()
Definition: cbmmodulebase.h:69
moja::modules::cbm::CBMModuleBase::doTimingInit
virtual void doTimingInit()
Definition: cbmmodulebase.h:56
moja
Definition: ageclasshelper.cpp:10
moja::modules::cbm::CBMModuleBase::onTimingPostInit
void onTimingPostInit() override
Definition: cbmmodulebase.h:34