version 0.4.1
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
27template <typename M>
28class GenericObserver : public IObserver<M>
29{
30 using Messages = M;
31
32public:
42 template <typename F>
43 GenericObserver(Messages message, F&& f)
44 : message_{message},
45 f_{f} {}
46 void updateImpl(Messages message) override {
47 if (message_ == message) {
48 f_(step_);
49 ++step_;
50 }
51 }
52
53private:
54 Messages message_;
55 std::function<void(int)> f_;
56 int step_{0};
57};
58} // namespace Ikarus
Enums for observer messages.
Implementation of the observer design pattern.
Definition: assemblermanipulatorbuildingblocks.hh:22
GenericObserver class for observing specific messages.
Definition: genericobserver.hh:29
GenericObserver(Messages message, F &&f)
Constructor for GenericObserver.
Definition: genericobserver.hh:43
void updateImpl(Messages message) override
Definition: genericobserver.hh:46
Generic observer interface for the Observer design pattern. See for a description of the design patt...
Definition: observer.hh:26