diff options
author | babenko <babenko@yandex-team.com> | 2024-08-12 22:45:39 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2024-08-12 22:57:55 +0300 |
commit | 225a97565211be7452d2b59dcbbd2fb76ec46da8 (patch) | |
tree | b95266b8c006d35a19054ec14e7dc25ef653211f | |
parent | c1df86f69d5fe6dda5a7248f232b9f2c4adb0ef3 (diff) | |
download | ydb-225a97565211be7452d2b59dcbbd2fb76ec46da8.tar.gz |
Enable PHOENIX_DEFINE_TYPE for private types
3ca0bb475a2e2612b653fef665717b8f9bfd5562
-rw-r--r-- | yt/yt/core/phoenix/type_decl-inl.h | 6 | ||||
-rw-r--r-- | yt/yt/core/phoenix/type_def-inl.h | 12 | ||||
-rw-r--r-- | yt/yt/core/phoenix/unittests/phoenix_ut.cpp | 43 |
3 files changed, 56 insertions, 5 deletions
diff --git a/yt/yt/core/phoenix/type_decl-inl.h b/yt/yt/core/phoenix/type_decl-inl.h index e8750b31c4..e458acf303 100644 --- a/yt/yt/core/phoenix/type_decl-inl.h +++ b/yt/yt/core/phoenix/type_decl-inl.h @@ -4,7 +4,7 @@ #include "type_decl.h" #endif -namespace NYT::NPhoenix2 { +namespace NYT::NPhoenix2::NDetail { //////////////////////////////////////////////////////////////////////////////// @@ -41,6 +41,10 @@ public: \ private: \ static const ::NYT::NPhoenix2::NDetail::TRuntimeFieldDescriptorMap<type, TLoadContext>& GetRuntimeFieldDescriptorMap() +#define PHOENIX_DECLARE_FRIEND() \ + template <class T> \ + friend struct TPhoenixTypeInitializer__; + #define PHOENIX_DECLARE_TYPE(type, typeTag) \ PHOENIX_DECLARE_TYPE__IMPL(type, typeTag, ) diff --git a/yt/yt/core/phoenix/type_def-inl.h b/yt/yt/core/phoenix/type_def-inl.h index d0c50b17db..774b55e7ae 100644 --- a/yt/yt/core/phoenix/type_def-inl.h +++ b/yt/yt/core/phoenix/type_def-inl.h @@ -25,10 +25,14 @@ //////////////////////////////////////////////////////////////////////////////// #define PHOENIX_DEFINE_TYPE__STATIC_INIT(type, parenthesizedTypeArgs) \ - [[maybe_unused]] static const void* PhoenixTypeDescriptorStaticInit__ ## type = [] { \ - type PP_DEPAREN(parenthesizedTypeArgs)::GetTypeDescriptor(); \ - return nullptr; \ - }() + template <class T> \ + struct TPhoenixTypeInitializer__; \ + \ + template <> \ + struct TPhoenixTypeInitializer__<type PP_DEPAREN(parenthesizedTypeArgs)> \ + { \ + [[maybe_unused]] static inline const void* Dummy = &type PP_DEPAREN(parenthesizedTypeArgs)::GetTypeDescriptor(); \ + } #define PHOENIX_DEFINE_TYPE(type) \ PHOENIX_DEFINE_TYPE__STATIC_INIT(type, ()); \ diff --git a/yt/yt/core/phoenix/unittests/phoenix_ut.cpp b/yt/yt/core/phoenix/unittests/phoenix_ut.cpp index d0f3e1058d..3dd62ff42c 100644 --- a/yt/yt/core/phoenix/unittests/phoenix_ut.cpp +++ b/yt/yt/core/phoenix/unittests/phoenix_ut.cpp @@ -1457,5 +1457,48 @@ TEST(TPhoenixTest, Opaque) //////////////////////////////////////////////////////////////////////////////// +namespace NPrivateInner { + +class TOuter +{ +public: + static void Test() + { + TInner inner1; + inner1.A = 123; + + auto inner2 = Deserialize<TInner>(Serialize(inner1)); + EXPECT_EQ(inner1, inner2); + } + +private: + PHOENIX_DECLARE_FRIEND(); + + struct TInner + { + int A; + + bool operator==(const TInner&) const = default; + + PHOENIX_DECLARE_TYPE(TInner, 0xbca5a722); + }; +}; + +PHOENIX_DEFINE_TYPE(TOuter::TInner); + +void TOuter::TInner::RegisterMetadata(auto&& registrar) +{ + registrar.template Field<1, &TThis::A>("a")(); +} + +} // namespace NPrivateInner + +TEST(TPhoenixTest, PrivateInner) +{ + NPrivateInner::TOuter::Test(); +} + +//////////////////////////////////////////////////////////////////////////////// + } // namespace } // namespace NYT::NPhoenix2 |