diff --git a/src/ll/api/base/Alias.h b/src/ll/api/base/Alias.h index bc9484c94d..71e384cc80 100644 --- a/src/ll/api/base/Alias.h +++ b/src/ll/api/base/Alias.h @@ -14,19 +14,35 @@ struct UntypedStorage { template [[nodiscard]] T& as() & { - return *reinterpret_cast(data); + if constexpr (std::is_reference_v) { + return **reinterpret_cast**>(data); + } else { + return *reinterpret_cast(data); + } } template [[nodiscard]] T const& as() const& { - return *reinterpret_cast(data); + if constexpr (std::is_reference_v) { + return **reinterpret_cast const**>(data); + } else { + return *reinterpret_cast(data); + } } template [[nodiscard]] T&& as() && { - return std::move(*reinterpret_cast(data)); + if constexpr (std::is_reference_v) { + return std::move(**reinterpret_cast**>(data)); + } else { + return std::move(*reinterpret_cast(data)); + } } template [[nodiscard]] T const&& as() const&& { - return std::move(*reinterpret_cast(data)); + if constexpr (std::is_reference_v) { + return std::move(**reinterpret_cast const**>(data)); + } else { + return std::move(*reinterpret_cast(data)); + } } }; diff --git a/src/ll/api/event/EventBus.cpp b/src/ll/api/event/EventBus.cpp index 7ddf88ade2..0482552f83 100644 --- a/src/ll/api/event/EventBus.cpp +++ b/src/ll/api/event/EventBus.cpp @@ -182,6 +182,27 @@ void EventBus::publish(std::string_view modName, Event& event, EventIdView const stream->publish(modName, event); } } + +coro::Generator EventBus::events(std::string_view modName) const { + std::lock_guard lock(impl->infoMutex); + if (auto it = impl->modInfos.find(modName); it != impl->modInfos.end()) { + for (auto& id : it->second.ownedEvents) { + co_yield id; + } + } +} + +coro::Generator> EventBus::events() const { + std::lock_guard lock(impl->infoMutex); + for (auto& [name, info] : impl->modInfos) { + for (auto& id : info.ownedEvents) { + co_yield {name, id}; + } + } +} + +bool EventBus::hasEvent(EventIdView const& eventId) const { return impl->events.contains(eventId); } + size_t EventBus::getListenerCount(EventIdView const& eventId) { if (eventId == EmptyEventId) { return impl->listenerInfos.size(); diff --git a/src/ll/api/event/EventBus.h b/src/ll/api/event/EventBus.h index 3b4f19019e..9ec40ddaea 100644 --- a/src/ll/api/event/EventBus.h +++ b/src/ll/api/event/EventBus.h @@ -10,6 +10,7 @@ #include "ll/api/base/Concepts.h" #include "ll/api/base/Macro.h" +#include "ll/api/coro/Generator.h" #include "ll/api/event/Event.h" #include "ll/api/event/EventId.h" #include "ll/api/event/Listener.h" @@ -61,6 +62,12 @@ class EventBus { publish(modName, event, getEventId); } + LLNDAPI coro::Generator events(std::string_view modName) const; + + LLNDAPI coro::Generator> events() const; + + LLNDAPI bool hasEvent(EventIdView const& eventId) const; + LLNDAPI size_t getListenerCount(EventIdView const&); template T>