/proc/self/cwd/eval/eval/attribute_trail.h
Line | Count | Source |
1 | | #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_ATTRIBUTE_TRAIL_H_ |
2 | | #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_ATTRIBUTE_TRAIL_H_ |
3 | | |
4 | | #include <string> |
5 | | #include <utility> |
6 | | |
7 | | #include "absl/types/optional.h" |
8 | | #include "absl/utility/utility.h" |
9 | | #include "base/attribute.h" |
10 | | |
11 | | namespace google::api::expr::runtime { |
12 | | |
13 | | // AttributeTrail reflects current attribute path. |
14 | | // It is functionally similar to cel::Attribute, yet intended to have better |
15 | | // complexity on attribute path increment operations. |
16 | | // TODO(issues/41) Current AttributeTrail implementation is equivalent to |
17 | | // cel::Attribute - improve it. |
18 | | // Intended to be used in conjunction with cel::Value, describing the attribute |
19 | | // value originated from. |
20 | | // Empty AttributeTrail denotes object with attribute path not defined |
21 | | // or supported. |
22 | | class AttributeTrail { |
23 | | public: |
24 | 17.1M | AttributeTrail() : attribute_(absl::nullopt) {} |
25 | | |
26 | | explicit AttributeTrail(std::string variable_name) |
27 | 0 | : attribute_(absl::in_place, std::move(variable_name)) {} |
28 | | |
29 | | explicit AttributeTrail(cel::Attribute attribute) |
30 | 0 | : attribute_(std::move(attribute)) {} |
31 | | |
32 | | // NOLINTNEXTLINE(google-explicit-constructor) |
33 | 13.4M | AttributeTrail(absl::nullopt_t) : AttributeTrail() {} |
34 | | |
35 | 2.37M | AttributeTrail(const AttributeTrail&) = default; |
36 | 0 | AttributeTrail& operator=(const AttributeTrail&) = default; |
37 | 2.90M | AttributeTrail(AttributeTrail&&) = default; |
38 | 2.55M | AttributeTrail& operator=(AttributeTrail&&) = default; |
39 | | |
40 | 12.4M | AttributeTrail& operator=(absl::nullopt_t) { |
41 | 12.4M | attribute_.reset(); |
42 | 12.4M | return *this; |
43 | 12.4M | } |
44 | | |
45 | | // Creates AttributeTrail with attribute path incremented by "qualifier". |
46 | | AttributeTrail Step(cel::AttributeQualifier qualifier) const; |
47 | | |
48 | | // Creates AttributeTrail with attribute path incremented by "qualifier". |
49 | 0 | AttributeTrail Step(const std::string* qualifier) const { |
50 | 0 | if (empty()) return AttributeTrail(); |
51 | 0 | return Step(cel::AttributeQualifier::OfString(*qualifier)); |
52 | 0 | } |
53 | | |
54 | | // Returns CelAttribute that corresponds to content of AttributeTrail. |
55 | 0 | const cel::Attribute& attribute() const { return attribute_.value(); } |
56 | | |
57 | 0 | bool empty() const { return !attribute_.has_value(); } |
58 | | |
59 | | private: |
60 | | absl::optional<cel::Attribute> attribute_; |
61 | | }; |
62 | | |
63 | | } // namespace google::api::expr::runtime |
64 | | |
65 | | #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_ATTRIBUTE_TRAIL_H_ |