Add Music fluctuations project and Chinese plan docs
This commit is contained in:
32
MVS/Music fluctuations/source/event/event.h
Normal file
32
MVS/Music fluctuations/source/event/event.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
|
||||
using ListenerID = uint64_t;
|
||||
|
||||
template<class... ArgTypes>
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
void a(){}
|
||||
using Callback = std::function<void(ArgTypes...)>;
|
||||
|
||||
ListenerID AddListener(Callback p_callback);
|
||||
|
||||
ListenerID operator+=(Callback p_callback);
|
||||
|
||||
bool RemoveListener(ListenerID p_listenerID);
|
||||
|
||||
bool operator-=(ListenerID p_listenerID);
|
||||
|
||||
void RemoveAllListeners();
|
||||
|
||||
uint64_t GetListenerCount();
|
||||
|
||||
void Invoke(ArgTypes... p_args);
|
||||
|
||||
private:
|
||||
std::unordered_map<ListenerID, Callback> m_callbacks; //存储该事件的所有监听者
|
||||
ListenerID m_availableListenerID = 0; //一个监听者ID的自增统计量
|
||||
};
|
||||
|
||||
#include"Event.inl"
|
||||
Reference in New Issue
Block a user