AttributePattern is a fully-qualified absolute attribute path pattern. Supported segments steps in the path are: - field selection; - map lookup by key; - list access by index.
| 219 | // - map lookup by key; |
| 220 | // - list access by index. |
| 221 | class AttributePattern final { |
| 222 | public: |
| 223 | // MatchType enum specifies how closely pattern is matching the attribute: |
| 224 | enum class MatchType { |
| 225 | NONE, // Pattern does not match attribute itself nor its children |
| 226 | PARTIAL, // Pattern matches an entity nested within attribute; |
| 227 | FULL // Pattern matches an attribute itself. |
| 228 | }; |
| 229 | |
| 230 | AttributePattern(std::string variable, |
| 231 | std::vector<AttributeQualifierPattern> qualifier_path) |
| 232 | : variable_(std::move(variable)), |
| 233 | qualifier_path_(std::move(qualifier_path)) {} |
| 234 | |
| 235 | absl::string_view variable() const { return variable_; } |
| 236 | |
| 237 | absl::Span<const AttributeQualifierPattern> qualifier_path() const { |
| 238 | return qualifier_path_; |
| 239 | } |
| 240 | |
| 241 | // Matches the pattern to an attribute. |
| 242 | // Distinguishes between no-match, partial match and full match cases. |
| 243 | MatchType IsMatch(const Attribute& attribute) const { |
| 244 | MatchType result = MatchType::NONE; |
| 245 | if (attribute.variable_name() != variable_) { |
| 246 | return result; |
| 247 | } |
| 248 | |
| 249 | auto max_index = qualifier_path().size(); |
| 250 | result = MatchType::FULL; |
| 251 | if (qualifier_path().size() > attribute.qualifier_path().size()) { |
| 252 | max_index = attribute.qualifier_path().size(); |
| 253 | result = MatchType::PARTIAL; |
| 254 | } |
| 255 | |
| 256 | for (size_t i = 0; i < max_index; i++) { |
| 257 | if (!(qualifier_path()[i].IsMatch(attribute.qualifier_path()[i]))) { |
| 258 | return MatchType::NONE; |
| 259 | } |
| 260 | } |
| 261 | return result; |
| 262 | } |
| 263 | |
| 264 | private: |
| 265 | std::string variable_; |
| 266 | std::vector<AttributeQualifierPattern> qualifier_path_; |
| 267 | }; |
| 268 | |
| 269 | struct FieldSpecifier { |
| 270 | int64_t number; |