Base refactor
This commit is contained in:
		@@ -1,32 +0,0 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "dawnlibs.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  template<typename ...T>
 | 
			
		||||
  class Event {
 | 
			
		||||
    private:
 | 
			
		||||
      std::hashmap<int32_t, std::function<void(T...)>> callback;
 | 
			
		||||
      int32_t nextEventId = 0;
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
      int32_t listen(const std::function <void(T...)> &callback) {
 | 
			
		||||
        this->callback.insert(std::make_pair(this->nextEventId, callback));
 | 
			
		||||
        return this->nextEventId++;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      void unlisten(int32_t id) {
 | 
			
		||||
        this->callback.erase(id);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      void trigger(T... args) {
 | 
			
		||||
        for(auto &it : this->callback) {
 | 
			
		||||
          it.second(args...);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user