Skip to content

Commit

Permalink
Add ways to construct cluster structs from the shared superclass. (#2…
Browse files Browse the repository at this point in the history
…6763)

* 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.
  • Loading branch information
bzbarsky-apple authored May 26, 2023
1 parent b1a373b commit 19ae369
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19ae369

Please sign in to comment.