OpenBarnyard
 
Loading...
Searching...
No Matches
TGlobalEmitter.h
Go to the documentation of this file.
1#pragma once
2#include "TQList.h"
3
5
6template <class T>
7class TGenericGlobalListener : public TQList<TGenericGlobalListener<T>>::TNode
8{
9public:
10 using EventCallback = void ( * )( void*, const T& );
11
12 template <class T>
13 friend class TGlobalEmitter;
14
15protected:
21
22 void Execute( const T& a_rData )
23 {
24 m_fnCallback( m_pReceiver, a_rData );
25 }
26
27 void ConnectImpl( void* pReceiver, EventCallback fnCallback );
29
30protected:
33};
34
35template <class T>
37{
38public:
39 class ListenerList : public Toshi::TQList<TGenericGlobalListener<T>>
40 {
41 public:
42 };
43
44public:
45 static void Throw( const T& a_rData )
46 {
47 for ( auto it = sm_oListeners.Begin(); it != sm_oListeners.End(); ++it )
48 {
49 it->Execute( a_rData );
50 }
51 }
52
53public:
55};
56
57template <class ReceiverType, class EventType>
58class TGlobalListener : public TGenericGlobalListener<EventType>
59{
60public:
61 void Connect( ReceiverType* receiver, TGenericGlobalListener<EventType>::EventCallback callback )
62 {
64 }
65
70};
71
72template <class T>
73inline void TGenericGlobalListener<T>::ConnectImpl( void* pReceiver, EventCallback fnCallback )
74{
76 m_pReceiver = pReceiver;
77 m_fnCallback = fnCallback;
79}
80
81template <class T>
88
93{
94public:
95 TGenericGlobalEvent( const void* a_pData )
96 : m_pData( a_pData ) {}
97
98public:
99 const void* m_pData;
100};
101
105template <class T>
107{
108public:
109 virtual void ThrowGlobal() const
110 {
111 TGlobalEmitter<T>::Throw( *TSTATICCAST( const T, this ) );
113 }
114};
115
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TNULL
Definition Typedefs.h:23
void(*)(void *, const T &) EventCallback
void ConnectImpl(void *pReceiver, EventCallback fnCallback)
EventCallback m_fnCallback
friend class TGlobalEmitter
void Execute(const T &a_rData)
static void Throw(const T &a_rData)
static ListenerList sm_oListeners
void Connect(ReceiverType *receiver, TGenericGlobalListener< EventType >::EventCallback callback)
Used to catch all events that are thrown from TGlobalEvent.
TGenericGlobalEvent(const void *a_pData)
Use as a parent class for classes that are global events.
virtual void ThrowGlobal() const
friend TQList
Definition TQList.h:13