version 0.4.4
controllogger.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2025 The Ikarus Developers ikarus@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
10#pragma once
11#include <chrono>
12
16
17namespace Ikarus {
18
22class ControlLogger : public Listener
23{
24public:
25 template <typename BC>
27 this->subscribe(bc, [&](ControlMessages message, const BC::State& state) { this->update(message, state); });
28 return *this;
29 }
30
37 void update(ControlMessages message, const Concepts::ControlRoutineState auto& state) {
38 switch (message) {
40 stepEnded();
41 break;
43 controlStarted(state.information.name);
44 break;
46 stepStarted(state.loadStep, state.stepSize);
47 break;
49 controlEnded(state.information.totalIterations, state.information.name);
50 break;
51 default:
52 break; // default: do nothing when notified
53 }
54 }
55
56private:
57 using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>;
58 TimePoint start_{};
59 TimePoint stop_{};
60 std::chrono::milliseconds duration_{};
61
62 void stepEnded();
63 void controlStarted(const std::string& name);
64 void controlEnded(int totalIterations, const std::string& name);
65 void stepStarted(int stepNumber, double stepSize);
66};
67} // namespace Ikarus
Enums for observer messages.
Implementation of the observer design pattern with broadcasters.
Definition: assemblermanipulatorbuildingblocks.hh:22
ControlMessages
Enum class defining control-routine-related messages.
Definition: broadcastermessages.hh:18
Implementation of an observer for logging control routines.
Definition: controllogger.hh:23
ControlLogger & subscribeTo(BC &bc)
Definition: controllogger.hh:26
void update(ControlMessages message, const Concepts::ControlRoutineState auto &state)
Implementation of the update method for logging control messages with a control routine state.
Definition: controllogger.hh:37
Implements a listener.
Definition: listener.hh:28
auto subscribe(Broadcaster &broadcaster, std::function< void(typename Broadcaster::MessageType, const typename Broadcaster::State &)> callback)
Function to subscribe to a broadcaster with a given function (either a lambda, std::function or funct...
Definition: listener.hh:41
Concept to check if a type represents a control routine state.
Definition: utils/concepts.hh:649
Several concepts.