MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / AttributePattern

Class AttributePattern

base/attribute.h:221–267  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

219// - map lookup by key;
220// - list access by index.
221class 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
269struct FieldSpecifier {
270 int64_t number;

Callers 7

TESTFunction · 0.85
TEST_FFunction · 0.85
TESTFunction · 0.85
TEST_PFunction · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85

Calls

no outgoing calls

Tested by 6

TESTFunction · 0.68
TEST_FFunction · 0.68
TESTFunction · 0.68
TEST_PFunction · 0.68
TEST_FFunction · 0.68
TEST_FFunction · 0.68