AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
observerList.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <algorithm>
23#include <atomic>
24#include <cstddef>
25#include <cstdint>
26#include <memory>
27#include <mutex>
28#include <vector>
29
30#include "events/event.hpp"
31#include "events/observer.hpp"
32
33namespace anch::events {
34
53 template<typename T>
55
56 // Attributes +
57 private:
59 std::mutex _mutex;
60
62 std::shared_ptr<const std::vector<anch::events::Observer<T>*>> _observers;
63
65 std::atomic<std::size_t> _active;
66
68 std::atomic<uint64_t> _removals;
69 // Attributes -
70
71 // Constructors +
72 public:
77
81 ObserverList(const ObserverList&) = delete;
82 // Constructors -
83
84 // Destructor +
85 public:
89 ~ObserverList() = default;
90 // Destructor -
91
92 // Operators +
93 public:
98 // Operators -
99
100 // Methods +
101 public:
110
118
124 void notify(const anch::events::Event<T>& event);
125
126 private:
132 std::size_t currentThreadNotifications() const;
133 // Methods -
134
135 };
136
137}
138
139#include "events/impl/observerList.hpp"
An observer interface of the observers/observable design pattern.
Definition observer.hpp:42
ObserverList(const ObserverList &)=delete
void remove(anch::events::Observer< T > &observer)
void notify(const anch::events::Event< T > &event)
bool add(anch::events::Observer< T > &observer)
ObserverList & operator=(const ObserverList &)=delete
Events management namespace.
Definition event.hpp:25
Event representation.
Definition event.hpp:37