| 1 | //===----------------------------------------------------------------------===// |
| 2 | // DuckDB |
| 3 | // |
| 4 | // duckdb/optimizer/matcher/function_matcher.hpp |
| 5 | // |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "duckdb/common/common.hpp" |
| 12 | #include "duckdb/common/unordered_set.hpp" |
| 13 | #include <algorithm> |
| 14 | |
| 15 | namespace duckdb { |
| 16 | |
| 17 | //! The FunctionMatcher class contains a set of matchers that can be used to pattern match specific functions |
| 18 | class FunctionMatcher { |
| 19 | public: |
| 20 | virtual ~FunctionMatcher() { |
| 21 | } |
| 22 | |
| 23 | virtual bool Match(string &name) = 0; |
| 24 | |
| 25 | static bool Match(unique_ptr<FunctionMatcher> &matcher, string &name) { |
| 26 | if (!matcher) { |
| 27 | return true; |
| 28 | } |
| 29 | return matcher->Match(name); |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | //! The SpecificFunctionMatcher class matches a single specified function name |
| 34 | class SpecificFunctionMatcher : public FunctionMatcher { |
| 35 | public: |
| 36 | explicit SpecificFunctionMatcher(string name) : name(std::move(name)) { |
| 37 | } |
| 38 | |
| 39 | bool Match(string &name) override { |
| 40 | return name == this->name; |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | string name; |
| 45 | }; |
| 46 | |
| 47 | //! The ManyFunctionMatcher class matches a set of functions |
| 48 | class ManyFunctionMatcher : public FunctionMatcher { |
| 49 | public: |
| 50 | explicit ManyFunctionMatcher(unordered_set<string> names) : names(std::move(names)) { |
| 51 | } |
| 52 | |
| 53 | bool Match(string &name) override { |
| 54 | return names.find(x: name) != names.end(); |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | unordered_set<string> names; |
| 59 | }; |
| 60 | |
| 61 | } // namespace duckdb |
| 62 | |