/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 | 7.25M | 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 | 4.95M | AttributeTrail(absl::nullopt_t) : AttributeTrail() {} |
34 | | |
35 | 1.57M | AttributeTrail(const AttributeTrail&) = default; |
36 | 0 | AttributeTrail& operator=(const AttributeTrail&) = default; |
37 | 1.99M | AttributeTrail(AttributeTrail&&) = default; |
38 | 1.00M | AttributeTrail& operator=(AttributeTrail&&) = default; |
39 | | |
40 | 7.26M | AttributeTrail& operator=(absl::nullopt_t) { |
41 | 7.26M | attribute_.reset(); |
42 | 7.26M | return *this; |
43 | 7.26M | } |
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 | return Step(cel::AttributeQualifier::OfString(*qualifier)); |
51 | 0 | } |
52 | | |
53 | | // Returns CelAttribute that corresponds to content of AttributeTrail. |
54 | 0 | const cel::Attribute& attribute() const { return attribute_.value(); } |
55 | | |
56 | 0 | bool empty() const { return !attribute_.has_value(); } |
57 | | |
58 | | private: |
59 | | absl::optional<cel::Attribute> attribute_; |
60 | | }; |
61 | | |
62 | | } // namespace google::api::expr::runtime |
63 | | |
64 | | #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_ATTRIBUTE_TRAIL_H_ |