version 0.4
genericobserver.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
9#pragma once
10#include <concepts>
11#include <string>
12
13#include <spdlog/spdlog.h>
14
17
18namespace Ikarus {
19
27 template <typename Messages>
28 class GenericObserver : public IObserver<Messages> {
29 public:
39 template <typename F>
40 GenericObserver(Messages p_message, F&& p_f) : message{p_message}, f{p_f} {}
41 void updateImpl(Messages p_message) override {
42 if (p_message == message) {
43 f(step);
44 ++step;
45 }
46 }
47
48 Messages message;
49 std::function<void(int)> f;
50 int step{0};
51 };
52} // namespace Ikarus
Enums for observer messages.
Implementation of the observer design pattern.
Definition: simpleassemblers.hh:21
GenericObserver class for observing specific messages.
Definition: genericobserver.hh:28
GenericObserver(Messages p_message, F &&p_f)
Constructor for GenericObserver.
Definition: genericobserver.hh:40
Messages message
Definition: genericobserver.hh:48
std::function< void(int)> f
Definition: genericobserver.hh:49
int step
Definition: genericobserver.hh:50
void updateImpl(Messages p_message) override
Definition: genericobserver.hh:41
Generic observer interface for the Observer design pattern. See for a description of the design patt...
Definition: observer.hh:25