-
Notifications
You must be signed in to change notification settings - Fork 5.5k
matcher: add support for new any matcher mechanism #19143
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
Changes from 3 commits
a56a864
86db280
9d59dde
e264d43
435cb54
c06f3f1
c8a610f
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 |
|---|---|---|
|
|
@@ -65,6 +65,17 @@ using MatchTreeFactoryCb = std::function<std::unique_ptr<MatchTree<DataType>>()> | |
| template <class DataType> using OnMatchFactoryCb = std::function<OnMatch<DataType>()>; | ||
| template <class DataType> using DataInputFactoryCb = std::function<DataInputPtr<DataType>()>; | ||
|
|
||
| template <class DataType> class AnyMatcher : public MatchTree<DataType> { | ||
| public: | ||
| explicit AnyMatcher(absl::optional<OnMatch<DataType>> on_no_match) | ||
| : on_no_match_(std::move(on_no_match)) {} | ||
|
|
||
| typename MatchTree<DataType>::MatchResult match(const DataType&) override { | ||
| return {MatchState::MatchComplete, on_no_match_}; | ||
|
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. I'm not an expert here, but should the 2nd param (
Contributor
Author
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. I think in other use cases this always does a copy, since the Action object is generally small (lambda + pointer). We could probably change this around but would be a bigger refactor I think |
||
| } | ||
| const absl::optional<OnMatch<DataType>> on_no_match_; | ||
| }; | ||
|
|
||
| /** | ||
| * Recursively constructs a MatchTree from a protobuf configuration. | ||
| * @param DataType the type used as a source for DataInputs | ||
|
|
@@ -86,12 +97,20 @@ template <class DataType, class ActionFactoryContext> class MatchTreeFactory { | |
| case MatcherType::kMatcherList: | ||
| return createListMatcher(config); | ||
| default: | ||
| NOT_REACHED_GCOVR_EXCL_LINE; | ||
| return nullptr; | ||
| return createAnyMatcher(config); | ||
| } | ||
| } | ||
|
|
||
| private: | ||
| template <class MatcherType> | ||
| MatchTreeFactoryCb<DataType> createAnyMatcher(const MatcherType& config) { | ||
| auto on_no_match = createOnMatch(config.on_no_match()); | ||
|
|
||
| return [on_no_match]() { | ||
| return std::make_unique<AnyMatcher<DataType>>( | ||
| on_no_match ? absl::make_optional((*on_no_match)()) : absl::nullopt); | ||
| }; | ||
| } | ||
| template <class MatcherType> | ||
| MatchTreeFactoryCb<DataType> createListMatcher(const MatcherType& config) { | ||
| std::vector<std::pair<FieldMatcherFactoryCb<DataType>, OnMatchFactoryCb<DataType>>> | ||
|
|
||
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.
Please add some comments.