-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathattribute_trail.h
More file actions
61 lines (48 loc) · 2.17 KB
/
Copy pathattribute_trail.h
File metadata and controls
61 lines (48 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_ATTRIBUTE_TRAIL_H_
#define THIRD_PARTY_CEL_CPP_EVAL_EVAL_ATTRIBUTE_TRAIL_H_
#include <string>
#include <utility>
#include <vector>
#include "google/api/expr/v1alpha1/syntax.pb.h"
#include "google/protobuf/arena.h"
#include "absl/types/optional.h"
#include "absl/utility/utility.h"
#include "base/memory.h"
#include "eval/public/cel_attribute.h"
#include "eval/public/cel_expression.h"
#include "eval/public/cel_value.h"
#include "eval/public/unknown_attribute_set.h"
namespace google::api::expr::runtime {
// AttributeTrail reflects current attribute path.
// It is functionally similar to CelAttribute, yet intended to have better
// complexity on attribute path increment operations.
// TODO(issues/41) Current AttributeTrail implementation is equivalent to
// CelAttribute - improve it.
// Intended to be used in conjunction with CelValue, describing the attribute
// value originated from.
// Empty AttributeTrail denotes object with attribute path not defined
// or supported.
class AttributeTrail {
public:
AttributeTrail() : attribute_(absl::nullopt) {}
AttributeTrail(google::api::expr::v1alpha1::Expr root, cel::MemoryManager& manager);
explicit AttributeTrail(std::string variable_name)
: attribute_(absl::in_place, std::move(variable_name)) {}
// Creates AttributeTrail with attribute path incremented by "qualifier".
AttributeTrail Step(CelAttributeQualifier qualifier,
cel::MemoryManager& manager) const;
// Creates AttributeTrail with attribute path incremented by "qualifier".
AttributeTrail Step(const std::string* qualifier,
cel::MemoryManager& manager) const {
return Step(cel::AttributeQualifier::OfString(*qualifier), manager);
}
// Returns CelAttribute that corresponds to content of AttributeTrail.
const CelAttribute& attribute() const { return attribute_.value(); }
bool empty() const { return !attribute_.has_value(); }
private:
explicit AttributeTrail(CelAttribute attribute)
: attribute_(std::move(attribute)) {}
absl::optional<CelAttribute> attribute_;
};
} // namespace google::api::expr::runtime
#endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_ATTRIBUTE_TRAIL_H_