Skip to content

Commit

Permalink
Improve handling of single structs associated with many clusters. (#2…
Browse files Browse the repository at this point in the history
…6495)

Instead of having a single set of types under "namespace detail" plus namespace
aliases, have actual distinct types in the distinct cluster namespaces, with a
common super-class in the detail namespace to improve code sharing.  This
still leaves the fields enums as an alias of the detail bits, but people are
unlikely to be dispatching to overloads on the type of that fields enum.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Dec 20, 2023
1 parent c5ad0cf commit 2240226
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 162 deletions.
8 changes: 0 additions & 8 deletions examples/chip-tool/templates/ComplexArgumentParser-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

#include <commands/clusters/ComplexArgument.h>

{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_parser_impl namespace="detail"}}
{{/if}}
{{/zcl_structs}}

{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_parser_impl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_clusters}}
8 changes: 0 additions & 8 deletions examples/chip-tool/templates/ComplexArgumentParser.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@
#include <lib/core/CHIPError.h>
#include <app-common/zap-generated/cluster-objects.h>

{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_parser_decl namespace="detail"}}
{{/if}}
{{/zcl_structs}}

{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_parser_decl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_clusters}}
8 changes: 0 additions & 8 deletions examples/chip-tool/templates/logging/DataModelLogger-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@

using namespace chip::app::Clusters;

{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_impl namespace="detail"}}
{{/if}}
{{/zcl_structs}}

{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_logger_impl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_clusters}}

Expand Down
8 changes: 0 additions & 8 deletions examples/chip-tool/templates/logging/DataModelLogger.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
#include <lib/core/CHIPError.h>
#include <app-common/zap-generated/cluster-objects.h>

{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_decl namespace="detail"}}
{{/if}}
{{/zcl_structs}}

{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_logger_decl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_clusters}}

Expand Down
19 changes: 18 additions & 1 deletion src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,24 @@ namespace {{asUpperCamelCase name}} {
namespace Structs {
{{/first}}
{{#if has_more_than_one_cluster}}
namespace {{asUpperCamelCase name}} = Clusters::detail::Structs::{{asUpperCamelCase name}};
namespace {{asUpperCamelCase name}} {

using Fields = Clusters::detail::Structs::{{asUpperCamelCase name}}::Fields;

struct Type : public Clusters::detail::Structs::{{asUpperCamelCase name}}::Type
{
};

{{#if struct_contains_array}}
struct DecodableType : public Clusters::detail::Structs::{{asUpperCamelCase name}}::DecodableType
{
};
{{else}}
using DecodableType = Type;
{{/if}}

} // namespace {{asUpperCamelCase name}}

{{else}}
{{> cluster_objects_struct header=true}}
{{/if}}
Expand Down

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

182 changes: 122 additions & 60 deletions zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp

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

Loading

0 comments on commit 2240226

Please sign in to comment.