diff options
author | kruall <kruall@ydb.tech> | 2023-11-10 13:05:28 +0300 |
---|---|---|
committer | kruall <kruall@ydb.tech> | 2023-11-10 13:41:58 +0300 |
commit | d84527173e1f76f9a00ffdef14af1c49cb8a502d (patch) | |
tree | 14f3e683744ec9eee2d217e11d02d2257405abc9 /library/cpp/actors/core/actor.h | |
parent | 4c800ac80af5ac83fcc772491904d0aa8e87949c (diff) | |
download | ydb-d84527173e1f76f9a00ffdef14af1c49cb8a502d.tar.gz |
Check stateFunc type before assign it, KIKIMR-19280
Diffstat (limited to 'library/cpp/actors/core/actor.h')
-rw-r--r-- | library/cpp/actors/core/actor.h | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/library/cpp/actors/core/actor.h b/library/cpp/actors/core/actor.h index 7452b50571..96a8f5d05a 100644 --- a/library/cpp/actors/core/actor.h +++ b/library/cpp/actors/core/actor.h @@ -651,6 +651,8 @@ namespace NActors { template <typename TDerived> class TActor: public IActorCallback { private: + using TDerivedReceiveFunc = void (TDerived::*)(TAutoPtr<IEventHandle>& ev); + template <typename T, typename = const char*> struct HasActorName: std::false_type {}; template <typename T> @@ -682,21 +684,56 @@ namespace NActors { protected: // static constexpr char ActorName[] = "UNNAMED"; - TActor(void (TDerived::* func)(TAutoPtr<IEventHandle>& ev)) + TActor(TDerivedReceiveFunc func) : IActorCallback(static_cast<TReceiveFunc>(func), GetActivityTypeIndex()) { } template <class TEnum = EActivityType> - TActor(void (TDerived::* func)(TAutoPtr<IEventHandle>& ev), const TEnum activityEnumType = EActivityType::OTHER) + TActor(TDerivedReceiveFunc func, const TEnum activityEnumType = EActivityType::OTHER) : IActorCallback(static_cast<TReceiveFunc>(func), activityEnumType) { } - TActor(void (TDerived::* func)(TAutoPtr<IEventHandle>& ev), const TString& actorName) + TActor(TDerivedReceiveFunc func, const TString& actorName) : IActorCallback(static_cast<TReceiveFunc>(func), TLocalProcessKeyState<TActorActivityTag>::GetInstance().Register(actorName)) { } public: typedef TDerived TThis; + + // UnsafeBecome methods don't verify the bindings of the stateFunc to the TDerived + template <typename T> + void UnsafeBecome(T stateFunc) { + this->IActorCallback::Become(stateFunc); + } + + template <typename T, typename... TArgs> + void UnsafeBecome(T stateFunc, const TActorContext& ctx, TArgs&&... args) { + this->IActorCallback::Become(stateFunc, ctx, std::forward<TArgs>(args)...); + } + + template <typename T, typename... TArgs> + void UnsafeBecome(T stateFunc, TArgs&&... args) { + this->IActorCallback::Become(stateFunc, std::forward<TArgs>(args)...); + } + + template <typename T> + void Become(T stateFunc) { + // TODO(kruall): have to uncomment asserts after end of sync contrib/ydb + // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>); + this->IActorCallback::Become(stateFunc); + } + + template <typename T, typename... TArgs> + void Become(T stateFunc, const TActorContext& ctx, TArgs&&... args) { + // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>); + this->IActorCallback::Become(stateFunc, ctx, std::forward<TArgs>(args)...); + } + + template <typename T, typename... TArgs> + void Become(T stateFunc, TArgs&&... args) { + // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>); + this->IActorCallback::Become(stateFunc, std::forward<TArgs>(args)...); + } }; |