summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorazevaykin <[email protected]>2023-12-05 11:59:32 +0300
committerazevaykin <[email protected]>2023-12-05 13:27:44 +0300
commit1d17d3cbd320ede2a343f42894abd095b96d832c (patch)
treea07b054cdc7c20a0f8b70043086db12c9cec0d66
parent4ff6a4d9aec2ce6fe4297433c90df34fd86a6b12 (diff)
IEventHandle Upcast/Downcast
https://a.yandex-team.ru/review/4895257/details#comment-7227783
-rw-r--r--ydb/library/actors/core/event.h29
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>