Program Listing for File event.hpp¶
↰ Return to documentation for file (/home/runner/work/Legion-Engine/Legion-Engine/legion/engine/core/events/event.hpp
)
#pragma once
#include <core/types/primitives.hpp>
#include <core/types/type_util.hpp>
#include <core/platform/platform.hpp>
#include <core/async/ring_sync_lock.hpp>
#include <unordered_map>
namespace legion::core::events
{
namespace detail
{
static async::rw_spinlock eventNameLock;
static std::unordered_map<id_type, std::string> eventNames;
template<typename T>
id_type reportEventType()
{
eventNames[typeHash<T>()] = nameOfType<T>();
return typeHash<T>();
}
}
struct event_base
{
virtual bool persistent() LEGION_IMPURE_RETURN(false);
virtual bool unique() LEGION_IMPURE_RETURN(true);
virtual ~event_base() = default;
virtual id_type get_id() LEGION_PURE;
};
template<typename Self>
struct event : public event_base
{
friend class EventBus;
inline static const id_type id = detail::reportEventType<Self>();
virtual ~event() = default;
private:
virtual id_type get_id()
{
return id;
}
};
}