-
Notifications
You must be signed in to change notification settings - Fork 83
Add field tags #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add field tags #357
Changes from all commits
9eff94a
b26ddd2
2f5a0da
c45d01a
5a4f33f
1337ff1
915ef07
4ccf76c
47c26d9
44de0b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #include "score/mw/com/impl/field_tags.h" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #ifndef PLATFORM_AAS_MW_COM_IMPL_FIELD_TAGS_H | ||
| #define PLATFORM_AAS_MW_COM_IMPL_FIELD_TAGS_H | ||
|
|
||
| #include <type_traits> | ||
|
|
||
| namespace score::mw::com::impl | ||
| { | ||
|
|
||
| /// \brief Tag types used on ProxyField/SkeletonField level to accomplish overload-resolution for various signatures, | ||
| /// which depend on the availability of Get/Set/Notifier. A field must enable WithGetter or WithNotifier | ||
| /// (a write-only field would be invisible to consumers). | ||
| struct WithGetter | ||
| { | ||
| }; | ||
|
|
||
| struct WithSetter | ||
| { | ||
| }; | ||
|
|
||
| struct WithNotifier | ||
| { | ||
| }; | ||
|
|
||
| namespace detail | ||
| { | ||
|
|
||
| template <typename TargetType, typename... Tags> | ||
| struct contains_type : std::disjunction<std::is_same<TargetType, Tags>...> | ||
| { | ||
| }; | ||
|
|
||
| // SFINAE only works when the condition depends on the function-template parameters, not the class-template | ||
| // parameters. The std::is_same<FieldType, ClassFieldType> line ties substitution to a function-template | ||
| // parameter so the check fires at overload resolution instead of class instantiation. | ||
| template <typename FieldType, typename ClassFieldType, typename TargetTag, typename... Tags> | ||
| struct is_tag_enabled : std::conjunction<contains_type<TargetTag, Tags...>, std::is_same<FieldType, ClassFieldType>> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since is_tag_enabled is a public function to be used by other targets, it shouldn't be in the detail namespace. |
||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have unit tests for any public function (so definitely is_tag_enabled and if contains_type is publicly exposed i.e. not in the detail namespace then also for it). You can look at the unit tests that I wrote for method_handler_checker_test as a reference if you want: https://github.com/eclipse-score/communication/pull/369/changes#diff-a5298ded87ed55bcf9aceb680edbe7e0c9b81700b7a5e0f24feb7b3600dac64d
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can only support "positive" tests for the moment, but you should also write the negative tests e.g. |
||
| }; | ||
|
|
||
| /// \brief Marker used as a disambiguator on test-only ctors to keep them distinct from production overloads. | ||
| /// Lives in detail to signal "not part of the public API"; tests reach into the detail namespace knowingly. | ||
| struct WithTestTag | ||
| { | ||
| }; | ||
|
|
||
| } // namespace detail | ||
|
|
||
| } // namespace score::mw::com::impl | ||
|
|
||
| #endif // PLATFORM_AAS_MW_COM_IMPL_FIELD_TAGS_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment "A field must enable WithGetter or WithNotifier (a write-only field would be invisible to consumers)." isn't really relevant here IMO. this should rather be in the documentation of the field itself. The tags themselves don't care about that invariant. The invairnat only matters in the place where the tags are used i.e. the actual field.