diff options
| -rw-r--r-- | ydb/library/actors/core/event.h | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/ydb/library/actors/core/event.h b/ydb/library/actors/core/event.h index 3926312e978..417ef53f337 100644 --- a/ydb/library/actors/core/event.h +++ b/ydb/library/actors/core/event.h @@ -53,6 +53,9 @@ namespace NActors { virtual TEventSerializationInfo CreateSerializationInfo() const { return {}; } }; + template <typename TEventType> + class TEventHandle; + // fat handle class IEventHandle : TNonCopyable { struct TOnNondelivery { @@ -72,6 +75,27 @@ namespace NActors { return fits ? static_cast<TEv*>(Event.Get()) : nullptr; } + template <typename TEv> + inline TEv* StaticCastAsLocal() const noexcept { // blind cast + if constexpr (!std::is_same_v<TEv, IEventBase>) { + Y_DEBUG_ABORT_UNLESS(GetTypeRewrite() == TEv::EventType); + }; + + return static_cast<TEv*>(Event.Get()); + } + + template <typename TEv> + static TAutoPtr<TEventHandle<TEv>> Downcast(TAutoPtr<IEventHandle>&& ev) { + Y_DEBUG_ABORT_UNLESS(ev->GetTypeRewrite() == TEv::EventType); + + return static_cast<typename TEv::THandle*>(ev.Release()); + }; + + template <typename TEv> + static TAutoPtr<IEventHandle> Upcast(TAutoPtr<TEventHandle<TEv>>&& ev) { + return ev.Release(); + }; + template <typename TEventType> TEventType* Get() { if (Type != TEventType::EventType) @@ -324,11 +348,6 @@ namespace NActors { static TAutoPtr<T> Release(THolder<IEventHandle>& ev) { return ev->Release<T>(); } - - template <typename TEv> - inline TEv* StaticCastAsLocal() const noexcept { // blind cast - return static_cast<TEv*>(Event.Get()); - } }; template <typename TEventType> |
