/proc/self/cwd/common/values/legacy_map_value.h
Line | Count | Source |
1 | | // Copyright 2023 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | // IWYU pragma: private, include "common/values/map_value.h" |
16 | | // IWYU pragma: friend "common/values/map_value.h" |
17 | | |
18 | | #ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_MAP_VALUE_H_ |
19 | | #define THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_MAP_VALUE_H_ |
20 | | |
21 | | #include <cstddef> |
22 | | #include <ostream> |
23 | | #include <string> |
24 | | |
25 | | #include "absl/base/nullability.h" |
26 | | #include "absl/status/status.h" |
27 | | #include "absl/status/statusor.h" |
28 | | #include "absl/strings/string_view.h" |
29 | | #include "absl/types/optional.h" |
30 | | #include "common/value_kind.h" |
31 | | #include "common/values/custom_map_value.h" |
32 | | #include "common/values/parsed_json_map_value.h" |
33 | | #include "common/values/parsed_map_field_value.h" |
34 | | #include "common/values/values.h" |
35 | | #include "google/protobuf/arena.h" |
36 | | #include "google/protobuf/descriptor.h" |
37 | | #include "google/protobuf/io/zero_copy_stream.h" |
38 | | #include "google/protobuf/message.h" |
39 | | |
40 | | namespace google::api::expr::runtime { |
41 | | class CelMap; |
42 | | } |
43 | | |
44 | | namespace cel { |
45 | | |
46 | | class Value; |
47 | | |
48 | | namespace common_internal { |
49 | | |
50 | | class LegacyMapValue; |
51 | | |
52 | | class LegacyMapValue final |
53 | | : private common_internal::MapValueMixin<LegacyMapValue> { |
54 | | public: |
55 | | static constexpr ValueKind kKind = ValueKind::kMap; |
56 | | |
57 | | explicit LegacyMapValue( |
58 | | const google::api::expr::runtime::CelMap* absl_nullability_unknown impl) |
59 | 28 | : impl_(impl) {} |
60 | | |
61 | | // By default, this creates an empty map whose type is `map(dyn, dyn)`. |
62 | | // Unless you can help it, you should use a more specific typed map value. |
63 | | LegacyMapValue() = default; |
64 | | LegacyMapValue(const LegacyMapValue&) = default; |
65 | | LegacyMapValue(LegacyMapValue&&) = default; |
66 | | LegacyMapValue& operator=(const LegacyMapValue&) = default; |
67 | | LegacyMapValue& operator=(LegacyMapValue&&) = default; |
68 | | |
69 | 0 | constexpr ValueKind kind() const { return kKind; } |
70 | | |
71 | 0 | absl::string_view GetTypeName() const { return "map"; } |
72 | | |
73 | | std::string DebugString() const; |
74 | | |
75 | | // See Value::SerializeTo(). |
76 | | absl::Status SerializeTo( |
77 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
78 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
79 | | google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const; |
80 | | |
81 | | // See Value::ConvertToJson(). |
82 | | absl::Status ConvertToJson( |
83 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
84 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
85 | | google::protobuf::Message* absl_nonnull json) const; |
86 | | |
87 | | // See Value::ConvertToJsonObject(). |
88 | | absl::Status ConvertToJsonObject( |
89 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
90 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
91 | | google::protobuf::Message* absl_nonnull json) const; |
92 | | |
93 | | absl::Status Equal(const Value& other, |
94 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
95 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
96 | | google::protobuf::Arena* absl_nonnull arena, |
97 | | Value* absl_nonnull result) const; |
98 | | using MapValueMixin::Equal; |
99 | | |
100 | 0 | bool IsZeroValue() const { return IsEmpty(); } |
101 | | |
102 | | bool IsEmpty() const; |
103 | | |
104 | | size_t Size() const; |
105 | | |
106 | | // See the corresponding member function of `MapValue` for |
107 | | // documentation. |
108 | | absl::Status Get(const Value& key, |
109 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
110 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
111 | | google::protobuf::Arena* absl_nonnull arena, |
112 | | Value* absl_nonnull result) const; |
113 | | using MapValueMixin::Get; |
114 | | |
115 | | // See the corresponding member function of `MapValue` for |
116 | | // documentation. |
117 | | absl::StatusOr<bool> Find( |
118 | | const Value& key, |
119 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
120 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
121 | | google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const; |
122 | | using MapValueMixin::Find; |
123 | | |
124 | | // See the corresponding member function of `MapValue` for |
125 | | // documentation. |
126 | | absl::Status Has(const Value& key, |
127 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
128 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
129 | | google::protobuf::Arena* absl_nonnull arena, |
130 | | Value* absl_nonnull result) const; |
131 | | using MapValueMixin::Has; |
132 | | |
133 | | // See the corresponding member function of `MapValue` for |
134 | | // documentation. |
135 | | absl::Status ListKeys( |
136 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
137 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
138 | | google::protobuf::Arena* absl_nonnull arena, ListValue* absl_nonnull result) const; |
139 | | using MapValueMixin::ListKeys; |
140 | | |
141 | | // See the corresponding type declaration of `MapValue` for |
142 | | // documentation. |
143 | | using ForEachCallback = typename CustomMapValueInterface::ForEachCallback; |
144 | | |
145 | | // See the corresponding member function of `MapValue` for |
146 | | // documentation. |
147 | | absl::Status ForEach( |
148 | | ForEachCallback callback, |
149 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
150 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
151 | | google::protobuf::Arena* absl_nonnull arena) const; |
152 | | |
153 | | absl::StatusOr<absl_nonnull ValueIteratorPtr> NewIterator() const; |
154 | | |
155 | 28 | const google::api::expr::runtime::CelMap* absl_nonnull cel_map() const { |
156 | 28 | return impl_; |
157 | 28 | } |
158 | | |
159 | 0 | friend void swap(LegacyMapValue& lhs, LegacyMapValue& rhs) noexcept { |
160 | 0 | using std::swap; |
161 | 0 | swap(lhs.impl_, rhs.impl_); |
162 | 0 | } |
163 | | |
164 | | private: |
165 | | friend class common_internal::ValueMixin<LegacyMapValue>; |
166 | | friend class common_internal::MapValueMixin<LegacyMapValue>; |
167 | | |
168 | | const google::api::expr::runtime::CelMap* absl_nullability_unknown impl_ = |
169 | | nullptr; |
170 | | }; |
171 | | |
172 | 0 | inline std::ostream& operator<<(std::ostream& out, const LegacyMapValue& type) { |
173 | 0 | return out << type.DebugString(); |
174 | 0 | } |
175 | | |
176 | | bool IsLegacyMapValue(const Value& value); |
177 | | |
178 | | LegacyMapValue GetLegacyMapValue(const Value& value); |
179 | | |
180 | | absl::optional<LegacyMapValue> AsLegacyMapValue(const Value& value); |
181 | | |
182 | | class LegacyParsedMapFieldMapValue; |
183 | | class LegacyParsedJsonMapValue; |
184 | | |
185 | | CustomMapValue WrapLegacyParsedMapField(ParsedMapFieldValue value, |
186 | | google::protobuf::Arena* absl_nonnull arena); |
187 | | |
188 | | CustomMapValue WrapLegacyParsedJsonMap(ParsedJsonMapValue value, |
189 | | google::protobuf::Arena* absl_nonnull arena); |
190 | | |
191 | | } // namespace common_internal |
192 | | |
193 | | } // namespace cel |
194 | | |
195 | | #endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_MAP_VALUE_H_ |