Skip to content

Commit 1546024

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Improve handling of single structs associated with many clusters. (#26495)
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.
1 parent bd9b4a8 commit 1546024

File tree

10 files changed

+321
-162
lines changed

10 files changed

+321
-162
lines changed

examples/chip-tool/templates/ComplexArgumentParser-src.zapt

-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@
22

33
#include <commands/clusters/ComplexArgument.h>
44

5-
{{#zcl_structs}}
6-
{{#if has_more_than_one_cluster}}
7-
{{> struct_parser_impl namespace="detail"}}
8-
{{/if}}
9-
{{/zcl_structs}}
10-
115
{{#zcl_clusters}}
126
{{#zcl_structs}}
13-
{{#unless has_more_than_one_cluster}}
147
{{> struct_parser_impl namespace=(as_camel_cased ../name false)}}
15-
{{/unless}}
168
{{/zcl_structs}}
179
{{/zcl_clusters}}

examples/chip-tool/templates/ComplexArgumentParser.zapt

-8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55
#include <lib/core/CHIPError.h>
66
#include <app-common/zap-generated/cluster-objects.h>
77

8-
{{#zcl_structs}}
9-
{{#if has_more_than_one_cluster}}
10-
{{> struct_parser_decl namespace="detail"}}
11-
{{/if}}
12-
{{/zcl_structs}}
13-
148
{{#zcl_clusters}}
159
{{#zcl_structs}}
16-
{{#unless has_more_than_one_cluster}}
1710
{{> struct_parser_decl namespace=(as_camel_cased ../name false)}}
18-
{{/unless}}
1911
{{/zcl_structs}}
2012
{{/zcl_clusters}}

examples/chip-tool/templates/logging/DataModelLogger-src.zapt

-8
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@
44

55
using namespace chip::app::Clusters;
66

7-
{{#zcl_structs}}
8-
{{#if has_more_than_one_cluster}}
9-
{{> struct_logger_impl namespace="detail"}}
10-
{{/if}}
11-
{{/zcl_structs}}
12-
137
{{#zcl_clusters}}
148
{{#zcl_structs}}
15-
{{#unless has_more_than_one_cluster}}
169
{{> struct_logger_impl namespace=(as_camel_cased ../name false)}}
17-
{{/unless}}
1810
{{/zcl_structs}}
1911
{{/zcl_clusters}}
2012

examples/chip-tool/templates/logging/DataModelLogger.zapt

-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
#include <lib/core/CHIPError.h>
44
#include <app-common/zap-generated/cluster-objects.h>
55

6-
{{#zcl_structs}}
7-
{{#if has_more_than_one_cluster}}
8-
{{> struct_logger_decl namespace="detail"}}
9-
{{/if}}
10-
{{/zcl_structs}}
11-
126
{{#zcl_clusters}}
137
{{#zcl_structs}}
14-
{{#unless has_more_than_one_cluster}}
158
{{> struct_logger_decl namespace=(as_camel_cased ../name false)}}
16-
{{/unless}}
179
{{/zcl_structs}}
1810
{{/zcl_clusters}}
1911

src/app/zap-templates/templates/app/cluster-objects.zapt

+18-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,24 @@ namespace {{asUpperCamelCase name}} {
5454
namespace Structs {
5555
{{/first}}
5656
{{#if has_more_than_one_cluster}}
57-
namespace {{asUpperCamelCase name}} = Clusters::detail::Structs::{{asUpperCamelCase name}};
57+
namespace {{asUpperCamelCase name}} {
58+
59+
using Fields = Clusters::detail::Structs::{{asUpperCamelCase name}}::Fields;
60+
61+
struct Type : public Clusters::detail::Structs::{{asUpperCamelCase name}}::Type
62+
{
63+
};
64+
65+
{{#if struct_contains_array}}
66+
struct DecodableType : public Clusters::detail::Structs::{{asUpperCamelCase name}}::DecodableType
67+
{
68+
};
69+
{{else}}
70+
using DecodableType = Type;
71+
{{/if}}
72+
73+
} // namespace {{asUpperCamelCase name}}
74+
5875
{{else}}
5976
{{> cluster_objects_struct header=true}}
6077
{{/if}}

zzz_generated/app-common/app-common/zap-generated/cluster-objects.h

+48-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp

+122-60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)