Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TClassEventDispatcher.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <utility>
6#include <type_traits>
7
8namespace ph::editor
9{
10
11template<typename EventType, typename ClassType>
13{
14private:
15 static_assert(std::is_class_v<ClassType>);
16
18
19public:
21
25
26 template<auto MethodPtr, typename Class>
27 Listener* addListener(Class* instancePtr);
28
31 void removeListener(Listener* listener);
32
36
37private:
38 friend ClassType;
39
44 template<typename DispatchFunc>
45 void dispatch(const EventType& e, DispatchFunc dispatchFunc);
46
47 void dispatch(const EventType& e);
48
49 DispatcherType m_dispatcher;
50};
51
52template<typename EventType, typename ClassType>
54 Listener listener)
55-> Listener*
56{
57 return m_dispatcher.addListener(std::move(listener));
58}
59
60template<typename EventType, typename ClassType>
61template<auto MethodPtr, typename Class>
63 Class* const instancePtr)
64-> Listener*
65{
66 return m_dispatcher.addListener(Listener{}.template set<MethodPtr>(instancePtr));
67}
68
69template<typename EventType, typename ClassType>
71 Listener* const listener)
72{
73 m_dispatcher.removeListener(listener);
74}
75
76template<typename EventType, typename ClassType>
78 Listener* const listener)
79{
80 m_dispatcher.removeListenerImmediately(listener);
81}
82
83template<typename EventType, typename ClassType>
84template<typename DispatchFunc>
86 const EventType& e, DispatchFunc dispatchFunc)
87{
88 m_dispatcher.dispatch(e, std::move(dispatchFunc));
89}
90
91template<typename EventType, typename ClassType>
92inline void TClassEventDispatcher<EventType, ClassType>::dispatch(
93 const EventType& e)
94{
95 m_dispatcher.dispatch(e);
96}
97
98}// end namespace ph
Definition TClassEventDispatcher.h:13
void removeListenerImmediately(Listener *listener)
Same as TEventDispatcher::removeListenerImmediately().
Definition TClassEventDispatcher.h:77
void removeListener(Listener *listener)
Same as TEventDispatcher::removeListener().
Definition TClassEventDispatcher.h:70
Listener * addListener(Listener listener)
Same as TEventDispatcher::addListener().
Definition TClassEventDispatcher.h:53
Listener * addListener(Class *instancePtr)
DispatcherType::Listener Listener
Definition TClassEventDispatcher.h:20
Definition TEventDispatcher.h:23
TEventListener< EventType > Listener
Definition TEventDispatcher.h:27
Listener * addListener(Listener listener)
Definition TEventDispatcher.h:67
Definition ph_editor.h:10