Molybden API
Loading...
Searching...
No Matches
event.hpp
1// Copyright (c) 2000-2024 TeamDev. All rights reserved.
2// TeamDev PROPRIETARY and CONFIDENTIAL.
3// Use is subject to license terms.
4
5#ifndef MOLYBDEN_EVENT_HPP
6#define MOLYBDEN_EVENT_HPP
7
8#include <atomic>
9#include <functional>
10#include <unordered_map>
11
12#include "molybden/base/internal/event_impl.hpp"
13
14namespace molybden {
15
24template <typename T>
25class Event {
26 public:
30 using Signature = void(const T& e);
31
44 std::shared_ptr<Subscription> operator+=(std::function<Signature> observer);
45
46 private:
47 void notify(const T& args);
48 void reset();
49
50 internal::EventImpl<T> impl_;
51 friend class ObservableOwner;
52};
53
54template <typename T>
55std::shared_ptr<Subscription> Event<T>::operator+=(
56 std::function<Signature> observer) {
57 return impl_ += observer;
58}
59
60template <typename T>
61void Event<T>::notify(const T& args) {
62 impl_.notify(args);
63}
64
65template <typename T>
66void Event<T>::reset() {
67 impl_.reset();
68}
69
70} // namespace molybden
71
72#endif // MOLYBDEN_EVENT_HPP
Events allow you to be notified when something happens in Molybden.
Definition event.hpp:25
std::shared_ptr< Subscription > operator+=(std::function< Signature > observer)
Subscribes to receiving a notification when the event occurs.
Definition event.hpp:55
void(const T &e) Signature
The observer's signature.
Definition event.hpp:30