coral
A C++ library for distributed co-simulation
logging.hpp
Go to the documentation of this file.
1 
10 #ifndef CORAL_SLAVE_LOGGING_HPP_INCLUDED
11 #define CORAL_SLAVE_LOGGING_HPP_INCLUDED
12 
13 #include <fstream>
14 #include <memory>
15 #include <string>
16 
17 #include <coral/slave/instance.hpp>
18 
19 
20 namespace coral
21 {
22 namespace slave
23 {
24 
25 
27 class LoggingInstance : public Instance
28 {
29 public:
43  explicit LoggingInstance(
45  const std::string& outputFilePrefix = std::string{});
46 
47  // slave::Instance methods.
49  void Setup(
50  const std::string& slaveName,
51  const std::string& executionName,
52  coral::model::TimePoint startTime,
53  coral::model::TimePoint stopTime,
54  bool adaptiveStepSize,
55  double relativeTolerance) override;
56  void StartSimulation() override;
57  void EndSimulation() override;
58  bool DoStep(coral::model::TimePoint currentT, coral::model::TimeDuration deltaT) override;
59  double GetRealVariable(coral::model::VariableID variable) const override;
60  int GetIntegerVariable(coral::model::VariableID variable) const override;
61  bool GetBooleanVariable(coral::model::VariableID variable) const override;
63  bool SetRealVariable(coral::model::VariableID variable, double value) override;
64  bool SetIntegerVariable(coral::model::VariableID variable, int value) override;
65  bool SetBooleanVariable(coral::model::VariableID variable, bool value) override;
66  bool SetStringVariable(coral::model::VariableID variable, const std::string& value) override;
67 
68 private:
69  std::shared_ptr<Instance> m_instance;
70  std::string m_outputFilePrefix;
71  std::ofstream m_outputStream;
72 };
73 
74 
75 }} // namespace
76 #endif // header guard
std::string GetStringVariable(coral::model::VariableID variable) const override
Returns the value of a string variable.
bool SetStringVariable(coral::model::VariableID variable, const std::string &value) override
Sets the value of a string variable.
bool SetRealVariable(coral::model::VariableID variable, double value) override
Sets the value of a real variable.
STL class.
bool SetBooleanVariable(coral::model::VariableID variable, bool value) override
Sets the value of a boolean variable.
int GetIntegerVariable(coral::model::VariableID variable) const override
Returns the value of an integer variable.
STL class.
void Setup(const std::string &slaveName, const std::string &executionName, coral::model::TimePoint startTime, coral::model::TimePoint stopTime, bool adaptiveStepSize, double relativeTolerance) override
Instructs the slave to perform pre-simulation setup and enter initialisation mode.
LoggingInstance(std::shared_ptr< Instance > instance, const std::string &outputFilePrefix=std::string{})
Constructs a LoggingInstance that wraps the given slave instance and adds logging to it...
A description of a slave type.
Definition: model.hpp:148
Definition: variable_io.hpp:28
double TimeDuration
The type used to specify (simulation) time durations.
Definition: model.hpp:56
coral::model::SlaveTypeDescription TypeDescription() const override
Returns an object that describes the slave type.
bool DoStep(coral::model::TimePoint currentT, coral::model::TimeDuration deltaT) override
Performs model calculations for the time step which starts at the time point currentT and has a durat...
void EndSimulation() override
Informs the slave that the simulation run has ended.
Defines the coral::slave::Instance interface.
bool SetIntegerVariable(coral::model::VariableID variable, int value) override
Sets the value of an integer variable.
double GetRealVariable(coral::model::VariableID variable) const override
Returns the value of a real variable.
bool GetBooleanVariable(coral::model::VariableID variable) const override
Returns the value of a boolean variable.
void StartSimulation() override
Informs the slave that the initialisation stage ends and the simulation begins.
An interface for classes that represent slave instances.
Definition: instance.hpp:42
double TimePoint
The type used to specify (simulation) time points.
Definition: model.hpp:42
A slave instance wrapper that logs variable values to a file.
Definition: logging.hpp:27