forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcel_attribute.cc
More file actions
57 lines (46 loc) · 1.58 KB
/
Copy pathcel_attribute.cc
File metadata and controls
57 lines (46 loc) · 1.58 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
#include "eval/public/cel_attribute.h"
#include <algorithm>
#include "absl/strings/string_view.h"
#include "absl/types/variant.h"
namespace google {
namespace api {
namespace expr {
namespace runtime {
namespace {
struct QualifierVisitor {
CelAttributeQualifierPattern operator()(absl::string_view v) {
if (v == "*") {
return CelAttributeQualifierPattern::CreateWildcard();
}
return CelAttributeQualifierPattern::Create(CelValue::CreateStringView(v));
}
CelAttributeQualifierPattern operator()(int64_t v) {
return CelAttributeQualifierPattern::Create(CelValue::CreateInt64(v));
}
CelAttributeQualifierPattern operator()(uint64_t v) {
return CelAttributeQualifierPattern::Create(CelValue::CreateUint64(v));
}
CelAttributeQualifierPattern operator()(bool v) {
return CelAttributeQualifierPattern::Create(CelValue::CreateBool(v));
}
CelAttributeQualifierPattern operator()(CelAttributeQualifierPattern v) {
return v;
}
};
} // namespace
CelAttributePattern CreateCelAttributePattern(
absl::string_view variable,
std::initializer_list<absl::variant<absl::string_view, int64_t, uint64_t, bool,
CelAttributeQualifierPattern>>
path_spec) {
std::vector<CelAttributeQualifierPattern> path;
path.reserve(path_spec.size());
for (const auto& spec_elem : path_spec) {
path.emplace_back(absl::visit(QualifierVisitor(), spec_elem));
}
return CelAttributePattern(std::string(variable), std::move(path));
}
} // namespace runtime
} // namespace expr
} // namespace api
} // namespace google