Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T>
- class Signal
- {
- public:
- void dispatch(T * e)
- {
- //copy dispatch list in case a listener remove itself
- std::vector<std::function<void(T*)>*> dispatch = mListeners;
- std::vector<std::function<void(T*)>*>::iterator it;
- for(it = dispatch.begin(); it != dispatch.end(); ++it)
- {
- (*(*it))(e);
- }
- };
- void addListener(std::function<void(T*)> * listener)
- {
- mListeners.push_back(listener);
- };
- void removeListener(std::function<void(T*)> * listener)
- {
- std::vector<std::function<void(T*)>*>::iterator it;
- for(it = mListeners.begin(); it != mListeners.end(); ++it)
- {
- if((*it) == listener)
- {
- it = mListeners.erase(it);
- break;
- }
- }
- };
- private:
- std::vector<std::function<void(T*)>*> mListeners;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement