From 19ae369ee57b828b3934bea599f1e2d000d32730 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 26 May 2023 09:38:35 -0400 Subject: [PATCH] Add ways to construct cluster structs from the shared superclass. (#26763) * Add ways to construct cluster structs from the shared superclass. This is only relevant when a struct is being shared across multiple clusters. * Address review comment. --- .../templates/app/cluster-objects.zapt | 16 +++++++ .../zap-generated/cluster-objects.h | 44 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/app/zap-templates/templates/app/cluster-objects.zapt b/src/app/zap-templates/templates/app/cluster-objects.zapt index e8ffcc3b9bc2a7..fbe6e0a320b3c9 100644 --- a/src/app/zap-templates/templates/app/cluster-objects.zapt +++ b/src/app/zap-templates/templates/app/cluster-objects.zapt @@ -58,13 +58,29 @@ namespace {{asUpperCamelCase name}} { using Fields = Clusters::detail::Structs::{{asUpperCamelCase name}}::Fields; +// This is a struct type shared across multiple clusters. Create a type-safe +// declaration in this cluster namespace (so not just pulling in the shared +// implementation via "using", but make sure we can initialize our +// Type/DecodableType from the generic Type/DecodableType as needed. struct Type : public Clusters::detail::Structs::{{asUpperCamelCase name}}::Type { +private: + using Super = Clusters::detail::Structs::{{asUpperCamelCase name}}::Type; +public: + constexpr Type() = default; + constexpr Type(const Super & arg) : Super(arg) {} + constexpr Type(Super && arg) : Super(std::move(arg)) {} }; {{#if struct_contains_array}} struct DecodableType : public Clusters::detail::Structs::{{asUpperCamelCase name}}::DecodableType { +private: + using Super = Clusters::detail::Structs::{{asUpperCamelCase name}}::DecodableType; +public: + DecodableType() = default; + DecodableType(const Super & arg) : Super(arg) {} + DecodableType(Super && arg) : Super(std::move(arg)) {} }; {{else}} using DecodableType = Type; diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index 8ce9f499da8934..6a4a2949da3c05 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -13180,8 +13180,19 @@ namespace LabelStruct { using Fields = Clusters::detail::Structs::LabelStruct::Fields; +// This is a struct type shared across multiple clusters. Create a type-safe +// declaration in this cluster namespace (so not just pulling in the shared +// implementation via "using", but make sure we can initialize our +// Type/DecodableType from the generic Type/DecodableType as needed. struct Type : public Clusters::detail::Structs::LabelStruct::Type { +private: + using Super = Clusters::detail::Structs::LabelStruct::Type; + +public: + constexpr Type() = default; + constexpr Type(const Super & arg) : Super(arg) {} + constexpr Type(Super && arg) : Super(std::move(arg)) {} }; using DecodableType = Type; @@ -13267,8 +13278,19 @@ namespace LabelStruct { using Fields = Clusters::detail::Structs::LabelStruct::Fields; +// This is a struct type shared across multiple clusters. Create a type-safe +// declaration in this cluster namespace (so not just pulling in the shared +// implementation via "using", but make sure we can initialize our +// Type/DecodableType from the generic Type/DecodableType as needed. struct Type : public Clusters::detail::Structs::LabelStruct::Type { +private: + using Super = Clusters::detail::Structs::LabelStruct::Type; + +public: + constexpr Type() = default; + constexpr Type(const Super & arg) : Super(arg) {} + constexpr Type(Super && arg) : Super(std::move(arg)) {} }; using DecodableType = Type; @@ -27013,8 +27035,19 @@ namespace ApplicationStruct { using Fields = Clusters::detail::Structs::ApplicationStruct::Fields; +// This is a struct type shared across multiple clusters. Create a type-safe +// declaration in this cluster namespace (so not just pulling in the shared +// implementation via "using", but make sure we can initialize our +// Type/DecodableType from the generic Type/DecodableType as needed. struct Type : public Clusters::detail::Structs::ApplicationStruct::Type { +private: + using Super = Clusters::detail::Structs::ApplicationStruct::Type; + +public: + constexpr Type() = default; + constexpr Type(const Super & arg) : Super(arg) {} + constexpr Type(Super && arg) : Super(std::move(arg)) {} }; using DecodableType = Type; @@ -27299,8 +27332,19 @@ namespace ApplicationStruct { using Fields = Clusters::detail::Structs::ApplicationStruct::Fields; +// This is a struct type shared across multiple clusters. Create a type-safe +// declaration in this cluster namespace (so not just pulling in the shared +// implementation via "using", but make sure we can initialize our +// Type/DecodableType from the generic Type/DecodableType as needed. struct Type : public Clusters::detail::Structs::ApplicationStruct::Type { +private: + using Super = Clusters::detail::Structs::ApplicationStruct::Type; + +public: + constexpr Type() = default; + constexpr Type(const Super & arg) : Super(arg) {} + constexpr Type(Super && arg) : Super(std::move(arg)) {} }; using DecodableType = Type;