Molybden API
Loading...
Searching...
No Matches
event.hpp
1// Copyright (c) 2000-2023 TeamDev Ltd. 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
49 internal::EventImpl<T> impl_;
50 friend class ObservableOwner;
51};
52
53template <typename T>
54std::shared_ptr<Subscription> Event<T>::operator+=(
55 std::function<Signature> observer) {
56 return impl_ += observer;
57}
58
59template <typename T>
60void Event<T>::notify(const T& args) {
61 impl_.notify(args);
62}
63
64} // namespace molybden
65
66#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:54
void(const T &e) Signature
The observer's signature.
Definition event.hpp:30