/proc/self/cwd/common/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 | | #ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUE_H_ |
16 | | #define THIRD_PARTY_CEL_CPP_COMMON_VALUE_H_ |
17 | | |
18 | | #include <cstddef> |
19 | | #include <cstdint> |
20 | | #include <cstring> |
21 | | #include <memory> |
22 | | #include <ostream> |
23 | | #include <string> |
24 | | #include <type_traits> |
25 | | #include <utility> |
26 | | |
27 | | #include "absl/base/attributes.h" |
28 | | #include "absl/base/nullability.h" |
29 | | #include "absl/log/absl_check.h" |
30 | | #include "absl/meta/type_traits.h" |
31 | | #include "absl/status/status.h" |
32 | | #include "absl/status/statusor.h" |
33 | | #include "absl/strings/string_view.h" |
34 | | #include "absl/types/optional.h" |
35 | | #include "absl/types/span.h" |
36 | | #include "absl/utility/utility.h" |
37 | | #include "base/attribute.h" |
38 | | #include "common/arena.h" |
39 | | #include "common/native_type.h" |
40 | | #include "common/optional_ref.h" |
41 | | #include "common/type.h" |
42 | | #include "common/typeinfo.h" |
43 | | #include "common/value_kind.h" |
44 | | #include "common/values/bool_value.h" // IWYU pragma: export |
45 | | #include "common/values/bytes_value.h" // IWYU pragma: export |
46 | | #include "common/values/bytes_value_input_stream.h" // IWYU pragma: export |
47 | | #include "common/values/bytes_value_output_stream.h" // IWYU pragma: export |
48 | | #include "common/values/custom_list_value.h" // IWYU pragma: export |
49 | | #include "common/values/custom_map_value.h" // IWYU pragma: export |
50 | | #include "common/values/custom_struct_value.h" // IWYU pragma: export |
51 | | #include "common/values/double_value.h" // IWYU pragma: export |
52 | | #include "common/values/duration_value.h" // IWYU pragma: export |
53 | | #include "common/values/enum_value.h" // IWYU pragma: export |
54 | | #include "common/values/error_value.h" // IWYU pragma: export |
55 | | #include "common/values/int_value.h" // IWYU pragma: export |
56 | | #include "common/values/list_value.h" // IWYU pragma: export |
57 | | #include "common/values/map_value.h" // IWYU pragma: export |
58 | | #include "common/values/message_value.h" // IWYU pragma: export |
59 | | #include "common/values/null_value.h" // IWYU pragma: export |
60 | | #include "common/values/opaque_value.h" // IWYU pragma: export |
61 | | #include "common/values/optional_value.h" // IWYU pragma: export |
62 | | #include "common/values/parsed_json_list_value.h" // IWYU pragma: export |
63 | | #include "common/values/parsed_json_map_value.h" // IWYU pragma: export |
64 | | #include "common/values/parsed_map_field_value.h" // IWYU pragma: export |
65 | | #include "common/values/parsed_message_value.h" // IWYU pragma: export |
66 | | #include "common/values/parsed_repeated_field_value.h" // IWYU pragma: export |
67 | | #include "common/values/string_value.h" // IWYU pragma: export |
68 | | #include "common/values/struct_value.h" // IWYU pragma: export |
69 | | #include "common/values/timestamp_value.h" // IWYU pragma: export |
70 | | #include "common/values/type_value.h" // IWYU pragma: export |
71 | | #include "common/values/uint_value.h" // IWYU pragma: export |
72 | | #include "common/values/unknown_value.h" // IWYU pragma: export |
73 | | #include "common/values/value_variant.h" |
74 | | #include "common/values/values.h" |
75 | | #include "internal/status_macros.h" |
76 | | #include "runtime/runtime_options.h" |
77 | | #include "google/protobuf/arena.h" |
78 | | #include "google/protobuf/descriptor.h" |
79 | | #include "google/protobuf/generated_enum_reflection.h" |
80 | | #include "google/protobuf/io/zero_copy_stream.h" |
81 | | #include "google/protobuf/map_field.h" |
82 | | #include "google/protobuf/message.h" |
83 | | |
84 | | #pragma push_macro("GetMessage") |
85 | | #ifdef GetMessage |
86 | | // GetMessage in windows API headers might be defined as a macro. Depending on |
87 | | // ordering, might cause issues with Value::GetMessage or |
88 | | // google::protobuf::Reflection::GetMessage. |
89 | | #undef GetMessage |
90 | | #endif |
91 | | |
92 | | namespace cel { |
93 | | |
94 | | // `Value` is a composition type which encompasses all values supported by the |
95 | | // Common Expression Language. When default constructed or moved, `Value` is in |
96 | | // a known but invalid state. Any attempt to use it from then on, without |
97 | | // assigning another type, is undefined behavior. In debug builds, we do our |
98 | | // best to fail. |
99 | | class Value final : private common_internal::ValueMixin<Value> { |
100 | | public: |
101 | | // Returns an appropriate `Value` for the dynamic protobuf enum. For open |
102 | | // enums, returns `cel::IntValue`. For closed enums, returns `cel::ErrorValue` |
103 | | // if the value is not present in the enum otherwise returns `cel::IntValue`. |
104 | | static Value Enum(const google::protobuf::EnumValueDescriptor* absl_nonnull value); |
105 | | static Value Enum(const google::protobuf::EnumDescriptor* absl_nonnull type, |
106 | | int32_t number); |
107 | | |
108 | | // SFINAE overload for generated protobuf enums which are not well-known. |
109 | | // Always returns `cel::IntValue`. |
110 | | template <typename T> |
111 | | static common_internal::EnableIfGeneratedEnum<T, IntValue> Enum(T value) { |
112 | | return IntValue(value); |
113 | | } |
114 | | |
115 | | // SFINAE overload for google::protobuf::NullValue. Always returns |
116 | | // `cel::NullValue`. |
117 | | template <typename T> |
118 | | static common_internal::EnableIfWellKnownEnum<T, google::protobuf::NullValue, |
119 | | NullValue> |
120 | | Enum(T) { |
121 | | return NullValue(); |
122 | | } |
123 | | |
124 | | // Returns an appropriate `Value` for the dynamic protobuf message. If |
125 | | // `message` is the well known type `google.protobuf.Any`, `descriptor_pool` |
126 | | // and `message_factory` will be used to unpack the value. Both must outlive |
127 | | // the resulting value and any of its shallow copies. Otherwise the message is |
128 | | // copied using `arena`. |
129 | | static Value FromMessage( |
130 | | const google::protobuf::Message& message, |
131 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
132 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
133 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
134 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
135 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
136 | | static Value FromMessage( |
137 | | google::protobuf::Message&& message, |
138 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
139 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
140 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
141 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
142 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
143 | | |
144 | | // Returns an appropriate `Value` for the dynamic protobuf message. If |
145 | | // `message` is the well known type `google.protobuf.Any`, `descriptor_pool` |
146 | | // and `message_factory` will be used to unpack the value. Both must outlive |
147 | | // the resulting value and any of its shallow copies. Otherwise the message is |
148 | | // borrowed (no copying). If the message is on an arena, that arena will be |
149 | | // attributed as the owner. Otherwise `arena` is used. |
150 | | static Value WrapMessage( |
151 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
152 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
153 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
154 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
155 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
156 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
157 | | |
158 | | // Returns an appropriate `Value` for the dynamic protobuf message. If |
159 | | // `message` is the well known type `google.protobuf.Any`, `descriptor_pool` |
160 | | // and `message_factory` will be used to unpack the value. Both must outlive |
161 | | // the resulting value and any of its shallow copies. Otherwise the message is |
162 | | // borrowed (no copying). This function does not attempt to validate arena |
163 | | // ownership of a dynamic message that was not unpacked from a well known |
164 | | // type. Caller is responsible for ensuring the resulting value and any |
165 | | // derived values do not outlive the input message. |
166 | | static Value WrapMessageUnsafe( |
167 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
168 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
169 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
170 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
171 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
172 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
173 | | |
174 | | // Returns an appropriate `Value` for the dynamic protobuf message field. If |
175 | | // `field` in `message` is the well known type `google.protobuf.Any`, |
176 | | // `descriptor_pool` and `message_factory` will be used to unpack the value. |
177 | | // Both must outlive the resulting value and any of its shallow copies. |
178 | | // Otherwise the field is borrowed (no copying). If the message is on an |
179 | | // arena, that arena will be attributed as the owner. Otherwise `arena` is |
180 | | // used. |
181 | | static Value WrapField( |
182 | | ProtoWrapperTypeOptions wrapper_type_options, |
183 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
184 | | const google::protobuf::FieldDescriptor* absl_nonnull field |
185 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
186 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
187 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
188 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
189 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
190 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
191 | | static Value WrapField( |
192 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
193 | | const google::protobuf::FieldDescriptor* absl_nonnull field |
194 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
195 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
196 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
197 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
198 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
199 | 0 | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
200 | 0 | return WrapField(ProtoWrapperTypeOptions::kUnsetNull, message, field, |
201 | 0 | descriptor_pool, message_factory, arena); |
202 | 0 | } |
203 | | |
204 | | // Returns an appropriate `Value` for the dynamic protobuf message field. If |
205 | | // `field` in `message` is the well known type `google.protobuf.Any`, |
206 | | // `descriptor_pool` and `message_factory` will be used to unpack the value. |
207 | | // Both must outlive the resulting value and any of its shallow copies. |
208 | | // Otherwise the field is borrowed (no copying). Caller is responsible for |
209 | | // ensuring the resulting value and any derived values do not outlive the |
210 | | // input message. |
211 | | static Value WrapFieldUnsafe( |
212 | | ProtoWrapperTypeOptions wrapper_type_options, |
213 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
214 | | const google::protobuf::FieldDescriptor* absl_nonnull field |
215 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
216 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
217 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
218 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
219 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
220 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
221 | | |
222 | | // Returns an appropriate `Value` for the dynamic protobuf message repeated |
223 | | // field. If `field` in `message` is the well known type |
224 | | // `google.protobuf.Any`, `descriptor_pool` and `message_factory` will be used |
225 | | // to unpack the value. Both must outlive the resulting value and any of its |
226 | | // shallow copies. |
227 | | static Value WrapRepeatedField( |
228 | | int index, |
229 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
230 | | const google::protobuf::FieldDescriptor* absl_nonnull field |
231 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
232 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
233 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
234 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
235 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
236 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
237 | | |
238 | | // Returns an appropriate `Value` for the dynamic protobuf message repeated |
239 | | // field. If `field` in `message` is the well known type |
240 | | // `google.protobuf.Any`, `descriptor_pool` and `message_factory` will be used |
241 | | // to unpack the value. Both must outlive the resulting value and any of its |
242 | | // shallow copies. |
243 | | static Value WrapRepeatedFieldUnsafe( |
244 | | int index, |
245 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
246 | | const google::protobuf::FieldDescriptor* absl_nonnull field |
247 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
248 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
249 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
250 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
251 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
252 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
253 | | |
254 | | // Returns an appropriate `StringValue` for the dynamic protobuf message map |
255 | | // field key. The map field key must be a string or the behavior is undefined. |
256 | | static StringValue WrapMapFieldKeyString( |
257 | | const google::protobuf::MapKey& key, |
258 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
259 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
260 | | |
261 | | // Returns an appropriate `Value` for the dynamic protobuf message map |
262 | | // field value. If `field` in `message`, which is `value`, is the well known |
263 | | // type `google.protobuf.Any`, `descriptor_pool` and `message_factory` will be |
264 | | // used to unpack the value. Both must outlive the resulting value and any of |
265 | | // its shallow copies. |
266 | | static Value WrapMapFieldValue( |
267 | | const google::protobuf::MapValueConstRef& value, |
268 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
269 | | const google::protobuf::FieldDescriptor* absl_nonnull field |
270 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
271 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
272 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
273 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
274 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
275 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
276 | | |
277 | | // Returns an appropriate `Value` for the dynamic protobuf message map |
278 | | // field value. If `field` in `message`, which is `value`, is the well known |
279 | | // type `google.protobuf.Any`, `descriptor_pool` and `message_factory` will be |
280 | | // used to unpack the value. Both must outlive the resulting value and any of |
281 | | // its shallow copies. Caller is responsible for ensuring the resulting value |
282 | | // and any derived values do not outlive the input message. |
283 | | static Value WrapMapFieldValueUnsafe( |
284 | | const google::protobuf::MapValueConstRef& value, |
285 | | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
286 | | const google::protobuf::FieldDescriptor* absl_nonnull field |
287 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
288 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
289 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
290 | | google::protobuf::MessageFactory* absl_nonnull message_factory |
291 | | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
292 | | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
293 | | |
294 | 210k | Value() = default; |
295 | 239k | Value(const Value&) = default; |
296 | 122k | Value& operator=(const Value&) = default; |
297 | 1.41M | Value(Value&& other) = default; |
298 | 169k | Value& operator=(Value&&) = default; |
299 | | |
300 | | // NOLINTNEXTLINE(google-explicit-constructor) |
301 | 0 | Value(const ListValue& value) : variant_(value.ToValueVariant()) {} |
302 | | |
303 | | // NOLINTNEXTLINE(google-explicit-constructor) |
304 | 3.48k | Value(ListValue&& value) : variant_(std::move(value).ToValueVariant()) {} |
305 | | |
306 | | // NOLINTNEXTLINE(google-explicit-constructor) |
307 | 0 | Value& operator=(const ListValue& value) { |
308 | 0 | variant_ = value.ToValueVariant(); |
309 | 0 | return *this; |
310 | 0 | } |
311 | | |
312 | | // NOLINTNEXTLINE(google-explicit-constructor) |
313 | 8.31k | Value& operator=(ListValue&& value) { |
314 | 8.31k | variant_ = std::move(value).ToValueVariant(); |
315 | 8.31k | return *this; |
316 | 8.31k | } |
317 | | |
318 | | // NOLINTNEXTLINE(google-explicit-constructor) |
319 | 0 | Value(const MapValue& value) : variant_(value.ToValueVariant()) {} |
320 | | |
321 | | // NOLINTNEXTLINE(google-explicit-constructor) |
322 | 8.13k | Value(MapValue&& value) : variant_(std::move(value).ToValueVariant()) {} |
323 | | |
324 | | // NOLINTNEXTLINE(google-explicit-constructor) |
325 | 0 | Value& operator=(const MapValue& value) { |
326 | 0 | variant_ = value.ToValueVariant(); |
327 | 0 | return *this; |
328 | 0 | } |
329 | | |
330 | | // NOLINTNEXTLINE(google-explicit-constructor) |
331 | 677 | Value& operator=(MapValue&& value) { |
332 | 677 | variant_ = std::move(value).ToValueVariant(); |
333 | 677 | return *this; |
334 | 677 | } |
335 | | |
336 | | // NOLINTNEXTLINE(google-explicit-constructor) |
337 | 0 | Value(const StructValue& value) : variant_(value.ToValueVariant()) {} |
338 | | |
339 | | // NOLINTNEXTLINE(google-explicit-constructor) |
340 | 0 | Value(StructValue&& value) : variant_(std::move(value).ToValueVariant()) {} |
341 | | |
342 | | // NOLINTNEXTLINE(google-explicit-constructor) |
343 | 0 | Value& operator=(const StructValue& value) { |
344 | 0 | variant_ = value.ToValueVariant(); |
345 | 0 | return *this; |
346 | 0 | } |
347 | | |
348 | | // NOLINTNEXTLINE(google-explicit-constructor) |
349 | 0 | Value& operator=(StructValue&& value) { |
350 | 0 | variant_ = std::move(value).ToValueVariant(); |
351 | 0 | return *this; |
352 | 0 | } |
353 | | |
354 | | // NOLINTNEXTLINE(google-explicit-constructor) |
355 | 0 | Value(const MessageValue& value) : variant_(value.ToValueVariant()) {} |
356 | | |
357 | | // NOLINTNEXTLINE(google-explicit-constructor) |
358 | 0 | Value(MessageValue&& value) : variant_(std::move(value).ToValueVariant()) {} |
359 | | |
360 | | // NOLINTNEXTLINE(google-explicit-constructor) |
361 | 0 | Value& operator=(const MessageValue& value) { |
362 | 0 | variant_ = value.ToValueVariant(); |
363 | 0 | return *this; |
364 | 0 | } |
365 | | |
366 | | // NOLINTNEXTLINE(google-explicit-constructor) |
367 | 0 | Value& operator=(MessageValue&& value) { |
368 | 0 | variant_ = std::move(value).ToValueVariant(); |
369 | 0 | return *this; |
370 | 0 | } |
371 | | |
372 | | // NOLINTNEXTLINE(google-explicit-constructor) |
373 | | Value(const OptionalValue& value) |
374 | | : variant_(absl::in_place_type<OpaqueValue>, |
375 | 0 | static_cast<const OpaqueValue&>(value)) {} |
376 | | |
377 | | // NOLINTNEXTLINE(google-explicit-constructor) |
378 | | Value(OptionalValue&& value) |
379 | | : variant_(absl::in_place_type<OpaqueValue>, |
380 | 0 | static_cast<OpaqueValue&&>(value)) {} |
381 | | |
382 | | // NOLINTNEXTLINE(google-explicit-constructor) |
383 | 0 | Value& operator=(const OptionalValue& value) { |
384 | 0 | variant_.Assign(static_cast<const OpaqueValue&>(value)); |
385 | 0 | return *this; |
386 | 0 | } |
387 | | |
388 | | // NOLINTNEXTLINE(google-explicit-constructor) |
389 | 0 | Value& operator=(OptionalValue&& value) { |
390 | 0 | variant_.Assign(static_cast<OpaqueValue&&>(value)); |
391 | 0 | return *this; |
392 | 0 | } |
393 | | |
394 | | template <typename T, |
395 | | typename = std::enable_if_t< |
396 | | common_internal::IsValueAlternativeV<absl::remove_cvref_t<T>>>> |
397 | | // NOLINTNEXTLINE(google-explicit-constructor) |
398 | | Value(T&& alternative) noexcept |
399 | 166k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, |
400 | 166k | std::forward<T>(alternative)) {}cel::Value::Value<cel::BoolValue, void>(cel::BoolValue&&) Line | Count | Source | 399 | 18.4k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 18.4k | std::forward<T>(alternative)) {} |
Unexecuted instantiation: cel::Value::Value<cel::UnknownValue, void>(cel::UnknownValue&&) cel::Value::Value<cel::ErrorValue, void>(cel::ErrorValue&&) Line | Count | Source | 399 | 10.7k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 10.7k | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::IntValue, void>(cel::IntValue&&) Line | Count | Source | 399 | 81.3k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 81.3k | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::UintValue, void>(cel::UintValue&&) Line | Count | Source | 399 | 19.4k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 19.4k | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::StringValue, void>(cel::StringValue&&) Line | Count | Source | 399 | 12.8k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 12.8k | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::TypeValue, void>(cel::TypeValue&&) Line | Count | Source | 399 | 759 | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 759 | std::forward<T>(alternative)) {} |
Unexecuted instantiation: cel::Value::Value<cel::CustomListValue, void>(cel::CustomListValue&&) Unexecuted instantiation: cel::Value::Value<cel::UnknownValue&, void>(cel::UnknownValue&) Unexecuted instantiation: cel::Value::Value<cel::CustomMapValue, void>(cel::CustomMapValue&&) cel::Value::Value<cel::StringValue const&, void>(cel::StringValue const&) Line | Count | Source | 399 | 1.94k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 1.94k | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::NullValue, void>(cel::NullValue&&) Line | Count | Source | 399 | 365 | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 365 | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::DoubleValue, void>(cel::DoubleValue&&) Line | Count | Source | 399 | 16.9k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 16.9k | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::BytesValue, void>(cel::BytesValue&&) Line | Count | Source | 399 | 3.62k | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 3.62k | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::DurationValue, void>(cel::DurationValue&&) Line | Count | Source | 399 | 168 | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 168 | std::forward<T>(alternative)) {} |
cel::Value::Value<cel::TimestampValue, void>(cel::TimestampValue&&) Line | Count | Source | 399 | 1 | : variant_(absl::in_place_type<absl::remove_cvref_t<T>>, | 400 | 1 | std::forward<T>(alternative)) {} |
Unexecuted instantiation: cel::Value::Value<cel::OpaqueValue const&, void>(cel::OpaqueValue const&) Unexecuted instantiation: cel::Value::Value<cel::ParsedJsonListValue, void>(cel::ParsedJsonListValue&&) Unexecuted instantiation: cel::Value::Value<cel::ParsedJsonMapValue, void>(cel::ParsedJsonMapValue&&) Unexecuted instantiation: cel::Value::Value<cel::common_internal::LegacyStructValue, void>(cel::common_internal::LegacyStructValue&&) Unexecuted instantiation: cel::Value::Value<cel::NullValue const&, void>(cel::NullValue const&) Unexecuted instantiation: cel::Value::Value<cel::BoolValue const&, void>(cel::BoolValue const&) Unexecuted instantiation: cel::Value::Value<cel::IntValue const&, void>(cel::IntValue const&) Unexecuted instantiation: cel::Value::Value<cel::UintValue const&, void>(cel::UintValue const&) Unexecuted instantiation: cel::Value::Value<cel::DoubleValue const&, void>(cel::DoubleValue const&) Unexecuted instantiation: cel::Value::Value<cel::DurationValue const&, void>(cel::DurationValue const&) Unexecuted instantiation: cel::Value::Value<cel::TimestampValue const&, void>(cel::TimestampValue const&) Unexecuted instantiation: cel::Value::Value<cel::TypeValue const&, void>(cel::TypeValue const&) Unexecuted instantiation: cel::Value::Value<cel::common_internal::LegacyListValue const&, void>(cel::common_internal::LegacyListValue const&) Unexecuted instantiation: cel::Value::Value<cel::ParsedRepeatedFieldValue, void>(cel::ParsedRepeatedFieldValue&&) Unexecuted instantiation: cel::Value::Value<cel::common_internal::LegacyMapValue const&, void>(cel::common_internal::LegacyMapValue const&) Unexecuted instantiation: cel::Value::Value<cel::ParsedMapFieldValue, void>(cel::ParsedMapFieldValue&&) Unexecuted instantiation: cel::Value::Value<cel::common_internal::LegacyStructValue const&, void>(cel::common_internal::LegacyStructValue const&) Unexecuted instantiation: cel::Value::Value<cel::ParsedMessageValue, void>(cel::ParsedMessageValue&&) Unexecuted instantiation: cel::Value::Value<cel::CustomStructValue, void>(cel::CustomStructValue&&) Unexecuted instantiation: cel::Value::Value<cel::OpaqueValue, void>(cel::OpaqueValue&&) Unexecuted instantiation: cel::Value::Value<cel::UnknownValue const&, void>(cel::UnknownValue const&) |
401 | | |
402 | | template <typename T, |
403 | | typename = std::enable_if_t< |
404 | | common_internal::IsValueAlternativeV<absl::remove_cvref_t<T>>>> |
405 | | // NOLINTNEXTLINE(google-explicit-constructor) |
406 | 95.0k | Value& operator=(T&& alternative) noexcept { |
407 | 95.0k | variant_.Assign(std::forward<T>(alternative)); |
408 | 95.0k | return *this; |
409 | 95.0k | } cel::Value& cel::Value::operator=<cel::ErrorValue, void>(cel::ErrorValue&&) Line | Count | Source | 406 | 64.1k | Value& operator=(T&& alternative) noexcept { | 407 | 64.1k | variant_.Assign(std::forward<T>(alternative)); | 408 | 64.1k | return *this; | 409 | 64.1k | } |
cel::Value& cel::Value::operator=<cel::NullValue, void>(cel::NullValue&&) Line | Count | Source | 406 | 5.37k | Value& operator=(T&& alternative) noexcept { | 407 | 5.37k | variant_.Assign(std::forward<T>(alternative)); | 408 | 5.37k | return *this; | 409 | 5.37k | } |
cel::Value& cel::Value::operator=<cel::BoolValue, void>(cel::BoolValue&&) Line | Count | Source | 406 | 14.4k | Value& operator=(T&& alternative) noexcept { | 407 | 14.4k | variant_.Assign(std::forward<T>(alternative)); | 408 | 14.4k | return *this; | 409 | 14.4k | } |
Unexecuted instantiation: cel::Value& cel::Value::operator=<cel::UnknownValue, void>(cel::UnknownValue&&) Unexecuted instantiation: cel::Value& cel::Value::operator=<cel::CustomListValue, void>(cel::CustomListValue&&) Unexecuted instantiation: cel::Value& cel::Value::operator=<cel::CustomMapValue, void>(cel::CustomMapValue&&) cel::Value& cel::Value::operator=<cel::IntValue, void>(cel::IntValue&&) Line | Count | Source | 406 | 10.4k | Value& operator=(T&& alternative) noexcept { | 407 | 10.4k | variant_.Assign(std::forward<T>(alternative)); | 408 | 10.4k | return *this; | 409 | 10.4k | } |
cel::Value& cel::Value::operator=<cel::UintValue, void>(cel::UintValue&&) Line | Count | Source | 406 | 104 | Value& operator=(T&& alternative) noexcept { | 407 | 104 | variant_.Assign(std::forward<T>(alternative)); | 408 | 104 | return *this; | 409 | 104 | } |
cel::Value& cel::Value::operator=<cel::DoubleValue, void>(cel::DoubleValue&&) Line | Count | Source | 406 | 117 | Value& operator=(T&& alternative) noexcept { | 407 | 117 | variant_.Assign(std::forward<T>(alternative)); | 408 | 117 | return *this; | 409 | 117 | } |
cel::Value& cel::Value::operator=<cel::DurationValue, void>(cel::DurationValue&&) Line | Count | Source | 406 | 6 | Value& operator=(T&& alternative) noexcept { | 407 | 6 | variant_.Assign(std::forward<T>(alternative)); | 408 | 6 | return *this; | 409 | 6 | } |
cel::Value& cel::Value::operator=<cel::TimestampValue, void>(cel::TimestampValue&&) Line | Count | Source | 406 | 48 | Value& operator=(T&& alternative) noexcept { | 407 | 48 | variant_.Assign(std::forward<T>(alternative)); | 408 | 48 | return *this; | 409 | 48 | } |
cel::Value& cel::Value::operator=<cel::StringValue, void>(cel::StringValue&&) Line | Count | Source | 406 | 26 | Value& operator=(T&& alternative) noexcept { | 407 | 26 | variant_.Assign(std::forward<T>(alternative)); | 408 | 26 | return *this; | 409 | 26 | } |
Unexecuted instantiation: cel::Value& cel::Value::operator=<cel::StringValue const&, void>(cel::StringValue const&) cel::Value& cel::Value::operator=<cel::BytesValue, void>(cel::BytesValue&&) Line | Count | Source | 406 | 102 | Value& operator=(T&& alternative) noexcept { | 407 | 102 | variant_.Assign(std::forward<T>(alternative)); | 408 | 102 | return *this; | 409 | 102 | } |
cel::Value& cel::Value::operator=<cel::common_internal::LegacyStructValue, void>(cel::common_internal::LegacyStructValue&&) Line | Count | Source | 406 | 289 | Value& operator=(T&& alternative) noexcept { | 407 | 289 | variant_.Assign(std::forward<T>(alternative)); | 408 | 289 | return *this; | 409 | 289 | } |
Unexecuted instantiation: cel::Value& cel::Value::operator=<cel::TypeValue, void>(cel::TypeValue&&) |
410 | | |
411 | 1.15M | ValueKind kind() const { return variant_.kind(); } |
412 | | |
413 | | Type GetRuntimeType() const; |
414 | | |
415 | | absl::string_view GetTypeName() const; |
416 | | |
417 | | std::string DebugString() const; |
418 | | |
419 | | // `SerializeTo` serializes this value to `output`. If an error is returned, |
420 | | // `output` is in a valid but unspecified state. If this value does not |
421 | | // support serialization, `FAILED_PRECONDITION` is returned. |
422 | | absl::Status SerializeTo( |
423 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
424 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
425 | | google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const; |
426 | | |
427 | | // `ConvertToJson` converts this value to its JSON representation. The |
428 | | // argument `json` **MUST** be an instance of `google.protobuf.Value` which is |
429 | | // can either be the generated message or a dynamic message. The descriptor |
430 | | // pool `descriptor_pool` and message factory `message_factory` are used to |
431 | | // deal with serialized messages and a few corners cases. |
432 | | absl::Status ConvertToJson( |
433 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
434 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
435 | | google::protobuf::Message* absl_nonnull json) const; |
436 | | |
437 | | // `ConvertToJsonArray` converts this value to its JSON representation if and |
438 | | // only if it can be represented as an array. The argument `json` **MUST** be |
439 | | // an instance of `google.protobuf.ListValue` which is can either be the |
440 | | // generated message or a dynamic message. The descriptor pool |
441 | | // `descriptor_pool` and message factory `message_factory` are used to deal |
442 | | // with serialized messages and a few corners cases. |
443 | | absl::Status ConvertToJsonArray( |
444 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
445 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
446 | | google::protobuf::Message* absl_nonnull json) const; |
447 | | |
448 | | // `ConvertToJsonArray` converts this value to its JSON representation if and |
449 | | // only if it can be represented as an object. The argument `json` **MUST** be |
450 | | // an instance of `google.protobuf.Struct` which is can either be the |
451 | | // generated message or a dynamic message. The descriptor pool |
452 | | // `descriptor_pool` and message factory `message_factory` are used to deal |
453 | | // with serialized messages and a few corners cases. |
454 | | absl::Status ConvertToJsonObject( |
455 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
456 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
457 | | google::protobuf::Message* absl_nonnull json) const; |
458 | | |
459 | | absl::Status Equal(const Value& other, |
460 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
461 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
462 | | google::protobuf::Arena* absl_nonnull arena, |
463 | | Value* absl_nonnull result) const; |
464 | | using ValueMixin::Equal; |
465 | | |
466 | | bool IsZeroValue() const; |
467 | | |
468 | | // Clones the value to another arena, if necessary, such that the lifetime of |
469 | | // the value is tied to the arena. |
470 | | Value Clone(google::protobuf::Arena* absl_nonnull arena) const; |
471 | | |
472 | 0 | friend void swap(Value& lhs, Value& rhs) noexcept { |
473 | 0 | using std::swap; |
474 | 0 | swap(lhs.variant_, rhs.variant_); |
475 | 0 | } |
476 | | |
477 | | friend std::ostream& operator<<(std::ostream& out, const Value& value); |
478 | | |
479 | | ABSL_DEPRECATED("Just use operator.()") |
480 | 0 | Value* operator->() { return this; } |
481 | | |
482 | | ABSL_DEPRECATED("Just use operator.()") |
483 | 1.28M | const Value* operator->() const { return this; } |
484 | | |
485 | | // Returns `true` if this value is an instance of a bool value. |
486 | 31.9k | bool IsBool() const { return variant_.Is<BoolValue>(); } |
487 | | |
488 | | // Returns `true` if this value is an instance of a bool value and true. |
489 | 583 | bool IsTrue() const { return IsBool() && GetBool().NativeValue(); } |
490 | | |
491 | | // Returns `true` if this value is an instance of a bool value and false. |
492 | 42 | bool IsFalse() const { return IsBool() && !GetBool().NativeValue(); } |
493 | | |
494 | | // Returns `true` if this value is an instance of a bytes value. |
495 | 1.92k | bool IsBytes() const { return variant_.Is<BytesValue>(); } |
496 | | |
497 | | // Returns `true` if this value is an instance of a double value. |
498 | 12.3k | bool IsDouble() const { return variant_.Is<DoubleValue>(); } |
499 | | |
500 | | // Returns `true` if this value is an instance of a duration value. |
501 | 5 | bool IsDuration() const { return variant_.Is<DurationValue>(); } |
502 | | |
503 | | // Returns `true` if this value is an instance of an error value. |
504 | 265k | bool IsError() const { return variant_.Is<ErrorValue>(); } |
505 | | |
506 | | // Returns `true` if this value is an instance of an int value. |
507 | 34.7k | bool IsInt() const { return variant_.Is<IntValue>(); } |
508 | | |
509 | | // Returns `true` if this value is an instance of a list value. |
510 | 9.04k | bool IsList() const { |
511 | 9.04k | return variant_.Is<common_internal::LegacyListValue>() || |
512 | 9.04k | variant_.Is<CustomListValue>() || |
513 | 538 | variant_.Is<ParsedRepeatedFieldValue>() || |
514 | 538 | variant_.Is<ParsedJsonListValue>(); |
515 | 9.04k | } |
516 | | |
517 | | // Returns `true` if this value is an instance of a map value. |
518 | 4.15k | bool IsMap() const { |
519 | 4.15k | return variant_.Is<common_internal::LegacyMapValue>() || |
520 | 3.67k | variant_.Is<CustomMapValue>() || |
521 | 1.74k | variant_.Is<ParsedMapFieldValue>() || |
522 | 1.74k | variant_.Is<ParsedJsonMapValue>(); |
523 | 4.15k | } |
524 | | |
525 | | // Returns `true` if this value is an instance of a message value. If `true` |
526 | | // is returned, it is implied that `IsStruct()` would also return true. |
527 | 0 | bool IsMessage() const { return variant_.Is<ParsedMessageValue>(); } |
528 | | |
529 | | // Returns `true` if this value is an instance of a null value. |
530 | 7 | bool IsNull() const { return variant_.Is<NullValue>(); } |
531 | | |
532 | | // Returns `true` if this value is an instance of an opaque value. |
533 | 0 | bool IsOpaque() const { return variant_.Is<OpaqueValue>(); } |
534 | | |
535 | | // Returns `true` if this value is an instance of an optional value. If `true` |
536 | | // is returned, it is implied that `IsOpaque()` would also return true. |
537 | 0 | bool IsOptional() const { |
538 | 0 | if (const auto* alternative = variant_.As<OpaqueValue>(); |
539 | 0 | alternative != nullptr) { |
540 | 0 | return alternative->IsOptional(); |
541 | 0 | } |
542 | 0 | return false; |
543 | 0 | } |
544 | | |
545 | | // Returns `true` if this value is an instance of a parsed JSON list value. If |
546 | | // `true` is returned, it is implied that `IsList()` would also return |
547 | | // true. |
548 | 0 | bool IsParsedJsonList() const { return variant_.Is<ParsedJsonListValue>(); } |
549 | | |
550 | | // Returns `true` if this value is an instance of a parsed JSON map value. If |
551 | | // `true` is returned, it is implied that `IsMap()` would also return |
552 | | // true. |
553 | 0 | bool IsParsedJsonMap() const { return variant_.Is<ParsedJsonMapValue>(); } |
554 | | |
555 | | // Returns `true` if this value is an instance of a custom list value. If |
556 | | // `true` is returned, it is implied that `IsList()` would also return |
557 | | // true. |
558 | 0 | bool IsCustomList() const { return variant_.Is<CustomListValue>(); } |
559 | | |
560 | | // Returns `true` if this value is an instance of a custom map value. If |
561 | | // `true` is returned, it is implied that `IsMap()` would also return |
562 | | // true. |
563 | 0 | bool IsCustomMap() const { return variant_.Is<CustomMapValue>(); } |
564 | | |
565 | | // Returns `true` if this value is an instance of a parsed map field value. If |
566 | | // `true` is returned, it is implied that `IsMap()` would also return |
567 | | // true. |
568 | 0 | bool IsParsedMapField() const { return variant_.Is<ParsedMapFieldValue>(); } |
569 | | |
570 | | // Returns `true` if this value is an instance of a parsed message value. If |
571 | | // `true` is returned, it is implied that `IsMessage()` would also return |
572 | | // true. |
573 | 0 | bool IsParsedMessage() const { return variant_.Is<ParsedMessageValue>(); } |
574 | | |
575 | | // Returns `true` if this value is an instance of a parsed repeated field |
576 | | // value. If `true` is returned, it is implied that `IsList()` would also |
577 | | // return true. |
578 | 0 | bool IsParsedRepeatedField() const { |
579 | 0 | return variant_.Is<ParsedRepeatedFieldValue>(); |
580 | 0 | } |
581 | | |
582 | | // Returns `true` if this value is an instance of a custom struct value. If |
583 | | // `true` is returned, it is implied that `IsStruct()` would also return |
584 | | // true. |
585 | 0 | bool IsCustomStruct() const { return variant_.Is<CustomStructValue>(); } |
586 | | |
587 | | // Returns `true` if this value is an instance of a string value. |
588 | 9.25k | bool IsString() const { return variant_.Is<StringValue>(); } |
589 | | |
590 | | // Returns `true` if this value is an instance of a struct value. |
591 | 2.46k | bool IsStruct() const { |
592 | 2.46k | return variant_.Is<common_internal::LegacyStructValue>() || |
593 | 2.18k | variant_.Is<CustomStructValue>() || |
594 | 2.18k | variant_.Is<ParsedMessageValue>(); |
595 | 2.46k | } |
596 | | |
597 | | // Returns `true` if this value is an instance of a timestamp value. |
598 | 1 | bool IsTimestamp() const { return variant_.Is<TimestampValue>(); } |
599 | | |
600 | | // Returns `true` if this value is an instance of a type value. |
601 | 0 | bool IsType() const { return variant_.Is<TypeValue>(); } |
602 | | |
603 | | // Returns `true` if this value is an instance of a uint value. |
604 | 17.6k | bool IsUint() const { return variant_.Is<UintValue>(); } |
605 | | |
606 | | // Returns `true` if this value is an instance of an unknown value. |
607 | 84.4k | bool IsUnknown() const { return variant_.Is<UnknownValue>(); } |
608 | | |
609 | | // Convenience method for use with template metaprogramming. See |
610 | | // `IsBool()`. |
611 | | template <typename T> |
612 | 30.9k | std::enable_if_t<std::is_same_v<BoolValue, T>, bool> Is() const { |
613 | 30.9k | return IsBool(); |
614 | 30.9k | } |
615 | | |
616 | | // Convenience method for use with template metaprogramming. See |
617 | | // `IsBytes()`. |
618 | | template <typename T> |
619 | 1.92k | std::enable_if_t<std::is_same_v<BytesValue, T>, bool> Is() const { |
620 | 1.92k | return IsBytes(); |
621 | 1.92k | } |
622 | | |
623 | | // Convenience method for use with template metaprogramming. See |
624 | | // `IsDouble()`. |
625 | | template <typename T> |
626 | 2.48k | std::enable_if_t<std::is_same_v<DoubleValue, T>, bool> Is() const { |
627 | 2.48k | return IsDouble(); |
628 | 2.48k | } |
629 | | |
630 | | // Convenience method for use with template metaprogramming. See |
631 | | // `IsDuration()`. |
632 | | template <typename T> |
633 | | std::enable_if_t<std::is_same_v<DurationValue, T>, bool> Is() const { |
634 | | return IsDuration(); |
635 | | } |
636 | | |
637 | | // Convenience method for use with template metaprogramming. See |
638 | | // `IsError()`. |
639 | | template <typename T> |
640 | 199k | std::enable_if_t<std::is_same_v<ErrorValue, T>, bool> Is() const { |
641 | 199k | return IsError(); |
642 | 199k | } |
643 | | |
644 | | // Convenience method for use with template metaprogramming. See |
645 | | // `IsInt()`. |
646 | | template <typename T> |
647 | 6.13k | std::enable_if_t<std::is_same_v<IntValue, T>, bool> Is() const { |
648 | 6.13k | return IsInt(); |
649 | 6.13k | } |
650 | | |
651 | | // Convenience method for use with template metaprogramming. See |
652 | | // `IsList()`. |
653 | | template <typename T> |
654 | 6.97k | std::enable_if_t<std::is_same_v<ListValue, T>, bool> Is() const { |
655 | 6.97k | return IsList(); |
656 | 6.97k | } |
657 | | |
658 | | // Convenience method for use with template metaprogramming. See |
659 | | // `IsMap()`. |
660 | | template <typename T> |
661 | 3.61k | std::enable_if_t<std::is_same_v<MapValue, T>, bool> Is() const { |
662 | 3.61k | return IsMap(); |
663 | 3.61k | } |
664 | | |
665 | | // Convenience method for use with template metaprogramming. See |
666 | | // `IsMessage()`. |
667 | | template <typename T> |
668 | | std::enable_if_t<std::is_same_v<MessageValue, T>, bool> Is() const { |
669 | | return IsMessage(); |
670 | | } |
671 | | |
672 | | // Convenience method for use with template metaprogramming. See |
673 | | // `IsNull()`. |
674 | | template <typename T> |
675 | 0 | std::enable_if_t<std::is_same_v<NullValue, T>, bool> Is() const { |
676 | 0 | return IsNull(); |
677 | 0 | } |
678 | | |
679 | | // Convenience method for use with template metaprogramming. See |
680 | | // `IsOpaque()`. |
681 | | template <typename T> |
682 | 0 | std::enable_if_t<std::is_same_v<OpaqueValue, T>, bool> Is() const { |
683 | 0 | return IsOpaque(); |
684 | 0 | } |
685 | | |
686 | | // Convenience method for use with template metaprogramming. See |
687 | | // `IsOptional()`. |
688 | | template <typename T> |
689 | 0 | std::enable_if_t<std::is_same_v<OptionalValue, T>, bool> Is() const { |
690 | 0 | return IsOptional(); |
691 | 0 | } |
692 | | |
693 | | // Convenience method for use with template metaprogramming. See |
694 | | // `IsParsedJsonList()`. |
695 | | template <typename T> |
696 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, bool> Is() const { |
697 | | return IsParsedJsonList(); |
698 | | } |
699 | | |
700 | | // Convenience method for use with template metaprogramming. See |
701 | | // `IsParsedJsonMap()`. |
702 | | template <typename T> |
703 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, bool> Is() const { |
704 | | return IsParsedJsonMap(); |
705 | | } |
706 | | |
707 | | // Convenience method for use with template metaprogramming. See |
708 | | // `IsCustomList()`. |
709 | | template <typename T> |
710 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, bool> Is() const { |
711 | | return IsCustomList(); |
712 | | } |
713 | | |
714 | | // Convenience method for use with template metaprogramming. See |
715 | | // `IsCustomMap()`. |
716 | | template <typename T> |
717 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, bool> Is() const { |
718 | | return IsCustomMap(); |
719 | | } |
720 | | |
721 | | // Convenience method for use with template metaprogramming. See |
722 | | // `IsParsedMapField()`. |
723 | | template <typename T> |
724 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, bool> Is() const { |
725 | | return IsParsedMapField(); |
726 | | } |
727 | | |
728 | | // Convenience method for use with template metaprogramming. See |
729 | | // `IsParsedMessage()`. |
730 | | template <typename T> |
731 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, bool> Is() const { |
732 | | return IsParsedMessage(); |
733 | | } |
734 | | |
735 | | // Convenience method for use with template metaprogramming. See |
736 | | // `IsParsedRepeatedField()`. |
737 | | template <typename T> |
738 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, bool> Is() |
739 | | const { |
740 | | return IsParsedRepeatedField(); |
741 | | } |
742 | | |
743 | | // Convenience method for use with template metaprogramming. See |
744 | | // `IsParsedStruct()`. |
745 | | template <typename T> |
746 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, bool> Is() const { |
747 | | return IsCustomStruct(); |
748 | | } |
749 | | |
750 | | // Convenience method for use with template metaprogramming. See |
751 | | // `IsString()`. |
752 | | template <typename T> |
753 | 9.25k | std::enable_if_t<std::is_same_v<StringValue, T>, bool> Is() const { |
754 | 9.25k | return IsString(); |
755 | 9.25k | } |
756 | | |
757 | | // Convenience method for use with template metaprogramming. See |
758 | | // `IsStruct()`. |
759 | | template <typename T> |
760 | 1.66k | std::enable_if_t<std::is_same_v<StructValue, T>, bool> Is() const { |
761 | 1.66k | return IsStruct(); |
762 | 1.66k | } |
763 | | |
764 | | // Convenience method for use with template metaprogramming. See |
765 | | // `IsTimestamp()`. |
766 | | template <typename T> |
767 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, bool> Is() const { |
768 | | return IsTimestamp(); |
769 | | } |
770 | | |
771 | | // Convenience method for use with template metaprogramming. See |
772 | | // `IsType()`. |
773 | | template <typename T> |
774 | 0 | std::enable_if_t<std::is_same_v<TypeValue, T>, bool> Is() const { |
775 | 0 | return IsType(); |
776 | 0 | } |
777 | | |
778 | | // Convenience method for use with template metaprogramming. See |
779 | | // `IsUint()`. |
780 | | template <typename T> |
781 | 7.23k | std::enable_if_t<std::is_same_v<UintValue, T>, bool> Is() const { |
782 | 7.23k | return IsUint(); |
783 | 7.23k | } |
784 | | |
785 | | // Convenience method for use with template metaprogramming. See |
786 | | // `IsUnknown()`. |
787 | | template <typename T> |
788 | 65.7k | std::enable_if_t<std::is_same_v<UnknownValue, T>, bool> Is() const { |
789 | 65.7k | return IsUnknown(); |
790 | 65.7k | } |
791 | | |
792 | | // Performs a checked cast from a value to a bool value, |
793 | | // returning a non-empty optional with either a value or reference to the |
794 | | // bool value. Otherwise an empty optional is returned. |
795 | 12.5k | absl::optional<BoolValue> AsBool() const { |
796 | 12.5k | if (const auto* alternative = variant_.As<BoolValue>(); |
797 | 12.5k | alternative != nullptr) { |
798 | 11.7k | return *alternative; |
799 | 11.7k | } |
800 | 831 | return absl::nullopt; |
801 | 12.5k | } |
802 | | |
803 | | // Performs a checked cast from a value to a bytes value, |
804 | | // returning a non-empty optional with either a value or reference to the |
805 | | // bytes value. Otherwise an empty optional is returned. |
806 | 0 | optional_ref<const BytesValue> AsBytes() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
807 | 0 | return std::as_const(*this).AsBytes(); |
808 | 0 | } |
809 | | optional_ref<const BytesValue> AsBytes() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
810 | | absl::optional<BytesValue> AsBytes() &&; |
811 | 0 | absl::optional<BytesValue> AsBytes() const&& { |
812 | 0 | return common_internal::AsOptional(AsBytes()); |
813 | 0 | } |
814 | | |
815 | | // Performs a checked cast from a value to a double value, |
816 | | // returning a non-empty optional with either a value or reference to the |
817 | | // double value. Otherwise an empty optional is returned. |
818 | | absl::optional<DoubleValue> AsDouble() const; |
819 | | |
820 | | // Performs a checked cast from a value to a duration value, |
821 | | // returning a non-empty optional with either a value or reference to the |
822 | | // duration value. Otherwise an empty optional is returned. |
823 | | absl::optional<DurationValue> AsDuration() const; |
824 | | |
825 | | // Performs a checked cast from a value to an error value, |
826 | | // returning a non-empty optional with either a value or reference to the |
827 | | // error value. Otherwise an empty optional is returned. |
828 | 0 | optional_ref<const ErrorValue> AsError() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
829 | 0 | return std::as_const(*this).AsError(); |
830 | 0 | } |
831 | | optional_ref<const ErrorValue> AsError() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
832 | | absl::optional<ErrorValue> AsError() &&; |
833 | 0 | absl::optional<ErrorValue> AsError() const&& { |
834 | 0 | return common_internal::AsOptional(AsError()); |
835 | 0 | } |
836 | | |
837 | | // Performs a checked cast from a value to an int value, |
838 | | // returning a non-empty optional with either a value or reference to the |
839 | | // int value. Otherwise an empty optional is returned. |
840 | | absl::optional<IntValue> AsInt() const; |
841 | | |
842 | | // Performs a checked cast from a value to a list value, |
843 | | // returning a non-empty optional with either a value or reference to the |
844 | | // list value. Otherwise an empty optional is returned. |
845 | 0 | absl::optional<ListValue> AsList() & { return std::as_const(*this).AsList(); } |
846 | | absl::optional<ListValue> AsList() const&; |
847 | | absl::optional<ListValue> AsList() &&; |
848 | 0 | absl::optional<ListValue> AsList() const&& { |
849 | 0 | return common_internal::AsOptional(AsList()); |
850 | 0 | } |
851 | | |
852 | | // Performs a checked cast from a value to a map value, |
853 | | // returning a non-empty optional with either a value or reference to the |
854 | | // map value. Otherwise an empty optional is returned. |
855 | 0 | absl::optional<MapValue> AsMap() & { return std::as_const(*this).AsMap(); } |
856 | | absl::optional<MapValue> AsMap() const&; |
857 | | absl::optional<MapValue> AsMap() &&; |
858 | 0 | absl::optional<MapValue> AsMap() const&& { |
859 | 0 | return common_internal::AsOptional(AsMap()); |
860 | 0 | } |
861 | | |
862 | | // Performs a checked cast from a value to a message value, |
863 | | // returning a non-empty optional with either a value or reference to the |
864 | | // message value. Otherwise an empty optional is returned. |
865 | 0 | absl::optional<MessageValue> AsMessage() & { |
866 | 0 | return std::as_const(*this).AsMessage(); |
867 | 0 | } |
868 | | absl::optional<MessageValue> AsMessage() const&; |
869 | | absl::optional<MessageValue> AsMessage() &&; |
870 | 0 | absl::optional<MessageValue> AsMessage() const&& { |
871 | 0 | return common_internal::AsOptional(AsMessage()); |
872 | 0 | } |
873 | | |
874 | | // Performs a checked cast from a value to a null value, |
875 | | // returning a non-empty optional with either a value or reference to the |
876 | | // null value. Otherwise an empty optional is returned. |
877 | | absl::optional<NullValue> AsNull() const; |
878 | | |
879 | | // Performs a checked cast from a value to an opaque value, |
880 | | // returning a non-empty optional with either a value or reference to the |
881 | | // opaque value. Otherwise an empty optional is returned. |
882 | 0 | optional_ref<const OpaqueValue> AsOpaque() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
883 | 0 | return std::as_const(*this).AsOpaque(); |
884 | 0 | } |
885 | | optional_ref<const OpaqueValue> AsOpaque() |
886 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
887 | | absl::optional<OpaqueValue> AsOpaque() &&; |
888 | 0 | absl::optional<OpaqueValue> AsOpaque() const&& { |
889 | 0 | return common_internal::AsOptional(AsOpaque()); |
890 | 0 | } |
891 | | |
892 | | // Performs a checked cast from a value to an optional value, |
893 | | // returning a non-empty optional with either a value or reference to the |
894 | | // optional value. Otherwise an empty optional is returned. |
895 | | optional_ref<const OptionalValue> AsOptional() & |
896 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
897 | 0 | return std::as_const(*this).AsOptional(); |
898 | 0 | } |
899 | | optional_ref<const OptionalValue> AsOptional() |
900 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
901 | | absl::optional<OptionalValue> AsOptional() &&; |
902 | 0 | absl::optional<OptionalValue> AsOptional() const&& { |
903 | 0 | return common_internal::AsOptional(AsOptional()); |
904 | 0 | } |
905 | | |
906 | | // Performs a checked cast from a value to a parsed JSON list value, |
907 | | // returning a non-empty optional with either a value or reference to the |
908 | | // parsed message value. Otherwise an empty optional is returned. |
909 | | optional_ref<const ParsedJsonListValue> AsParsedJsonList() & |
910 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
911 | 0 | return std::as_const(*this).AsParsedJsonList(); |
912 | 0 | } |
913 | | optional_ref<const ParsedJsonListValue> AsParsedJsonList() |
914 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
915 | | absl::optional<ParsedJsonListValue> AsParsedJsonList() &&; |
916 | 0 | absl::optional<ParsedJsonListValue> AsParsedJsonList() const&& { |
917 | 0 | return common_internal::AsOptional(AsParsedJsonList()); |
918 | 0 | } |
919 | | |
920 | | // Performs a checked cast from a value to a parsed JSON map value, |
921 | | // returning a non-empty optional with either a value or reference to the |
922 | | // parsed message value. Otherwise an empty optional is returned. |
923 | | optional_ref<const ParsedJsonMapValue> AsParsedJsonMap() & |
924 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
925 | 0 | return std::as_const(*this).AsParsedJsonMap(); |
926 | 0 | } |
927 | | optional_ref<const ParsedJsonMapValue> AsParsedJsonMap() |
928 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
929 | | absl::optional<ParsedJsonMapValue> AsParsedJsonMap() &&; |
930 | 0 | absl::optional<ParsedJsonMapValue> AsParsedJsonMap() const&& { |
931 | 0 | return common_internal::AsOptional(AsParsedJsonMap()); |
932 | 0 | } |
933 | | |
934 | | // Performs a checked cast from a value to a custom list value, |
935 | | // returning a non-empty optional with either a value or reference to the |
936 | | // custom list value. Otherwise an empty optional is returned. |
937 | | optional_ref<const CustomListValue> AsCustomList() & |
938 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
939 | 0 | return std::as_const(*this).AsCustomList(); |
940 | 0 | } |
941 | | optional_ref<const CustomListValue> AsCustomList() |
942 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
943 | | absl::optional<CustomListValue> AsCustomList() &&; |
944 | 0 | absl::optional<CustomListValue> AsCustomList() const&& { |
945 | 0 | return common_internal::AsOptional(AsCustomList()); |
946 | 0 | } |
947 | | |
948 | | // Performs a checked cast from a value to a custom map value, |
949 | | // returning a non-empty optional with either a value or reference to the |
950 | | // custom map value. Otherwise an empty optional is returned. |
951 | | optional_ref<const CustomMapValue> AsCustomMap() & |
952 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
953 | 0 | return std::as_const(*this).AsCustomMap(); |
954 | 0 | } |
955 | | optional_ref<const CustomMapValue> AsCustomMap() |
956 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
957 | | absl::optional<CustomMapValue> AsCustomMap() &&; |
958 | 0 | absl::optional<CustomMapValue> AsCustomMap() const&& { |
959 | 0 | return common_internal::AsOptional(AsCustomMap()); |
960 | 0 | } |
961 | | |
962 | | // Performs a checked cast from a value to a parsed map field value, |
963 | | // returning a non-empty optional with either a value or reference to the |
964 | | // parsed map field value. Otherwise an empty optional is returned. |
965 | | optional_ref<const ParsedMapFieldValue> AsParsedMapField() & |
966 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
967 | 0 | return std::as_const(*this).AsParsedMapField(); |
968 | 0 | } |
969 | | optional_ref<const ParsedMapFieldValue> AsParsedMapField() |
970 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
971 | | absl::optional<ParsedMapFieldValue> AsParsedMapField() &&; |
972 | 0 | absl::optional<ParsedMapFieldValue> AsParsedMapField() const&& { |
973 | 0 | return common_internal::AsOptional(AsParsedMapField()); |
974 | 0 | } |
975 | | |
976 | | // Performs a checked cast from a value to a parsed message value, |
977 | | // returning a non-empty optional with either a value or reference to the |
978 | | // parsed message value. Otherwise an empty optional is returned. |
979 | | optional_ref<const ParsedMessageValue> AsParsedMessage() & |
980 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
981 | 0 | return std::as_const(*this).AsParsedMessage(); |
982 | 0 | } |
983 | | optional_ref<const ParsedMessageValue> AsParsedMessage() |
984 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
985 | | absl::optional<ParsedMessageValue> AsParsedMessage() &&; |
986 | 0 | absl::optional<ParsedMessageValue> AsParsedMessage() const&& { |
987 | 0 | return common_internal::AsOptional(AsParsedMessage()); |
988 | 0 | } |
989 | | |
990 | | // Performs a checked cast from a value to a parsed repeated field value, |
991 | | // returning a non-empty optional with either a value or reference to the |
992 | | // parsed repeated field value. Otherwise an empty optional is returned. |
993 | | optional_ref<const ParsedRepeatedFieldValue> AsParsedRepeatedField() & |
994 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
995 | 0 | return std::as_const(*this).AsParsedRepeatedField(); |
996 | 0 | } |
997 | | optional_ref<const ParsedRepeatedFieldValue> AsParsedRepeatedField() |
998 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
999 | | absl::optional<ParsedRepeatedFieldValue> AsParsedRepeatedField() &&; |
1000 | 0 | absl::optional<ParsedRepeatedFieldValue> AsParsedRepeatedField() const&& { |
1001 | 0 | return common_internal::AsOptional(AsParsedRepeatedField()); |
1002 | 0 | } |
1003 | | |
1004 | | // Performs a checked cast from a value to a custom struct value, |
1005 | | // returning a non-empty optional with either a value or reference to the |
1006 | | // custom struct value. Otherwise an empty optional is returned. |
1007 | | optional_ref<const CustomStructValue> AsCustomStruct() & |
1008 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1009 | 0 | return std::as_const(*this).AsCustomStruct(); |
1010 | 0 | } |
1011 | | optional_ref<const CustomStructValue> AsCustomStruct() |
1012 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1013 | | absl::optional<CustomStructValue> AsCustomStruct() &&; |
1014 | 0 | absl::optional<CustomStructValue> AsCustomStruct() const&& { |
1015 | 0 | return common_internal::AsOptional(AsCustomStruct()); |
1016 | 0 | } |
1017 | | |
1018 | | // Performs a checked cast from a value to a string value, |
1019 | | // returning a non-empty optional with either a value or reference to the |
1020 | | // string value. Otherwise an empty optional is returned. |
1021 | 0 | optional_ref<const StringValue> AsString() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1022 | 0 | return std::as_const(*this).AsString(); |
1023 | 0 | } |
1024 | | optional_ref<const StringValue> AsString() |
1025 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1026 | | absl::optional<StringValue> AsString() &&; |
1027 | 0 | absl::optional<StringValue> AsString() const&& { |
1028 | 0 | return common_internal::AsOptional(AsString()); |
1029 | 0 | } |
1030 | | |
1031 | | // Performs a checked cast from a value to a struct value, |
1032 | | // returning a non-empty optional with either a value or reference to the |
1033 | | // struct value. Otherwise an empty optional is returned. |
1034 | 0 | absl::optional<StructValue> AsStruct() & { |
1035 | 0 | return std::as_const(*this).AsStruct(); |
1036 | 0 | } |
1037 | | absl::optional<StructValue> AsStruct() const&; |
1038 | | absl::optional<StructValue> AsStruct() &&; |
1039 | 0 | absl::optional<StructValue> AsStruct() const&& { |
1040 | 0 | return common_internal::AsOptional(AsStruct()); |
1041 | 0 | } |
1042 | | |
1043 | | // Performs a checked cast from a value to a timestamp value, |
1044 | | // returning a non-empty optional with either a value or reference to the |
1045 | | // timestamp value. Otherwise an empty optional is returned. |
1046 | | absl::optional<TimestampValue> AsTimestamp() const; |
1047 | | |
1048 | | // Performs a checked cast from a value to a type value, |
1049 | | // returning a non-empty optional with either a value or reference to the |
1050 | | // type value. Otherwise an empty optional is returned. |
1051 | 0 | optional_ref<const TypeValue> AsType() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1052 | 0 | return std::as_const(*this).AsType(); |
1053 | 0 | } |
1054 | | optional_ref<const TypeValue> AsType() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1055 | | absl::optional<TypeValue> AsType() &&; |
1056 | 0 | absl::optional<TypeValue> AsType() const&& { |
1057 | 0 | return common_internal::AsOptional(AsType()); |
1058 | 0 | } |
1059 | | |
1060 | | // Performs a checked cast from a value to an uint value, |
1061 | | // returning a non-empty optional with either a value or reference to the |
1062 | | // uint value. Otherwise an empty optional is returned. |
1063 | | absl::optional<UintValue> AsUint() const; |
1064 | | |
1065 | | // Performs a checked cast from a value to an unknown value, |
1066 | | // returning a non-empty optional with either a value or reference to the |
1067 | | // unknown value. Otherwise an empty optional is returned. |
1068 | 0 | optional_ref<const UnknownValue> AsUnknown() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1069 | 0 | return std::as_const(*this).AsUnknown(); |
1070 | 0 | } |
1071 | | optional_ref<const UnknownValue> AsUnknown() |
1072 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1073 | | absl::optional<UnknownValue> AsUnknown() &&; |
1074 | 0 | absl::optional<UnknownValue> AsUnknown() const&& { |
1075 | 0 | return common_internal::AsOptional(AsUnknown()); |
1076 | 0 | } |
1077 | | |
1078 | | // Convenience method for use with template metaprogramming. See |
1079 | | // `AsBool()`. |
1080 | | template <typename T> |
1081 | | std::enable_if_t<std::is_same_v<BoolValue, T>, absl::optional<BoolValue>> |
1082 | 11.4k | As() & { |
1083 | 11.4k | return AsBool(); |
1084 | 11.4k | } |
1085 | | template <typename T> |
1086 | | std::enable_if_t<std::is_same_v<BoolValue, T>, absl::optional<BoolValue>> As() |
1087 | 0 | const& { |
1088 | 0 | return AsBool(); |
1089 | 0 | } |
1090 | | template <typename T> |
1091 | | std::enable_if_t<std::is_same_v<BoolValue, T>, absl::optional<BoolValue>> |
1092 | | As() && { |
1093 | | return AsBool(); |
1094 | | } |
1095 | | template <typename T> |
1096 | | std::enable_if_t<std::is_same_v<BoolValue, T>, absl::optional<BoolValue>> As() |
1097 | | const&& { |
1098 | | return AsBool(); |
1099 | | } |
1100 | | |
1101 | | // Convenience method for use with template metaprogramming. See |
1102 | | // `AsBytes()`. |
1103 | | template <typename T> |
1104 | | std::enable_if_t<std::is_same_v<BytesValue, T>, |
1105 | | optional_ref<const BytesValue>> |
1106 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1107 | | return AsBytes(); |
1108 | | } |
1109 | | template <typename T> |
1110 | | std::enable_if_t<std::is_same_v<BytesValue, T>, |
1111 | | optional_ref<const BytesValue>> |
1112 | 0 | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1113 | 0 | return AsBytes(); |
1114 | 0 | } |
1115 | | template <typename T> |
1116 | | std::enable_if_t<std::is_same_v<BytesValue, T>, absl::optional<BytesValue>> |
1117 | | As() && { |
1118 | | return std::move(*this).AsBytes(); |
1119 | | } |
1120 | | template <typename T> |
1121 | | std::enable_if_t<std::is_same_v<BytesValue, T>, absl::optional<BytesValue>> |
1122 | | As() const&& { |
1123 | | return std::move(*this).AsBytes(); |
1124 | | } |
1125 | | |
1126 | | // Convenience method for use with template metaprogramming. See |
1127 | | // `AsDouble()`. |
1128 | | template <typename T> |
1129 | | std::enable_if_t<std::is_same_v<DoubleValue, T>, absl::optional<DoubleValue>> |
1130 | | As() & { |
1131 | | return AsDouble(); |
1132 | | } |
1133 | | template <typename T> |
1134 | | std::enable_if_t<std::is_same_v<DoubleValue, T>, absl::optional<DoubleValue>> |
1135 | 0 | As() const& { |
1136 | 0 | return AsDouble(); |
1137 | 0 | } |
1138 | | template <typename T> |
1139 | | std::enable_if_t<std::is_same_v<DoubleValue, T>, absl::optional<DoubleValue>> |
1140 | | As() && { |
1141 | | return AsDouble(); |
1142 | | } |
1143 | | template <typename T> |
1144 | | std::enable_if_t<std::is_same_v<DoubleValue, T>, absl::optional<DoubleValue>> |
1145 | | As() const&& { |
1146 | | return AsDouble(); |
1147 | | } |
1148 | | |
1149 | | // Convenience method for use with template metaprogramming. See |
1150 | | // `AsDuration()`. |
1151 | | template <typename T> |
1152 | | std::enable_if_t<std::is_same_v<DurationValue, T>, |
1153 | | absl::optional<DurationValue>> |
1154 | | As() & { |
1155 | | return AsDuration(); |
1156 | | } |
1157 | | template <typename T> |
1158 | | std::enable_if_t<std::is_same_v<DurationValue, T>, |
1159 | | absl::optional<DurationValue>> |
1160 | | As() const& { |
1161 | | return AsDuration(); |
1162 | | } |
1163 | | template <typename T> |
1164 | | std::enable_if_t<std::is_same_v<DurationValue, T>, |
1165 | | absl::optional<DurationValue>> |
1166 | | As() && { |
1167 | | return AsDuration(); |
1168 | | } |
1169 | | template <typename T> |
1170 | | std::enable_if_t<std::is_same_v<DurationValue, T>, |
1171 | | absl::optional<DurationValue>> |
1172 | | As() const&& { |
1173 | | return AsDuration(); |
1174 | | } |
1175 | | |
1176 | | // Convenience method for use with template metaprogramming. See |
1177 | | // `AsError()`. |
1178 | | template <typename T> |
1179 | | std::enable_if_t<std::is_same_v<ErrorValue, T>, |
1180 | | optional_ref<const ErrorValue>> |
1181 | 0 | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1182 | 0 | return AsError(); |
1183 | 0 | } |
1184 | | template <typename T> |
1185 | | std::enable_if_t<std::is_same_v<ErrorValue, T>, |
1186 | | optional_ref<const ErrorValue>> |
1187 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1188 | | return AsError(); |
1189 | | } |
1190 | | template <typename T> |
1191 | | std::enable_if_t<std::is_same_v<ErrorValue, T>, absl::optional<ErrorValue>> |
1192 | | As() && { |
1193 | | return std::move(*this).AsError(); |
1194 | | } |
1195 | | template <typename T> |
1196 | | std::enable_if_t<std::is_same_v<ErrorValue, T>, absl::optional<ErrorValue>> |
1197 | | As() const&& { |
1198 | | return std::move(*this).AsError(); |
1199 | | } |
1200 | | |
1201 | | // Convenience method for use with template metaprogramming. See |
1202 | | // `AsInt()`. |
1203 | | template <typename T> |
1204 | | std::enable_if_t<std::is_same_v<IntValue, T>, absl::optional<IntValue>> |
1205 | | As() & { |
1206 | | return AsInt(); |
1207 | | } |
1208 | | template <typename T> |
1209 | | std::enable_if_t<std::is_same_v<IntValue, T>, absl::optional<IntValue>> As() |
1210 | 0 | const& { |
1211 | 0 | return AsInt(); |
1212 | 0 | } |
1213 | | template <typename T> |
1214 | | std::enable_if_t<std::is_same_v<IntValue, T>, absl::optional<IntValue>> |
1215 | | As() && { |
1216 | | return AsInt(); |
1217 | | } |
1218 | | template <typename T> |
1219 | | std::enable_if_t<std::is_same_v<IntValue, T>, absl::optional<IntValue>> As() |
1220 | | const&& { |
1221 | | return AsInt(); |
1222 | | } |
1223 | | |
1224 | | // Convenience method for use with template metaprogramming. See |
1225 | | // `AsList()`. |
1226 | | template <typename T> |
1227 | | std::enable_if_t<std::is_same_v<ListValue, T>, absl::optional<ListValue>> |
1228 | | As() & { |
1229 | | return AsList(); |
1230 | | } |
1231 | | template <typename T> |
1232 | | std::enable_if_t<std::is_same_v<ListValue, T>, absl::optional<ListValue>> As() |
1233 | | const& { |
1234 | | return AsList(); |
1235 | | } |
1236 | | template <typename T> |
1237 | | std::enable_if_t<std::is_same_v<ListValue, T>, absl::optional<ListValue>> |
1238 | | As() && { |
1239 | | return std::move(*this).AsList(); |
1240 | | } |
1241 | | template <typename T> |
1242 | | std::enable_if_t<std::is_same_v<ListValue, T>, absl::optional<ListValue>> As() |
1243 | | const&& { |
1244 | | return std::move(*this).AsList(); |
1245 | | } |
1246 | | |
1247 | | // Convenience method for use with template metaprogramming. See |
1248 | | // `AsMap()`. |
1249 | | template <typename T> |
1250 | | std::enable_if_t<std::is_same_v<MapValue, T>, absl::optional<MapValue>> |
1251 | | As() & { |
1252 | | return AsMap(); |
1253 | | } |
1254 | | template <typename T> |
1255 | | std::enable_if_t<std::is_same_v<MapValue, T>, absl::optional<MapValue>> As() |
1256 | | const& { |
1257 | | return AsMap(); |
1258 | | } |
1259 | | template <typename T> |
1260 | | std::enable_if_t<std::is_same_v<MapValue, T>, absl::optional<MapValue>> |
1261 | | As() && { |
1262 | | return std::move(*this).AsMap(); |
1263 | | } |
1264 | | template <typename T> |
1265 | | std::enable_if_t<std::is_same_v<MapValue, T>, absl::optional<MapValue>> As() |
1266 | | const&& { |
1267 | | return std::move(*this).AsMap(); |
1268 | | } |
1269 | | |
1270 | | // Convenience method for use with template metaprogramming. See |
1271 | | // `AsMessage()`. |
1272 | | template <typename T> |
1273 | | std::enable_if_t<std::is_same_v<MessageValue, T>, |
1274 | | absl::optional<MessageValue>> |
1275 | | As() & { |
1276 | | return AsMessage(); |
1277 | | } |
1278 | | template <typename T> |
1279 | | std::enable_if_t<std::is_same_v<MessageValue, T>, |
1280 | | absl::optional<MessageValue>> |
1281 | | As() const& { |
1282 | | return AsMessage(); |
1283 | | } |
1284 | | template <typename T> |
1285 | | std::enable_if_t<std::is_same_v<MessageValue, T>, |
1286 | | absl::optional<MessageValue>> |
1287 | | As() && { |
1288 | | return std::move(*this).AsMessage(); |
1289 | | } |
1290 | | template <typename T> |
1291 | | std::enable_if_t<std::is_same_v<MessageValue, T>, |
1292 | | absl::optional<MessageValue>> |
1293 | | As() const&& { |
1294 | | return std::move(*this).AsMessage(); |
1295 | | } |
1296 | | |
1297 | | // Convenience method for use with template metaprogramming. See |
1298 | | // `AsNull()`. |
1299 | | template <typename T> |
1300 | | std::enable_if_t<std::is_same_v<NullValue, T>, absl::optional<NullValue>> |
1301 | | As() & { |
1302 | | return AsNull(); |
1303 | | } |
1304 | | template <typename T> |
1305 | | std::enable_if_t<std::is_same_v<NullValue, T>, absl::optional<NullValue>> As() |
1306 | | const& { |
1307 | | return AsNull(); |
1308 | | } |
1309 | | template <typename T> |
1310 | | std::enable_if_t<std::is_same_v<NullValue, T>, absl::optional<NullValue>> |
1311 | | As() && { |
1312 | | return AsNull(); |
1313 | | } |
1314 | | template <typename T> |
1315 | | std::enable_if_t<std::is_same_v<NullValue, T>, absl::optional<NullValue>> As() |
1316 | | const&& { |
1317 | | return AsNull(); |
1318 | | } |
1319 | | |
1320 | | // Convenience method for use with template metaprogramming. See |
1321 | | // `AsOpaque()`. |
1322 | | template <typename T> |
1323 | | std::enable_if_t<std::is_same_v<OpaqueValue, T>, |
1324 | | optional_ref<const OpaqueValue>> |
1325 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1326 | | return AsOpaque(); |
1327 | | } |
1328 | | template <typename T> |
1329 | | std::enable_if_t<std::is_same_v<OpaqueValue, T>, |
1330 | | optional_ref<const OpaqueValue>> |
1331 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1332 | | return AsOpaque(); |
1333 | | } |
1334 | | template <typename T> |
1335 | | std::enable_if_t<std::is_same_v<OpaqueValue, T>, absl::optional<OpaqueValue>> |
1336 | | As() && { |
1337 | | return std::move(*this).AsOpaque(); |
1338 | | } |
1339 | | template <typename T> |
1340 | | std::enable_if_t<std::is_same_v<OpaqueValue, T>, absl::optional<OpaqueValue>> |
1341 | | As() const&& { |
1342 | | return std::move(*this).AsOpaque(); |
1343 | | } |
1344 | | |
1345 | | // Convenience method for use with template metaprogramming. See |
1346 | | // `AsOptional()`. |
1347 | | template <typename T> |
1348 | | std::enable_if_t<std::is_same_v<OptionalValue, T>, |
1349 | | optional_ref<const OptionalValue>> |
1350 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1351 | | return AsOptional(); |
1352 | | } |
1353 | | template <typename T> |
1354 | | std::enable_if_t<std::is_same_v<OptionalValue, T>, |
1355 | | optional_ref<const OptionalValue>> |
1356 | 0 | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1357 | 0 | return AsOptional(); |
1358 | 0 | } |
1359 | | template <typename T> |
1360 | | std::enable_if_t<std::is_same_v<OptionalValue, T>, |
1361 | | absl::optional<OptionalValue>> |
1362 | | As() && { |
1363 | | return std::move(*this).AsOptional(); |
1364 | | } |
1365 | | template <typename T> |
1366 | | std::enable_if_t<std::is_same_v<OptionalValue, T>, |
1367 | | absl::optional<OptionalValue>> |
1368 | | As() const&& { |
1369 | | return std::move(*this).AsOptional(); |
1370 | | } |
1371 | | |
1372 | | // Convenience method for use with template metaprogramming. See |
1373 | | // `AsParsedJsonList()`. |
1374 | | template <typename T> |
1375 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, |
1376 | | optional_ref<const ParsedJsonListValue>> |
1377 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1378 | | return AsParsedJsonList(); |
1379 | | } |
1380 | | template <typename T> |
1381 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, |
1382 | | optional_ref<const ParsedJsonListValue>> |
1383 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1384 | | return AsParsedJsonList(); |
1385 | | } |
1386 | | template <typename T> |
1387 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, |
1388 | | absl::optional<ParsedJsonListValue>> |
1389 | | As() && { |
1390 | | return std::move(*this).AsParsedJsonList(); |
1391 | | } |
1392 | | template <typename T> |
1393 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, |
1394 | | absl::optional<ParsedJsonListValue>> |
1395 | | As() const&& { |
1396 | | return std::move(*this).AsParsedJsonList(); |
1397 | | } |
1398 | | |
1399 | | // Convenience method for use with template metaprogramming. See |
1400 | | // `AsParsedJsonMap()`. |
1401 | | template <typename T> |
1402 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, |
1403 | | optional_ref<const ParsedJsonMapValue>> |
1404 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1405 | | return AsParsedJsonMap(); |
1406 | | } |
1407 | | template <typename T> |
1408 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, |
1409 | | optional_ref<const ParsedJsonMapValue>> |
1410 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1411 | | return AsParsedJsonMap(); |
1412 | | } |
1413 | | template <typename T> |
1414 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, |
1415 | | absl::optional<ParsedJsonMapValue>> |
1416 | | As() && { |
1417 | | return std::move(*this).AsParsedJsonMap(); |
1418 | | } |
1419 | | template <typename T> |
1420 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, |
1421 | | absl::optional<ParsedJsonMapValue>> |
1422 | | As() const&& { |
1423 | | return std::move(*this).AsParsedJsonMap(); |
1424 | | } |
1425 | | |
1426 | | // Convenience method for use with template metaprogramming. See |
1427 | | // `AsCustomList()`. |
1428 | | template <typename T> |
1429 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, |
1430 | | optional_ref<const CustomListValue>> |
1431 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1432 | | return AsCustomList(); |
1433 | | } |
1434 | | template <typename T> |
1435 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, |
1436 | | optional_ref<const CustomListValue>> |
1437 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1438 | | return AsCustomList(); |
1439 | | } |
1440 | | template <typename T> |
1441 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, |
1442 | | absl::optional<CustomListValue>> |
1443 | | As() && { |
1444 | | return std::move(*this).AsCustomList(); |
1445 | | } |
1446 | | template <typename T> |
1447 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, |
1448 | | absl::optional<CustomListValue>> |
1449 | | As() const&& { |
1450 | | return std::move(*this).AsCustomList(); |
1451 | | } |
1452 | | |
1453 | | // Convenience method for use with template metaprogramming. See |
1454 | | // `AsCustomMap()`. |
1455 | | template <typename T> |
1456 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, |
1457 | | optional_ref<const CustomMapValue>> |
1458 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1459 | | return AsCustomMap(); |
1460 | | } |
1461 | | template <typename T> |
1462 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, |
1463 | | optional_ref<const CustomMapValue>> |
1464 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1465 | | return AsCustomMap(); |
1466 | | } |
1467 | | template <typename T> |
1468 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, |
1469 | | absl::optional<CustomMapValue>> |
1470 | | As() && { |
1471 | | return std::move(*this).AsCustomMap(); |
1472 | | } |
1473 | | template <typename T> |
1474 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, |
1475 | | absl::optional<CustomMapValue>> |
1476 | | As() const&& { |
1477 | | return std::move(*this).AsCustomMap(); |
1478 | | } |
1479 | | |
1480 | | // Convenience method for use with template metaprogramming. See |
1481 | | // `AsParsedMapField()`. |
1482 | | template <typename T> |
1483 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, |
1484 | | optional_ref<const ParsedMapFieldValue>> |
1485 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1486 | | return AsParsedMapField(); |
1487 | | } |
1488 | | template <typename T> |
1489 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, |
1490 | | optional_ref<const ParsedMapFieldValue>> |
1491 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1492 | | return AsParsedMapField(); |
1493 | | } |
1494 | | template <typename T> |
1495 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, |
1496 | | absl::optional<ParsedMapFieldValue>> |
1497 | | As() && { |
1498 | | return std::move(*this).AsParsedMapField(); |
1499 | | } |
1500 | | template <typename T> |
1501 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, |
1502 | | absl::optional<ParsedMapFieldValue>> |
1503 | | As() const&& { |
1504 | | return std::move(*this).AsParsedMapField(); |
1505 | | } |
1506 | | |
1507 | | // Convenience method for use with template metaprogramming. See |
1508 | | // `AsParsedMessage()`. |
1509 | | template <typename T> |
1510 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, |
1511 | | optional_ref<const ParsedMessageValue>> |
1512 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1513 | | return AsParsedMessage(); |
1514 | | } |
1515 | | template <typename T> |
1516 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, |
1517 | | optional_ref<const ParsedMessageValue>> |
1518 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1519 | | return AsParsedMessage(); |
1520 | | } |
1521 | | template <typename T> |
1522 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, |
1523 | | absl::optional<ParsedMessageValue>> |
1524 | | As() && { |
1525 | | return std::move(*this).AsParsedMessage(); |
1526 | | } |
1527 | | template <typename T> |
1528 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, |
1529 | | absl::optional<ParsedMessageValue>> |
1530 | | As() const&& { |
1531 | | return std::move(*this).AsParsedMessage(); |
1532 | | } |
1533 | | |
1534 | | // Convenience method for use with template metaprogramming. See |
1535 | | // `AsParsedRepeatedField()`. |
1536 | | template <typename T> |
1537 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, |
1538 | | optional_ref<const ParsedRepeatedFieldValue>> |
1539 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1540 | | return AsParsedRepeatedField(); |
1541 | | } |
1542 | | template <typename T> |
1543 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, |
1544 | | optional_ref<const ParsedRepeatedFieldValue>> |
1545 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1546 | | return AsParsedRepeatedField(); |
1547 | | } |
1548 | | template <typename T> |
1549 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, |
1550 | | absl::optional<ParsedRepeatedFieldValue>> |
1551 | | As() && { |
1552 | | return std::move(*this).AsParsedRepeatedField(); |
1553 | | } |
1554 | | template <typename T> |
1555 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, |
1556 | | absl::optional<ParsedRepeatedFieldValue>> |
1557 | | As() const&& { |
1558 | | return std::move(*this).AsParsedRepeatedField(); |
1559 | | } |
1560 | | |
1561 | | // Convenience method for use with template metaprogramming. See |
1562 | | // `AsCustomStruct()`. |
1563 | | template <typename T> |
1564 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, |
1565 | | optional_ref<const CustomStructValue>> |
1566 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1567 | | return AsCustomStruct(); |
1568 | | } |
1569 | | template <typename T> |
1570 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, |
1571 | | optional_ref<const CustomStructValue>> |
1572 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1573 | | return AsCustomStruct(); |
1574 | | } |
1575 | | template <typename T> |
1576 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, |
1577 | | absl::optional<CustomStructValue>> |
1578 | | As() && { |
1579 | | return std::move(*this).AsCustomStruct(); |
1580 | | } |
1581 | | template <typename T> |
1582 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, |
1583 | | absl::optional<CustomStructValue>> |
1584 | | As() const&& { |
1585 | | return std::move(*this).AsCustomStruct(); |
1586 | | } |
1587 | | |
1588 | | // Convenience method for use with template metaprogramming. See |
1589 | | // `AsString()`. |
1590 | | template <typename T> |
1591 | | std::enable_if_t<std::is_same_v<StringValue, T>, |
1592 | | optional_ref<const StringValue>> |
1593 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1594 | | return AsString(); |
1595 | | } |
1596 | | template <typename T> |
1597 | | std::enable_if_t<std::is_same_v<StringValue, T>, |
1598 | | optional_ref<const StringValue>> |
1599 | 0 | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1600 | 0 | return AsString(); |
1601 | 0 | } |
1602 | | template <typename T> |
1603 | | std::enable_if_t<std::is_same_v<StringValue, T>, absl::optional<StringValue>> |
1604 | | As() && { |
1605 | | return std::move(*this).AsString(); |
1606 | | } |
1607 | | template <typename T> |
1608 | | std::enable_if_t<std::is_same_v<StringValue, T>, absl::optional<StringValue>> |
1609 | | As() const&& { |
1610 | | return std::move(*this).AsString(); |
1611 | | } |
1612 | | |
1613 | | // Convenience method for use with template metaprogramming. See |
1614 | | // `AsStruct()`. |
1615 | | template <typename T> |
1616 | | std::enable_if_t<std::is_same_v<StructValue, T>, absl::optional<StructValue>> |
1617 | | As() & { |
1618 | | return AsStruct(); |
1619 | | } |
1620 | | template <typename T> |
1621 | | std::enable_if_t<std::is_same_v<StructValue, T>, absl::optional<StructValue>> |
1622 | | As() const& { |
1623 | | return AsStruct(); |
1624 | | } |
1625 | | template <typename T> |
1626 | | std::enable_if_t<std::is_same_v<StructValue, T>, absl::optional<StructValue>> |
1627 | | As() && { |
1628 | | return std::move(*this).AsStruct(); |
1629 | | } |
1630 | | template <typename T> |
1631 | | std::enable_if_t<std::is_same_v<StructValue, T>, absl::optional<StructValue>> |
1632 | | As() const&& { |
1633 | | return std::move(*this).AsStruct(); |
1634 | | } |
1635 | | |
1636 | | // Convenience method for use with template metaprogramming. See |
1637 | | // `AsTimestamp()`. |
1638 | | template <typename T> |
1639 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, |
1640 | | absl::optional<TimestampValue>> |
1641 | | As() & { |
1642 | | return AsTimestamp(); |
1643 | | } |
1644 | | template <typename T> |
1645 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, |
1646 | | absl::optional<TimestampValue>> |
1647 | | As() const& { |
1648 | | return AsTimestamp(); |
1649 | | } |
1650 | | template <typename T> |
1651 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, |
1652 | | absl::optional<TimestampValue>> |
1653 | | As() && { |
1654 | | return AsTimestamp(); |
1655 | | } |
1656 | | template <typename T> |
1657 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, |
1658 | | absl::optional<TimestampValue>> |
1659 | | As() const&& { |
1660 | | return AsTimestamp(); |
1661 | | } |
1662 | | |
1663 | | // Convenience method for use with template metaprogramming. See |
1664 | | // `AsType()`. |
1665 | | template <typename T> |
1666 | | std::enable_if_t<std::is_same_v<TypeValue, T>, |
1667 | | optional_ref<const TypeValue>> |
1668 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1669 | | return AsType(); |
1670 | | } |
1671 | | template <typename T> |
1672 | | std::enable_if_t<std::is_same_v<TypeValue, T>, optional_ref<const TypeValue>> |
1673 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1674 | | return AsType(); |
1675 | | } |
1676 | | template <typename T> |
1677 | | std::enable_if_t<std::is_same_v<TypeValue, T>, absl::optional<TypeValue>> |
1678 | | As() && { |
1679 | | return std::move(*this).AsType(); |
1680 | | } |
1681 | | template <typename T> |
1682 | | std::enable_if_t<std::is_same_v<TypeValue, T>, absl::optional<TypeValue>> As() |
1683 | | const&& { |
1684 | | return std::move(*this).AsType(); |
1685 | | } |
1686 | | |
1687 | | // Convenience method for use with template metaprogramming. See |
1688 | | // `AsUint()`. |
1689 | | template <typename T> |
1690 | | std::enable_if_t<std::is_same_v<UintValue, T>, absl::optional<UintValue>> |
1691 | | As() & { |
1692 | | return AsUint(); |
1693 | | } |
1694 | | template <typename T> |
1695 | | std::enable_if_t<std::is_same_v<UintValue, T>, absl::optional<UintValue>> As() |
1696 | 0 | const& { |
1697 | 0 | return AsUint(); |
1698 | 0 | } |
1699 | | template <typename T> |
1700 | | std::enable_if_t<std::is_same_v<UintValue, T>, absl::optional<UintValue>> |
1701 | | As() && { |
1702 | | return AsUint(); |
1703 | | } |
1704 | | template <typename T> |
1705 | | std::enable_if_t<std::is_same_v<UintValue, T>, absl::optional<UintValue>> As() |
1706 | | const&& { |
1707 | | return AsUint(); |
1708 | | } |
1709 | | |
1710 | | // Convenience method for use with template metaprogramming. See |
1711 | | // `AsUnknown()`. |
1712 | | template <typename T> |
1713 | | std::enable_if_t<std::is_same_v<UnknownValue, T>, |
1714 | | optional_ref<const UnknownValue>> |
1715 | | As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1716 | | return AsUnknown(); |
1717 | | } |
1718 | | template <typename T> |
1719 | | std::enable_if_t<std::is_same_v<UnknownValue, T>, |
1720 | | optional_ref<const UnknownValue>> |
1721 | | As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1722 | | return AsUnknown(); |
1723 | | } |
1724 | | template <typename T> |
1725 | | std::enable_if_t<std::is_same_v<UnknownValue, T>, |
1726 | | absl::optional<UnknownValue>> |
1727 | | As() && { |
1728 | | return std::move(*this).AsUnknown(); |
1729 | | } |
1730 | | template <typename T> |
1731 | | std::enable_if_t<std::is_same_v<UnknownValue, T>, |
1732 | | absl::optional<UnknownValue>> |
1733 | | As() const&& { |
1734 | | return std::move(*this).AsUnknown(); |
1735 | | } |
1736 | | |
1737 | | // Performs an unchecked cast from a value to a bool value. In |
1738 | | // debug builds a best effort is made to crash. If `IsBool()` would return |
1739 | | // false, calling this method is undefined behavior. |
1740 | 12.7k | BoolValue GetBool() const { |
1741 | 25.5k | ABSL_DCHECK(IsBool()) << *this; |
1742 | 12.7k | return variant_.Get<BoolValue>(); |
1743 | 12.7k | } |
1744 | | |
1745 | | // Performs an unchecked cast from a value to a bytes value. In |
1746 | | // debug builds a best effort is made to crash. If `IsBytes()` would return |
1747 | | // false, calling this method is undefined behavior. |
1748 | 0 | const BytesValue& GetBytes() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1749 | 0 | return std::as_const(*this).GetBytes(); |
1750 | 0 | } |
1751 | | const BytesValue& GetBytes() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1752 | | BytesValue GetBytes() &&; |
1753 | 0 | BytesValue GetBytes() const&& { return GetBytes(); } |
1754 | | |
1755 | | // Performs an unchecked cast from a value to a double value. In |
1756 | | // debug builds a best effort is made to crash. If `IsDouble()` would return |
1757 | | // false, calling this method is undefined behavior. |
1758 | | DoubleValue GetDouble() const; |
1759 | | |
1760 | | // Performs an unchecked cast from a value to a duration value. In |
1761 | | // debug builds a best effort is made to crash. If `IsDuration()` would return |
1762 | | // false, calling this method is undefined behavior. |
1763 | | DurationValue GetDuration() const; |
1764 | | |
1765 | | // Performs an unchecked cast from a value to an error value. In |
1766 | | // debug builds a best effort is made to crash. If `IsError()` would return |
1767 | | // false, calling this method is undefined behavior. |
1768 | 0 | const ErrorValue& GetError() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1769 | 0 | return std::as_const(*this).GetError(); |
1770 | 0 | } |
1771 | | const ErrorValue& GetError() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1772 | | ErrorValue GetError() &&; |
1773 | 0 | ErrorValue GetError() const&& { return GetError(); } |
1774 | | |
1775 | | // Performs an unchecked cast from a value to an int value. In |
1776 | | // debug builds a best effort is made to crash. If `IsInt()` would return |
1777 | | // false, calling this method is undefined behavior. |
1778 | | IntValue GetInt() const; |
1779 | | |
1780 | | // Performs an unchecked cast from a value to a list value. In |
1781 | | // debug builds a best effort is made to crash. If `IsList()` would return |
1782 | | // false, calling this method is undefined behavior. |
1783 | 0 | ListValue GetList() & { return std::as_const(*this).GetList(); } |
1784 | | ListValue GetList() const&; |
1785 | | ListValue GetList() &&; |
1786 | 0 | ListValue GetList() const&& { return GetList(); } |
1787 | | |
1788 | | // Performs an unchecked cast from a value to a map value. In |
1789 | | // debug builds a best effort is made to crash. If `IsMap()` would return |
1790 | | // false, calling this method is undefined behavior. |
1791 | 0 | MapValue GetMap() & { return std::as_const(*this).GetMap(); } |
1792 | | MapValue GetMap() const&; |
1793 | | MapValue GetMap() &&; |
1794 | 0 | MapValue GetMap() const&& { return GetMap(); } |
1795 | | |
1796 | | // Performs an unchecked cast from a value to a message value. In |
1797 | | // debug builds a best effort is made to crash. If `IsMessage()` would return |
1798 | | // false, calling this method is undefined behavior. |
1799 | 0 | MessageValue GetMessage() & { return std::as_const(*this).GetMessage(); } |
1800 | | MessageValue GetMessage() const&; |
1801 | | MessageValue GetMessage() &&; |
1802 | 0 | MessageValue GetMessage() const&& { return GetMessage(); } |
1803 | | |
1804 | | // Performs an unchecked cast from a value to a null value. In |
1805 | | // debug builds a best effort is made to crash. If `IsNull()` would return |
1806 | | // false, calling this method is undefined behavior. |
1807 | | NullValue GetNull() const; |
1808 | | |
1809 | | // Performs an unchecked cast from a value to an opaque value. In |
1810 | | // debug builds a best effort is made to crash. If `IsOpaque()` would return |
1811 | | // false, calling this method is undefined behavior. |
1812 | 0 | const OpaqueValue& GetOpaque() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1813 | 0 | return std::as_const(*this).GetOpaque(); |
1814 | 0 | } |
1815 | | const OpaqueValue& GetOpaque() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1816 | | OpaqueValue GetOpaque() &&; |
1817 | 0 | OpaqueValue GetOpaque() const&& { return GetOpaque(); } |
1818 | | |
1819 | | // Performs an unchecked cast from a value to an optional value. In |
1820 | | // debug builds a best effort is made to crash. If `IsOptional()` would return |
1821 | | // false, calling this method is undefined behavior. |
1822 | 0 | const OptionalValue& GetOptional() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1823 | 0 | return std::as_const(*this).GetOptional(); |
1824 | 0 | } |
1825 | | const OptionalValue& GetOptional() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1826 | | OptionalValue GetOptional() &&; |
1827 | 0 | OptionalValue GetOptional() const&& { return GetOptional(); } |
1828 | | |
1829 | | // Performs an unchecked cast from a value to a parsed message value. In |
1830 | | // debug builds a best effort is made to crash. If `IsParsedJsonList()` would |
1831 | | // return false, calling this method is undefined behavior. |
1832 | | const ParsedJsonListValue& GetParsedJsonList() & |
1833 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1834 | 0 | return std::as_const(*this).GetParsedJsonList(); |
1835 | 0 | } |
1836 | | const ParsedJsonListValue& GetParsedJsonList() |
1837 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1838 | | ParsedJsonListValue GetParsedJsonList() &&; |
1839 | 0 | ParsedJsonListValue GetParsedJsonList() const&& { |
1840 | 0 | return GetParsedJsonList(); |
1841 | 0 | } |
1842 | | |
1843 | | // Performs an unchecked cast from a value to a parsed message value. In |
1844 | | // debug builds a best effort is made to crash. If `IsParsedJsonMap()` would |
1845 | | // return false, calling this method is undefined behavior. |
1846 | 0 | const ParsedJsonMapValue& GetParsedJsonMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1847 | 0 | return std::as_const(*this).GetParsedJsonMap(); |
1848 | 0 | } |
1849 | | const ParsedJsonMapValue& GetParsedJsonMap() |
1850 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1851 | | ParsedJsonMapValue GetParsedJsonMap() &&; |
1852 | 0 | ParsedJsonMapValue GetParsedJsonMap() const&& { return GetParsedJsonMap(); } |
1853 | | |
1854 | | // Performs an unchecked cast from a value to a custom list value. In |
1855 | | // debug builds a best effort is made to crash. If `IsCustomList()` would |
1856 | | // return false, calling this method is undefined behavior. |
1857 | 0 | const CustomListValue& GetCustomList() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1858 | 0 | return std::as_const(*this).GetCustomList(); |
1859 | 0 | } |
1860 | | const CustomListValue& GetCustomList() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1861 | | CustomListValue GetCustomList() &&; |
1862 | 0 | CustomListValue GetCustomList() const&& { return GetCustomList(); } |
1863 | | |
1864 | | // Performs an unchecked cast from a value to a custom map value. In |
1865 | | // debug builds a best effort is made to crash. If `IsCustomMap()` would |
1866 | | // return false, calling this method is undefined behavior. |
1867 | 0 | const CustomMapValue& GetCustomMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1868 | 0 | return std::as_const(*this).GetCustomMap(); |
1869 | 0 | } |
1870 | | const CustomMapValue& GetCustomMap() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1871 | | CustomMapValue GetCustomMap() &&; |
1872 | 0 | CustomMapValue GetCustomMap() const&& { return GetCustomMap(); } |
1873 | | |
1874 | | // Performs an unchecked cast from a value to a parsed map field value. In |
1875 | | // debug builds a best effort is made to crash. If `IsParsedMapField()` would |
1876 | | // return false, calling this method is undefined behavior. |
1877 | | const ParsedMapFieldValue& GetParsedMapField() & |
1878 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1879 | 0 | return std::as_const(*this).GetParsedMapField(); |
1880 | 0 | } |
1881 | | const ParsedMapFieldValue& GetParsedMapField() |
1882 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1883 | | ParsedMapFieldValue GetParsedMapField() &&; |
1884 | 0 | ParsedMapFieldValue GetParsedMapField() const&& { |
1885 | 0 | return GetParsedMapField(); |
1886 | 0 | } |
1887 | | |
1888 | | // Performs an unchecked cast from a value to a parsed message value. In |
1889 | | // debug builds a best effort is made to crash. If `IsParsedMessage()` would |
1890 | | // return false, calling this method is undefined behavior. |
1891 | 0 | const ParsedMessageValue& GetParsedMessage() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1892 | 0 | return std::as_const(*this).GetParsedMessage(); |
1893 | 0 | } |
1894 | | const ParsedMessageValue& GetParsedMessage() |
1895 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1896 | | ParsedMessageValue GetParsedMessage() &&; |
1897 | 0 | ParsedMessageValue GetParsedMessage() const&& { return GetParsedMessage(); } |
1898 | | |
1899 | | // Performs an unchecked cast from a value to a parsed repeated field value. |
1900 | | // In debug builds a best effort is made to crash. If |
1901 | | // `IsParsedRepeatedField()` would return false, calling this method is |
1902 | | // undefined behavior. |
1903 | | const ParsedRepeatedFieldValue& GetParsedRepeatedField() & |
1904 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1905 | 0 | return std::as_const(*this).GetParsedRepeatedField(); |
1906 | 0 | } |
1907 | | const ParsedRepeatedFieldValue& GetParsedRepeatedField() |
1908 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1909 | | ParsedRepeatedFieldValue GetParsedRepeatedField() &&; |
1910 | 0 | ParsedRepeatedFieldValue GetParsedRepeatedField() const&& { |
1911 | 0 | return GetParsedRepeatedField(); |
1912 | 0 | } |
1913 | | |
1914 | | // Performs an unchecked cast from a value to a custom struct value. In |
1915 | | // debug builds a best effort is made to crash. If `IsCustomStruct()` would |
1916 | | // return false, calling this method is undefined behavior. |
1917 | 0 | const CustomStructValue& GetCustomStruct() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1918 | 0 | return std::as_const(*this).GetCustomStruct(); |
1919 | 0 | } |
1920 | | const CustomStructValue& GetCustomStruct() |
1921 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1922 | | CustomStructValue GetCustomStruct() &&; |
1923 | 0 | CustomStructValue GetCustomStruct() const&& { return GetCustomStruct(); } |
1924 | | |
1925 | | // Performs an unchecked cast from a value to a string value. In |
1926 | | // debug builds a best effort is made to crash. If `IsString()` would return |
1927 | | // false, calling this method is undefined behavior. |
1928 | 0 | const StringValue& GetString() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1929 | 0 | return std::as_const(*this).GetString(); |
1930 | 0 | } |
1931 | | const StringValue& GetString() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1932 | | StringValue GetString() &&; |
1933 | 0 | StringValue GetString() const&& { return GetString(); } |
1934 | | |
1935 | | // Performs an unchecked cast from a value to a struct value. In |
1936 | | // debug builds a best effort is made to crash. If `IsStruct()` would return |
1937 | | // false, calling this method is undefined behavior. |
1938 | 0 | StructValue GetStruct() & { return std::as_const(*this).GetStruct(); } |
1939 | | StructValue GetStruct() const&; |
1940 | | StructValue GetStruct() &&; |
1941 | 0 | StructValue GetStruct() const&& { return GetStruct(); } |
1942 | | |
1943 | | // Performs an unchecked cast from a value to a timestamp value. In |
1944 | | // debug builds a best effort is made to crash. If `IsTimestamp()` would |
1945 | | // return false, calling this method is undefined behavior. |
1946 | | TimestampValue GetTimestamp() const; |
1947 | | |
1948 | | // Performs an unchecked cast from a value to a type value. In |
1949 | | // debug builds a best effort is made to crash. If `IsType()` would return |
1950 | | // false, calling this method is undefined behavior. |
1951 | 0 | const TypeValue& GetType() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1952 | 0 | return std::as_const(*this).GetType(); |
1953 | 0 | } |
1954 | | const TypeValue& GetType() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1955 | | TypeValue GetType() &&; |
1956 | 0 | TypeValue GetType() const&& { return GetType(); } |
1957 | | |
1958 | | // Performs an unchecked cast from a value to an uint value. In |
1959 | | // debug builds a best effort is made to crash. If `IsUint()` would return |
1960 | | // false, calling this method is undefined behavior. |
1961 | | UintValue GetUint() const; |
1962 | | |
1963 | | // Performs an unchecked cast from a value to an unknown value. In |
1964 | | // debug builds a best effort is made to crash. If `IsUnknown()` would return |
1965 | | // false, calling this method is undefined behavior. |
1966 | 0 | const UnknownValue& GetUnknown() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1967 | 0 | return std::as_const(*this).GetUnknown(); |
1968 | 0 | } |
1969 | | const UnknownValue& GetUnknown() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; |
1970 | | UnknownValue GetUnknown() &&; |
1971 | 0 | UnknownValue GetUnknown() const&& { return GetUnknown(); } |
1972 | | |
1973 | | // Convenience method for use with template metaprogramming. See |
1974 | | // `GetBool()`. |
1975 | | template <typename T> |
1976 | 0 | std::enable_if_t<std::is_same_v<BoolValue, T>, BoolValue> Get() & { |
1977 | 0 | return GetBool(); |
1978 | 0 | } |
1979 | | template <typename T> |
1980 | 3.36k | std::enable_if_t<std::is_same_v<BoolValue, T>, BoolValue> Get() const& { |
1981 | 3.36k | return GetBool(); |
1982 | 3.36k | } |
1983 | | template <typename T> |
1984 | | std::enable_if_t<std::is_same_v<BoolValue, T>, BoolValue> Get() && { |
1985 | | return GetBool(); |
1986 | | } |
1987 | | template <typename T> |
1988 | | std::enable_if_t<std::is_same_v<BoolValue, T>, BoolValue> Get() const&& { |
1989 | | return GetBool(); |
1990 | | } |
1991 | | |
1992 | | // Convenience method for use with template metaprogramming. See |
1993 | | // `GetBytes()`. |
1994 | | template <typename T> |
1995 | | std::enable_if_t<std::is_same_v<BytesValue, T>, const BytesValue&> Get() & |
1996 | | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
1997 | | return GetBytes(); |
1998 | | } |
1999 | | template <typename T> |
2000 | | std::enable_if_t<std::is_same_v<BytesValue, T>, const BytesValue&> Get() |
2001 | 1.92k | const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2002 | 1.92k | return GetBytes(); |
2003 | 1.92k | } |
2004 | | template <typename T> |
2005 | | std::enable_if_t<std::is_same_v<BytesValue, T>, BytesValue> Get() && { |
2006 | | return std::move(*this).GetBytes(); |
2007 | | } |
2008 | | template <typename T> |
2009 | | std::enable_if_t<std::is_same_v<BytesValue, T>, BytesValue> Get() const&& { |
2010 | | return std::move(*this).GetBytes(); |
2011 | | } |
2012 | | |
2013 | | // Convenience method for use with template metaprogramming. See |
2014 | | // `GetDouble()`. |
2015 | | template <typename T> |
2016 | | std::enable_if_t<std::is_same_v<DoubleValue, T>, DoubleValue> Get() & { |
2017 | | return GetDouble(); |
2018 | | } |
2019 | | template <typename T> |
2020 | 329 | std::enable_if_t<std::is_same_v<DoubleValue, T>, DoubleValue> Get() const& { |
2021 | 329 | return GetDouble(); |
2022 | 329 | } |
2023 | | template <typename T> |
2024 | | std::enable_if_t<std::is_same_v<DoubleValue, T>, DoubleValue> Get() && { |
2025 | | return GetDouble(); |
2026 | | } |
2027 | | template <typename T> |
2028 | | std::enable_if_t<std::is_same_v<DoubleValue, T>, DoubleValue> Get() const&& { |
2029 | | return GetDouble(); |
2030 | | } |
2031 | | |
2032 | | // Convenience method for use with template metaprogramming. See |
2033 | | // `GetDuration()`. |
2034 | | template <typename T> |
2035 | | std::enable_if_t<std::is_same_v<DurationValue, T>, DurationValue> Get() & { |
2036 | | return GetDuration(); |
2037 | | } |
2038 | | template <typename T> |
2039 | | std::enable_if_t<std::is_same_v<DurationValue, T>, DurationValue> Get() |
2040 | 1 | const& { |
2041 | 1 | return GetDuration(); |
2042 | 1 | } |
2043 | | template <typename T> |
2044 | | std::enable_if_t<std::is_same_v<DurationValue, T>, DurationValue> Get() && { |
2045 | | return GetDuration(); |
2046 | | } |
2047 | | template <typename T> |
2048 | | std::enable_if_t<std::is_same_v<DurationValue, T>, DurationValue> Get() |
2049 | | const&& { |
2050 | | return GetDuration(); |
2051 | | } |
2052 | | |
2053 | | // Convenience method for use with template metaprogramming. See |
2054 | | // `GetError()`. |
2055 | | template <typename T> |
2056 | | std::enable_if_t<std::is_same_v<ErrorValue, T>, const ErrorValue&> Get() & |
2057 | | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2058 | | return GetError(); |
2059 | | } |
2060 | | template <typename T> |
2061 | | std::enable_if_t<std::is_same_v<ErrorValue, T>, const ErrorValue&> Get() |
2062 | 5.05k | const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2063 | 5.05k | return GetError(); |
2064 | 5.05k | } |
2065 | | template <typename T> |
2066 | | std::enable_if_t<std::is_same_v<ErrorValue, T>, ErrorValue> Get() && { |
2067 | | return std::move(*this).GetError(); |
2068 | | } |
2069 | | template <typename T> |
2070 | | std::enable_if_t<std::is_same_v<ErrorValue, T>, ErrorValue> Get() const&& { |
2071 | | return std::move(*this).GetError(); |
2072 | | } |
2073 | | |
2074 | | // Convenience method for use with template metaprogramming. See |
2075 | | // `GetInt()`. |
2076 | | template <typename T> |
2077 | | std::enable_if_t<std::is_same_v<IntValue, T>, IntValue> Get() & { |
2078 | | return GetInt(); |
2079 | | } |
2080 | | template <typename T> |
2081 | 567 | std::enable_if_t<std::is_same_v<IntValue, T>, IntValue> Get() const& { |
2082 | 567 | return GetInt(); |
2083 | 567 | } |
2084 | | template <typename T> |
2085 | | std::enable_if_t<std::is_same_v<IntValue, T>, IntValue> Get() && { |
2086 | | return GetInt(); |
2087 | | } |
2088 | | template <typename T> |
2089 | | std::enable_if_t<std::is_same_v<IntValue, T>, IntValue> Get() const&& { |
2090 | | return GetInt(); |
2091 | | } |
2092 | | |
2093 | | // Convenience method for use with template metaprogramming. See |
2094 | | // `GetList()`. |
2095 | | template <typename T> |
2096 | | std::enable_if_t<std::is_same_v<ListValue, T>, ListValue> Get() & { |
2097 | | return GetList(); |
2098 | | } |
2099 | | template <typename T> |
2100 | 7.65k | std::enable_if_t<std::is_same_v<ListValue, T>, ListValue> Get() const& { |
2101 | 7.65k | return GetList(); |
2102 | 7.65k | } |
2103 | | template <typename T> |
2104 | | std::enable_if_t<std::is_same_v<ListValue, T>, ListValue> Get() && { |
2105 | | return std::move(*this).GetList(); |
2106 | | } |
2107 | | template <typename T> |
2108 | | std::enable_if_t<std::is_same_v<ListValue, T>, ListValue> Get() const&& { |
2109 | | return std::move(*this).GetList(); |
2110 | | } |
2111 | | |
2112 | | // Convenience method for use with template metaprogramming. See |
2113 | | // `GetMap()`. |
2114 | | template <typename T> |
2115 | | std::enable_if_t<std::is_same_v<MapValue, T>, MapValue> Get() & { |
2116 | | return GetMap(); |
2117 | | } |
2118 | | template <typename T> |
2119 | 3.85k | std::enable_if_t<std::is_same_v<MapValue, T>, MapValue> Get() const& { |
2120 | 3.85k | return GetMap(); |
2121 | 3.85k | } |
2122 | | template <typename T> |
2123 | | std::enable_if_t<std::is_same_v<MapValue, T>, MapValue> Get() && { |
2124 | | return std::move(*this).GetMap(); |
2125 | | } |
2126 | | template <typename T> |
2127 | | std::enable_if_t<std::is_same_v<MapValue, T>, MapValue> Get() const&& { |
2128 | | return std::move(*this).GetMap(); |
2129 | | } |
2130 | | |
2131 | | // Convenience method for use with template metaprogramming. See |
2132 | | // `GetMessage()`. |
2133 | | template <typename T> |
2134 | | std::enable_if_t<std::is_same_v<MessageValue, T>, MessageValue> Get() & { |
2135 | | return GetMessage(); |
2136 | | } |
2137 | | template <typename T> |
2138 | | std::enable_if_t<std::is_same_v<MessageValue, T>, MessageValue> Get() const& { |
2139 | | return GetMessage(); |
2140 | | } |
2141 | | template <typename T> |
2142 | | std::enable_if_t<std::is_same_v<MessageValue, T>, MessageValue> Get() && { |
2143 | | return std::move(*this).GetMessage(); |
2144 | | } |
2145 | | template <typename T> |
2146 | | std::enable_if_t<std::is_same_v<MessageValue, T>, MessageValue> Get() |
2147 | | const&& { |
2148 | | return std::move(*this).GetMessage(); |
2149 | | } |
2150 | | |
2151 | | // Convenience method for use with template metaprogramming. See |
2152 | | // `GetNull()`. |
2153 | | template <typename T> |
2154 | | std::enable_if_t<std::is_same_v<NullValue, T>, NullValue> Get() & { |
2155 | | return GetNull(); |
2156 | | } |
2157 | | template <typename T> |
2158 | 0 | std::enable_if_t<std::is_same_v<NullValue, T>, NullValue> Get() const& { |
2159 | 0 | return GetNull(); |
2160 | 0 | } |
2161 | | template <typename T> |
2162 | | std::enable_if_t<std::is_same_v<NullValue, T>, NullValue> Get() && { |
2163 | | return GetNull(); |
2164 | | } |
2165 | | template <typename T> |
2166 | | std::enable_if_t<std::is_same_v<NullValue, T>, NullValue> Get() const&& { |
2167 | | return GetNull(); |
2168 | | } |
2169 | | |
2170 | | // Convenience method for use with template metaprogramming. See |
2171 | | // `GetOpaque()`. |
2172 | | template <typename T> |
2173 | | std::enable_if_t<std::is_same_v<OpaqueValue, T>, const OpaqueValue&> |
2174 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2175 | | return GetOpaque(); |
2176 | | } |
2177 | | template <typename T> |
2178 | | std::enable_if_t<std::is_same_v<OpaqueValue, T>, const OpaqueValue&> Get() |
2179 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2180 | | return GetOpaque(); |
2181 | | } |
2182 | | template <typename T> |
2183 | | std::enable_if_t<std::is_same_v<OpaqueValue, T>, OpaqueValue> Get() && { |
2184 | | return std::move(*this).GetOpaque(); |
2185 | | } |
2186 | | template <typename T> |
2187 | | std::enable_if_t<std::is_same_v<OpaqueValue, T>, OpaqueValue> Get() const&& { |
2188 | | return std::move(*this).GetOpaque(); |
2189 | | } |
2190 | | |
2191 | | // Convenience method for use with template metaprogramming. See |
2192 | | // `GetOptional()`. |
2193 | | template <typename T> |
2194 | | std::enable_if_t<std::is_same_v<OptionalValue, T>, const OptionalValue&> |
2195 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2196 | | return GetOptional(); |
2197 | | } |
2198 | | template <typename T> |
2199 | | std::enable_if_t<std::is_same_v<OptionalValue, T>, const OptionalValue&> Get() |
2200 | | const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2201 | | return GetOptional(); |
2202 | | } |
2203 | | template <typename T> |
2204 | | std::enable_if_t<std::is_same_v<OptionalValue, T>, OptionalValue> Get() && { |
2205 | | return std::move(*this).GetOptional(); |
2206 | | } |
2207 | | template <typename T> |
2208 | | std::enable_if_t<std::is_same_v<OptionalValue, T>, OptionalValue> Get() |
2209 | | const&& { |
2210 | | return std::move(*this).GetOptional(); |
2211 | | } |
2212 | | |
2213 | | // Convenience method for use with template metaprogramming. See |
2214 | | // `GetParsedJsonList()`. |
2215 | | template <typename T> |
2216 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, |
2217 | | const ParsedJsonListValue&> |
2218 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2219 | | return GetParsedJsonList(); |
2220 | | } |
2221 | | template <typename T> |
2222 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, |
2223 | | const ParsedJsonListValue&> |
2224 | | Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2225 | | return GetParsedJsonList(); |
2226 | | } |
2227 | | template <typename T> |
2228 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, ParsedJsonListValue> |
2229 | | Get() && { |
2230 | | return std::move(*this).GetParsedJsonList(); |
2231 | | } |
2232 | | template <typename T> |
2233 | | std::enable_if_t<std::is_same_v<ParsedJsonListValue, T>, ParsedJsonListValue> |
2234 | | Get() const&& { |
2235 | | return std::move(*this).GetParsedJsonList(); |
2236 | | } |
2237 | | |
2238 | | // Convenience method for use with template metaprogramming. See |
2239 | | // `GetParsedJsonMap()`. |
2240 | | template <typename T> |
2241 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, |
2242 | | const ParsedJsonMapValue&> |
2243 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2244 | | return GetParsedJsonMap(); |
2245 | | } |
2246 | | template <typename T> |
2247 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, |
2248 | | const ParsedJsonMapValue&> |
2249 | | Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2250 | | return GetParsedJsonMap(); |
2251 | | } |
2252 | | template <typename T> |
2253 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, ParsedJsonMapValue> |
2254 | | Get() && { |
2255 | | return std::move(*this).GetParsedJsonMap(); |
2256 | | } |
2257 | | template <typename T> |
2258 | | std::enable_if_t<std::is_same_v<ParsedJsonMapValue, T>, ParsedJsonMapValue> |
2259 | | Get() const&& { |
2260 | | return std::move(*this).GetParsedJsonMap(); |
2261 | | } |
2262 | | |
2263 | | // Convenience method for use with template metaprogramming. See |
2264 | | // `GetCustomList()`. |
2265 | | template <typename T> |
2266 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, |
2267 | | const CustomListValue&> |
2268 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2269 | | return GetCustomList(); |
2270 | | } |
2271 | | template <typename T> |
2272 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, const CustomListValue&> |
2273 | | Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2274 | | return GetCustomList(); |
2275 | | } |
2276 | | template <typename T> |
2277 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, CustomListValue> |
2278 | | Get() && { |
2279 | | return std::move(*this).GetCustomList(); |
2280 | | } |
2281 | | template <typename T> |
2282 | | std::enable_if_t<std::is_same_v<CustomListValue, T>, CustomListValue> Get() |
2283 | | const&& { |
2284 | | return std::move(*this).GetCustomList(); |
2285 | | } |
2286 | | |
2287 | | // Convenience method for use with template metaprogramming. See |
2288 | | // `GetCustomMap()`. |
2289 | | template <typename T> |
2290 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, const CustomMapValue&> |
2291 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2292 | | return GetCustomMap(); |
2293 | | } |
2294 | | template <typename T> |
2295 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, const CustomMapValue&> |
2296 | | Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2297 | | return GetCustomMap(); |
2298 | | } |
2299 | | template <typename T> |
2300 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, CustomMapValue> Get() && { |
2301 | | return std::move(*this).GetCustomMap(); |
2302 | | } |
2303 | | template <typename T> |
2304 | | std::enable_if_t<std::is_same_v<CustomMapValue, T>, CustomMapValue> Get() |
2305 | | const&& { |
2306 | | return std::move(*this).GetCustomMap(); |
2307 | | } |
2308 | | |
2309 | | // Convenience method for use with template metaprogramming. See |
2310 | | // `GetParsedMapField()`. |
2311 | | template <typename T> |
2312 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, |
2313 | | const ParsedMapFieldValue&> |
2314 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2315 | | return GetParsedMapField(); |
2316 | | } |
2317 | | template <typename T> |
2318 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, |
2319 | | const ParsedMapFieldValue&> |
2320 | | Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2321 | | return GetParsedMapField(); |
2322 | | } |
2323 | | template <typename T> |
2324 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, ParsedMapFieldValue> |
2325 | | Get() && { |
2326 | | return std::move(*this).GetParsedMapField(); |
2327 | | } |
2328 | | template <typename T> |
2329 | | std::enable_if_t<std::is_same_v<ParsedMapFieldValue, T>, ParsedMapFieldValue> |
2330 | | Get() const&& { |
2331 | | return std::move(*this).GetParsedMapField(); |
2332 | | } |
2333 | | |
2334 | | // Convenience method for use with template metaprogramming. See |
2335 | | // `GetParsedMessage()`. |
2336 | | template <typename T> |
2337 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, |
2338 | | const ParsedMessageValue&> |
2339 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2340 | | return GetParsedMessage(); |
2341 | | } |
2342 | | template <typename T> |
2343 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, |
2344 | | const ParsedMessageValue&> |
2345 | | Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2346 | | return GetParsedMessage(); |
2347 | | } |
2348 | | template <typename T> |
2349 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, ParsedMessageValue> |
2350 | | Get() && { |
2351 | | return std::move(*this).GetParsedMessage(); |
2352 | | } |
2353 | | template <typename T> |
2354 | | std::enable_if_t<std::is_same_v<ParsedMessageValue, T>, ParsedMessageValue> |
2355 | | Get() const&& { |
2356 | | return std::move(*this).GetParsedMessage(); |
2357 | | } |
2358 | | |
2359 | | // Convenience method for use with template metaprogramming. See |
2360 | | // `GetParsedRepeatedField()`. |
2361 | | template <typename T> |
2362 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, |
2363 | | const ParsedRepeatedFieldValue&> |
2364 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2365 | | return GetParsedRepeatedField(); |
2366 | | } |
2367 | | template <typename T> |
2368 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, |
2369 | | const ParsedRepeatedFieldValue&> |
2370 | | Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2371 | | return GetParsedRepeatedField(); |
2372 | | } |
2373 | | template <typename T> |
2374 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, |
2375 | | ParsedRepeatedFieldValue> |
2376 | | Get() && { |
2377 | | return std::move(*this).GetParsedRepeatedField(); |
2378 | | } |
2379 | | template <typename T> |
2380 | | std::enable_if_t<std::is_same_v<ParsedRepeatedFieldValue, T>, |
2381 | | ParsedRepeatedFieldValue> |
2382 | | Get() const&& { |
2383 | | return std::move(*this).GetParsedRepeatedField(); |
2384 | | } |
2385 | | |
2386 | | // Convenience method for use with template metaprogramming. See |
2387 | | // `GetCustomStruct()`. |
2388 | | template <typename T> |
2389 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, |
2390 | | const CustomStructValue&> |
2391 | | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2392 | | return GetCustomStruct(); |
2393 | | } |
2394 | | template <typename T> |
2395 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, |
2396 | | const CustomStructValue&> |
2397 | | Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2398 | | return GetCustomStruct(); |
2399 | | } |
2400 | | template <typename T> |
2401 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, CustomStructValue> |
2402 | | Get() && { |
2403 | | return std::move(*this).GetCustomStruct(); |
2404 | | } |
2405 | | template <typename T> |
2406 | | std::enable_if_t<std::is_same_v<CustomStructValue, T>, CustomStructValue> |
2407 | | Get() const&& { |
2408 | | return std::move(*this).GetCustomStruct(); |
2409 | | } |
2410 | | |
2411 | | // Convenience method for use with template metaprogramming. See |
2412 | | // `GetString()`. |
2413 | | template <typename T> |
2414 | | std::enable_if_t<std::is_same_v<StringValue, T>, const StringValue&> |
2415 | 0 | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2416 | 0 | return GetString(); |
2417 | 0 | } |
2418 | | template <typename T> |
2419 | | std::enable_if_t<std::is_same_v<StringValue, T>, const StringValue&> Get() |
2420 | 9.25k | const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2421 | 9.25k | return GetString(); |
2422 | 9.25k | } |
2423 | | template <typename T> |
2424 | | std::enable_if_t<std::is_same_v<StringValue, T>, StringValue> Get() && { |
2425 | | return std::move(*this).GetString(); |
2426 | | } |
2427 | | template <typename T> |
2428 | | std::enable_if_t<std::is_same_v<StringValue, T>, StringValue> Get() const&& { |
2429 | | return std::move(*this).GetString(); |
2430 | | } |
2431 | | |
2432 | | // Convenience method for use with template metaprogramming. See |
2433 | | // `GetStruct()`. |
2434 | | template <typename T> |
2435 | 0 | std::enable_if_t<std::is_same_v<StructValue, T>, StructValue> Get() & { |
2436 | 0 | return GetStruct(); |
2437 | 0 | } |
2438 | | template <typename T> |
2439 | 0 | std::enable_if_t<std::is_same_v<StructValue, T>, StructValue> Get() const& { |
2440 | 0 | return GetStruct(); |
2441 | 0 | } |
2442 | | template <typename T> |
2443 | | std::enable_if_t<std::is_same_v<StructValue, T>, StructValue> Get() && { |
2444 | | return std::move(*this).GetStruct(); |
2445 | | } |
2446 | | template <typename T> |
2447 | | std::enable_if_t<std::is_same_v<StructValue, T>, StructValue> Get() const&& { |
2448 | | return std::move(*this).GetStruct(); |
2449 | | } |
2450 | | |
2451 | | // Convenience method for use with template metaprogramming. See |
2452 | | // `GetTimestamp()`. |
2453 | | template <typename T> |
2454 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, TimestampValue> Get() & { |
2455 | | return GetTimestamp(); |
2456 | | } |
2457 | | template <typename T> |
2458 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, TimestampValue> Get() |
2459 | 1 | const& { |
2460 | 1 | return GetTimestamp(); |
2461 | 1 | } |
2462 | | template <typename T> |
2463 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, TimestampValue> Get() && { |
2464 | | return GetTimestamp(); |
2465 | | } |
2466 | | template <typename T> |
2467 | | std::enable_if_t<std::is_same_v<TimestampValue, T>, TimestampValue> Get() |
2468 | | const&& { |
2469 | | return GetTimestamp(); |
2470 | | } |
2471 | | |
2472 | | // Convenience method for use with template metaprogramming. See |
2473 | | // `GetType()`. |
2474 | | template <typename T> |
2475 | | std::enable_if_t<std::is_same_v<TypeValue, T>, const TypeValue&> Get() & |
2476 | | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2477 | | return GetType(); |
2478 | | } |
2479 | | template <typename T> |
2480 | | std::enable_if_t<std::is_same_v<TypeValue, T>, const TypeValue&> Get() |
2481 | 12 | const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2482 | 12 | return GetType(); |
2483 | 12 | } |
2484 | | template <typename T> |
2485 | | std::enable_if_t<std::is_same_v<TypeValue, T>, TypeValue> Get() && { |
2486 | | return std::move(*this).GetType(); |
2487 | | } |
2488 | | template <typename T> |
2489 | | std::enable_if_t<std::is_same_v<TypeValue, T>, TypeValue> Get() const&& { |
2490 | | return std::move(*this).GetType(); |
2491 | | } |
2492 | | |
2493 | | // Convenience method for use with template metaprogramming. See |
2494 | | // `GetUint()`. |
2495 | | template <typename T> |
2496 | | std::enable_if_t<std::is_same_v<UintValue, T>, UintValue> Get() & { |
2497 | | return GetUint(); |
2498 | | } |
2499 | | template <typename T> |
2500 | 247 | std::enable_if_t<std::is_same_v<UintValue, T>, UintValue> Get() const& { |
2501 | 247 | return GetUint(); |
2502 | 247 | } |
2503 | | template <typename T> |
2504 | | std::enable_if_t<std::is_same_v<UintValue, T>, UintValue> Get() && { |
2505 | | return GetUint(); |
2506 | | } |
2507 | | template <typename T> |
2508 | | std::enable_if_t<std::is_same_v<UintValue, T>, UintValue> Get() const&& { |
2509 | | return GetUint(); |
2510 | | } |
2511 | | |
2512 | | // Convenience method for use with template metaprogramming. See |
2513 | | // `GetUnknown()`. |
2514 | | template <typename T> |
2515 | | std::enable_if_t<std::is_same_v<UnknownValue, T>, const UnknownValue&> |
2516 | 0 | Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2517 | 0 | return GetUnknown(); |
2518 | 0 | } |
2519 | | template <typename T> |
2520 | | std::enable_if_t<std::is_same_v<UnknownValue, T>, const UnknownValue&> Get() |
2521 | 0 | const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
2522 | 0 | return GetUnknown(); |
2523 | 0 | } |
2524 | | template <typename T> |
2525 | | std::enable_if_t<std::is_same_v<UnknownValue, T>, UnknownValue> Get() && { |
2526 | | return std::move(*this).GetUnknown(); |
2527 | | } |
2528 | | template <typename T> |
2529 | | std::enable_if_t<std::is_same_v<UnknownValue, T>, UnknownValue> Get() |
2530 | | const&& { |
2531 | | return std::move(*this).GetUnknown(); |
2532 | | } |
2533 | | |
2534 | | // When `Value` is default constructed, it is in a valid but undefined state. |
2535 | | // Any attempt to use it invokes undefined behavior. This mention can be used |
2536 | | // to test whether this value is valid. |
2537 | 0 | explicit operator bool() const { return true; } |
2538 | | |
2539 | | private: |
2540 | | friend struct NativeTypeTraits<Value>; |
2541 | | friend bool common_internal::IsLegacyListValue(const Value& value); |
2542 | | friend common_internal::LegacyListValue common_internal::GetLegacyListValue( |
2543 | | const Value& value); |
2544 | | friend bool common_internal::IsLegacyMapValue(const Value& value); |
2545 | | friend common_internal::LegacyMapValue common_internal::GetLegacyMapValue( |
2546 | | const Value& value); |
2547 | | friend bool common_internal::IsLegacyStructValue(const Value& value); |
2548 | | friend common_internal::LegacyStructValue |
2549 | | common_internal::GetLegacyStructValue(const Value& value); |
2550 | | friend class common_internal::ValueMixin<Value>; |
2551 | | friend struct ArenaTraits<Value>; |
2552 | | |
2553 | | common_internal::ValueVariant variant_; |
2554 | | }; |
2555 | | |
2556 | | // Overloads for heterogeneous equality of numeric values. |
2557 | | bool operator==(IntValue lhs, UintValue rhs); |
2558 | | bool operator==(UintValue lhs, IntValue rhs); |
2559 | | bool operator==(IntValue lhs, DoubleValue rhs); |
2560 | | bool operator==(DoubleValue lhs, IntValue rhs); |
2561 | | bool operator==(UintValue lhs, DoubleValue rhs); |
2562 | | bool operator==(DoubleValue lhs, UintValue rhs); |
2563 | 0 | inline bool operator!=(IntValue lhs, UintValue rhs) { |
2564 | 0 | return !operator==(lhs, rhs); |
2565 | 0 | } |
2566 | 0 | inline bool operator!=(UintValue lhs, IntValue rhs) { |
2567 | 0 | return !operator==(lhs, rhs); |
2568 | 0 | } |
2569 | 0 | inline bool operator!=(IntValue lhs, DoubleValue rhs) { |
2570 | 0 | return !operator==(lhs, rhs); |
2571 | 0 | } |
2572 | 0 | inline bool operator!=(DoubleValue lhs, IntValue rhs) { |
2573 | 0 | return !operator==(lhs, rhs); |
2574 | 0 | } |
2575 | 0 | inline bool operator!=(UintValue lhs, DoubleValue rhs) { |
2576 | 0 | return !operator==(lhs, rhs); |
2577 | 0 | } |
2578 | 0 | inline bool operator!=(DoubleValue lhs, UintValue rhs) { |
2579 | 0 | return !operator==(lhs, rhs); |
2580 | 0 | } |
2581 | | |
2582 | | template <> |
2583 | | struct NativeTypeTraits<Value> final { |
2584 | 0 | static NativeTypeId Id(const Value& value) { |
2585 | 0 | return value.variant_.Visit([](const auto& alternative) -> NativeTypeId { |
2586 | 0 | return NativeTypeId::Of(alternative); |
2587 | 0 | }); Unexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::NullValue>(cel::NullValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::BoolValue>(cel::BoolValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::IntValue>(cel::IntValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::UintValue>(cel::UintValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::DoubleValue>(cel::DoubleValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::DurationValue>(cel::DurationValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::TimestampValue>(cel::TimestampValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::TypeValue>(cel::TypeValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::common_internal::LegacyListValue>(cel::common_internal::LegacyListValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedJsonListValue>(cel::ParsedJsonListValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedRepeatedFieldValue>(cel::ParsedRepeatedFieldValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::CustomListValue>(cel::CustomListValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::common_internal::LegacyMapValue>(cel::common_internal::LegacyMapValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedJsonMapValue>(cel::ParsedJsonMapValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedMapFieldValue>(cel::ParsedMapFieldValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::CustomMapValue>(cel::CustomMapValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::common_internal::LegacyStructValue>(cel::common_internal::LegacyStructValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedMessageValue>(cel::ParsedMessageValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::CustomStructValue>(cel::CustomStructValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::OpaqueValue>(cel::OpaqueValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::BytesValue>(cel::BytesValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::StringValue>(cel::StringValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ErrorValue>(cel::ErrorValue const&) constUnexecuted instantiation: cel::TypeInfo cel::NativeTypeTraits<cel::Value, void>::Id(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::UnknownValue>(cel::UnknownValue const&) const |
2588 | 0 | } |
2589 | | }; |
2590 | | |
2591 | | template <> |
2592 | | struct ArenaTraits<Value> { |
2593 | 104k | static bool trivially_destructible(const Value& value) { |
2594 | 104k | return value.variant_.Visit([](const auto& alternative) -> bool { |
2595 | 104k | return ArenaTraits<>::trivially_destructible(alternative); |
2596 | 104k | }); bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::NullValue>(cel::NullValue const&) constLine | Count | Source | 2594 | 105 | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 105 | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 105 | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::BoolValue>(cel::BoolValue const&) constLine | Count | Source | 2594 | 3.80k | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 3.80k | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 3.80k | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::IntValue>(cel::IntValue const&) constLine | Count | Source | 2594 | 82.7k | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 82.7k | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 82.7k | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::UintValue>(cel::UintValue const&) constLine | Count | Source | 2594 | 2.83k | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 2.83k | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 2.83k | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::DoubleValue>(cel::DoubleValue const&) constLine | Count | Source | 2594 | 6.47k | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 6.47k | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 6.47k | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::DurationValue>(cel::DurationValue const&) constLine | Count | Source | 2594 | 1 | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 1 | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 1 | }); |
Unexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::TimestampValue>(cel::TimestampValue const&) constbool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::TypeValue>(cel::TypeValue const&) constLine | Count | Source | 2594 | 1.91k | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 1.91k | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 1.91k | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::common_internal::LegacyListValue>(cel::common_internal::LegacyListValue const&) constLine | Count | Source | 2594 | 154 | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 154 | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 154 | }); |
Unexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedJsonListValue>(cel::ParsedJsonListValue const&) constUnexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedRepeatedFieldValue>(cel::ParsedRepeatedFieldValue const&) constbool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::CustomListValue>(cel::CustomListValue const&) constLine | Count | Source | 2594 | 2.14k | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 2.14k | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 2.14k | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::common_internal::LegacyMapValue>(cel::common_internal::LegacyMapValue const&) constLine | Count | Source | 2594 | 1 | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 1 | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 1 | }); |
Unexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedJsonMapValue>(cel::ParsedJsonMapValue const&) constUnexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedMapFieldValue>(cel::ParsedMapFieldValue const&) constbool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::CustomMapValue>(cel::CustomMapValue const&) constLine | Count | Source | 2594 | 527 | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 527 | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 527 | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::common_internal::LegacyStructValue>(cel::common_internal::LegacyStructValue const&) constLine | Count | Source | 2594 | 1 | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 1 | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 1 | }); |
Unexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ParsedMessageValue>(cel::ParsedMessageValue const&) constUnexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::CustomStructValue>(cel::CustomStructValue const&) constUnexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::OpaqueValue>(cel::OpaqueValue const&) constbool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::BytesValue>(cel::BytesValue const&) constLine | Count | Source | 2594 | 2.68k | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 2.68k | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 2.68k | }); |
bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::StringValue>(cel::StringValue const&) constLine | Count | Source | 2594 | 1.55k | return value.variant_.Visit([](const auto& alternative) -> bool { | 2595 | 1.55k | return ArenaTraits<>::trivially_destructible(alternative); | 2596 | 1.55k | }); |
Unexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::ErrorValue>(cel::ErrorValue const&) constUnexecuted instantiation: bool cel::ArenaTraits<cel::Value>::trivially_destructible(cel::Value const&)::{lambda(auto:1 const&)#1}::operator()<cel::UnknownValue>(cel::UnknownValue const&) const |
2597 | 104k | } |
2598 | | }; |
2599 | | |
2600 | | // Statically assert some expectations. |
2601 | | static_assert(sizeof(Value) <= 32); |
2602 | | static_assert(alignof(Value) <= alignof(std::max_align_t)); |
2603 | | static_assert(std::is_default_constructible_v<Value>); |
2604 | | static_assert(std::is_copy_constructible_v<Value>); |
2605 | | static_assert(std::is_copy_assignable_v<Value>); |
2606 | | static_assert(std::is_nothrow_move_constructible_v<Value>); |
2607 | | static_assert(std::is_nothrow_move_assignable_v<Value>); |
2608 | | static_assert(std::is_nothrow_swappable_v<Value>); |
2609 | | |
2610 | | inline common_internal::ImplicitlyConvertibleStatus |
2611 | 0 | ErrorValueAssign::operator()(absl::Status status) const { |
2612 | 0 | *value_ = ErrorValue(std::move(status)); |
2613 | 0 | return common_internal::ImplicitlyConvertibleStatus(); |
2614 | 0 | } |
2615 | | |
2616 | | namespace common_internal { |
2617 | | |
2618 | | template <typename Base> |
2619 | | absl::StatusOr<Value> ValueMixin<Base>::Equal( |
2620 | | const Value& other, |
2621 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2622 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2623 | 0 | google::protobuf::Arena* absl_nonnull arena) const { |
2624 | 0 | ABSL_DCHECK(descriptor_pool != nullptr); |
2625 | 0 | ABSL_DCHECK(message_factory != nullptr); |
2626 | 0 | ABSL_DCHECK(arena != nullptr); |
2627 | |
|
2628 | 0 | Value result; |
2629 | 0 | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->Equal( |
2630 | 0 | other, descriptor_pool, message_factory, arena, &result)); |
2631 | 0 | return result; |
2632 | 0 | } |
2633 | | |
2634 | | template <typename Base> |
2635 | | absl::StatusOr<Value> ListValueMixin<Base>::Get( |
2636 | | size_t index, const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2637 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2638 | 112k | google::protobuf::Arena* absl_nonnull arena) const { |
2639 | 112k | ABSL_DCHECK(descriptor_pool != nullptr); |
2640 | 112k | ABSL_DCHECK(message_factory != nullptr); |
2641 | 112k | ABSL_DCHECK(arena != nullptr); |
2642 | | |
2643 | 112k | Value result; |
2644 | 112k | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->Get( |
2645 | 112k | index, descriptor_pool, message_factory, arena, &result)); |
2646 | 112k | return result; |
2647 | 112k | } |
2648 | | |
2649 | | template <typename Base> |
2650 | | absl::StatusOr<Value> ListValueMixin<Base>::Contains( |
2651 | | const Value& other, |
2652 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2653 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2654 | 1.53k | google::protobuf::Arena* absl_nonnull arena) const { |
2655 | 1.53k | ABSL_DCHECK(descriptor_pool != nullptr); |
2656 | 1.53k | ABSL_DCHECK(message_factory != nullptr); |
2657 | 1.53k | ABSL_DCHECK(arena != nullptr); |
2658 | | |
2659 | 1.53k | Value result; |
2660 | 1.53k | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->Contains( |
2661 | 1.53k | other, descriptor_pool, message_factory, arena, &result)); |
2662 | 1.53k | return result; |
2663 | 1.53k | } |
2664 | | |
2665 | | template <typename Base> |
2666 | | absl::StatusOr<Value> MapValueMixin<Base>::Get( |
2667 | | const Value& key, |
2668 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2669 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2670 | 14 | google::protobuf::Arena* absl_nonnull arena) const { |
2671 | 14 | ABSL_DCHECK(descriptor_pool != nullptr); |
2672 | 14 | ABSL_DCHECK(message_factory != nullptr); |
2673 | 14 | ABSL_DCHECK(arena != nullptr); |
2674 | | |
2675 | 14 | Value result; |
2676 | 14 | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->Get( |
2677 | 14 | key, descriptor_pool, message_factory, arena, &result)); |
2678 | 14 | return result; |
2679 | 14 | } |
2680 | | |
2681 | | template <typename Base> |
2682 | | absl::StatusOr<absl::optional<Value>> MapValueMixin<Base>::Find( |
2683 | | const Value& other, |
2684 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2685 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2686 | 68 | google::protobuf::Arena* absl_nonnull arena) const { |
2687 | 68 | ABSL_DCHECK(descriptor_pool != nullptr); |
2688 | 68 | ABSL_DCHECK(message_factory != nullptr); |
2689 | 68 | ABSL_DCHECK(arena != nullptr); |
2690 | | |
2691 | 68 | Value result; |
2692 | 68 | CEL_ASSIGN_OR_RETURN( |
2693 | 68 | bool found, static_cast<const Base*>(this)->Find( |
2694 | 68 | other, descriptor_pool, message_factory, arena, &result)); |
2695 | 68 | if (found) { |
2696 | 14 | return result; |
2697 | 14 | } |
2698 | 54 | return absl::nullopt; |
2699 | 68 | } |
2700 | | |
2701 | | template <typename Base> |
2702 | | absl::StatusOr<Value> MapValueMixin<Base>::Has( |
2703 | | const Value& key, |
2704 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2705 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2706 | 0 | google::protobuf::Arena* absl_nonnull arena) const { |
2707 | 0 | ABSL_DCHECK(descriptor_pool != nullptr); |
2708 | 0 | ABSL_DCHECK(message_factory != nullptr); |
2709 | 0 | ABSL_DCHECK(arena != nullptr); |
2710 | |
|
2711 | 0 | Value result; |
2712 | 0 | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->Has( |
2713 | 0 | key, descriptor_pool, message_factory, arena, &result)); |
2714 | 0 | return result; |
2715 | 0 | } |
2716 | | |
2717 | | template <typename Base> |
2718 | | absl::StatusOr<ListValue> MapValueMixin<Base>::ListKeys( |
2719 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2720 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2721 | | google::protobuf::Arena* absl_nonnull arena) const { |
2722 | | ABSL_DCHECK(descriptor_pool != nullptr); |
2723 | | ABSL_DCHECK(message_factory != nullptr); |
2724 | | ABSL_DCHECK(arena != nullptr); |
2725 | | |
2726 | | ListValue result; |
2727 | | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->ListKeys( |
2728 | | descriptor_pool, message_factory, arena, &result)); |
2729 | | return result; |
2730 | | } |
2731 | | |
2732 | | template <typename Base> |
2733 | | absl::StatusOr<Value> StructValueMixin<Base>::GetFieldByName( |
2734 | | absl::string_view name, |
2735 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2736 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2737 | 0 | google::protobuf::Arena* absl_nonnull arena) const { |
2738 | 0 | ABSL_DCHECK(descriptor_pool != nullptr); |
2739 | 0 | ABSL_DCHECK(message_factory != nullptr); |
2740 | 0 | ABSL_DCHECK(arena != nullptr); |
2741 | |
|
2742 | 0 | Value result; |
2743 | 0 | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->GetFieldByName( |
2744 | 0 | name, ProtoWrapperTypeOptions::kUnsetNull, descriptor_pool, |
2745 | 0 | message_factory, arena, &result)); |
2746 | 0 | return result; |
2747 | 0 | } |
2748 | | |
2749 | | template <typename Base> |
2750 | | absl::StatusOr<Value> StructValueMixin<Base>::GetFieldByName( |
2751 | | absl::string_view name, ProtoWrapperTypeOptions unboxing_options, |
2752 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2753 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2754 | | google::protobuf::Arena* absl_nonnull arena) const { |
2755 | | ABSL_DCHECK(descriptor_pool != nullptr); |
2756 | | ABSL_DCHECK(message_factory != nullptr); |
2757 | | ABSL_DCHECK(arena != nullptr); |
2758 | | |
2759 | | Value result; |
2760 | | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->GetFieldByName( |
2761 | | name, unboxing_options, descriptor_pool, message_factory, arena, |
2762 | | &result)); |
2763 | | return result; |
2764 | | } |
2765 | | |
2766 | | template <typename Base> |
2767 | | absl::StatusOr<Value> StructValueMixin<Base>::GetFieldByNumber( |
2768 | | int64_t number, const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2769 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2770 | | google::protobuf::Arena* absl_nonnull arena) const { |
2771 | | ABSL_DCHECK(descriptor_pool != nullptr); |
2772 | | ABSL_DCHECK(message_factory != nullptr); |
2773 | | ABSL_DCHECK(arena != nullptr); |
2774 | | |
2775 | | Value result; |
2776 | | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->GetFieldByNumber( |
2777 | | number, ProtoWrapperTypeOptions::kUnsetNull, descriptor_pool, |
2778 | | message_factory, arena, &result)); |
2779 | | return result; |
2780 | | } |
2781 | | |
2782 | | template <typename Base> |
2783 | | absl::StatusOr<Value> StructValueMixin<Base>::GetFieldByNumber( |
2784 | | int64_t number, ProtoWrapperTypeOptions unboxing_options, |
2785 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2786 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2787 | | google::protobuf::Arena* absl_nonnull arena) const { |
2788 | | ABSL_DCHECK(descriptor_pool != nullptr); |
2789 | | ABSL_DCHECK(message_factory != nullptr); |
2790 | | ABSL_DCHECK(arena != nullptr); |
2791 | | |
2792 | | Value result; |
2793 | | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->GetFieldByNumber( |
2794 | | number, unboxing_options, descriptor_pool, message_factory, arena, |
2795 | | &result)); |
2796 | | return result; |
2797 | | } |
2798 | | |
2799 | | template <typename Base> |
2800 | | absl::StatusOr<std::pair<Value, int>> StructValueMixin<Base>::Qualify( |
2801 | | absl::Span<const SelectQualifier> qualifiers, bool presence_test, |
2802 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2803 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2804 | 0 | google::protobuf::Arena* absl_nonnull arena) const { |
2805 | 0 | ABSL_DCHECK_GT(qualifiers.size(), 0); |
2806 | 0 | ABSL_DCHECK(descriptor_pool != nullptr); |
2807 | 0 | ABSL_DCHECK(message_factory != nullptr); |
2808 | 0 | ABSL_DCHECK(arena != nullptr); |
2809 | |
|
2810 | 0 | Value result; |
2811 | 0 | int count; |
2812 | 0 | CEL_RETURN_IF_ERROR(static_cast<const Base*>(this)->Qualify( |
2813 | 0 | qualifiers, presence_test, descriptor_pool, message_factory, arena, |
2814 | 0 | &result, &count)); |
2815 | 0 | return std::pair{std::move(result), count}; |
2816 | 0 | } |
2817 | | |
2818 | | } // namespace common_internal |
2819 | | |
2820 | | using ValueIteratorPtr = std::unique_ptr<ValueIterator>; |
2821 | | |
2822 | | inline absl::StatusOr<Value> ValueIterator::Next( |
2823 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2824 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2825 | 44 | google::protobuf::Arena* absl_nonnull arena) { |
2826 | 44 | ABSL_DCHECK(descriptor_pool != nullptr); |
2827 | 44 | ABSL_DCHECK(message_factory != nullptr); |
2828 | 44 | ABSL_DCHECK(arena != nullptr); |
2829 | | |
2830 | 44 | Value result; |
2831 | 44 | CEL_RETURN_IF_ERROR(Next(descriptor_pool, message_factory, arena, &result)); |
2832 | 44 | return result; |
2833 | 44 | } |
2834 | | |
2835 | | inline absl::StatusOr<absl::optional<Value>> ValueIterator::Next1( |
2836 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2837 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2838 | 0 | google::protobuf::Arena* absl_nonnull arena) { |
2839 | 0 | ABSL_DCHECK(descriptor_pool != nullptr); |
2840 | 0 | ABSL_DCHECK(message_factory != nullptr); |
2841 | 0 | ABSL_DCHECK(arena != nullptr); |
2842 | |
|
2843 | 0 | Value key_or_value; |
2844 | 0 | CEL_ASSIGN_OR_RETURN( |
2845 | 0 | bool ok, Next1(descriptor_pool, message_factory, arena, &key_or_value)); |
2846 | 0 | if (!ok) { |
2847 | 0 | return absl::nullopt; |
2848 | 0 | } |
2849 | 0 | return key_or_value; |
2850 | 0 | } |
2851 | | |
2852 | | inline absl::StatusOr<absl::optional<std::pair<Value, Value>>> |
2853 | | ValueIterator::Next2(const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2854 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2855 | 0 | google::protobuf::Arena* absl_nonnull arena) { |
2856 | 0 | ABSL_DCHECK(descriptor_pool != nullptr); |
2857 | 0 | ABSL_DCHECK(message_factory != nullptr); |
2858 | 0 | ABSL_DCHECK(arena != nullptr); |
2859 | 0 |
|
2860 | 0 | Value key; |
2861 | 0 | Value value; |
2862 | 0 | CEL_ASSIGN_OR_RETURN( |
2863 | 0 | bool ok, Next2(descriptor_pool, message_factory, arena, &key, &value)); |
2864 | 0 | if (!ok) { |
2865 | 0 | return absl::nullopt; |
2866 | 0 | } |
2867 | 0 | return std::pair{std::move(key), std::move(value)}; |
2868 | 0 | } |
2869 | | |
2870 | | absl_nonnull std::unique_ptr<ValueIterator> NewEmptyValueIterator(); |
2871 | | |
2872 | | class ValueBuilder { |
2873 | | public: |
2874 | 1.65k | virtual ~ValueBuilder() = default; |
2875 | | |
2876 | | virtual absl::StatusOr<absl::optional<ErrorValue>> SetFieldByName( |
2877 | | absl::string_view name, Value value) = 0; |
2878 | | |
2879 | | virtual absl::StatusOr<absl::optional<ErrorValue>> SetFieldByNumber( |
2880 | | int64_t number, Value value) = 0; |
2881 | | |
2882 | | virtual absl::StatusOr<Value> Build() && = 0; |
2883 | | }; |
2884 | | |
2885 | | using ValueBuilderPtr = std::unique_ptr<ValueBuilder>; |
2886 | | |
2887 | | absl_nonnull ListValueBuilderPtr |
2888 | | NewListValueBuilder(google::protobuf::Arena* absl_nonnull arena); |
2889 | | |
2890 | | absl_nonnull MapValueBuilderPtr |
2891 | | NewMapValueBuilder(google::protobuf::Arena* absl_nonnull arena); |
2892 | | |
2893 | | // Returns a new `StructValueBuilder`. Returns `nullptr` if there is no such |
2894 | | // message type with the name `name` in `descriptor_pool`. Returns an error if |
2895 | | // `message_factory` is unable to provide a prototype for the descriptor |
2896 | | // returned from `descriptor_pool`. |
2897 | | absl_nullable StructValueBuilderPtr NewStructValueBuilder( |
2898 | | google::protobuf::Arena* absl_nonnull arena, |
2899 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
2900 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
2901 | | absl::string_view name); |
2902 | | |
2903 | | using ListValueBuilderInterface = ListValueBuilder; |
2904 | | using MapValueBuilderInterface = MapValueBuilder; |
2905 | | using StructValueBuilderInterface = StructValueBuilder; |
2906 | | |
2907 | | // Now that Value is complete, we can define various parts of list, map, opaque, |
2908 | | // and struct which depend on Value. |
2909 | | |
2910 | | namespace common_internal { |
2911 | | |
2912 | | using MapFieldKeyAccessor = void (*)(const google::protobuf::MapKey&, |
2913 | | const google::protobuf::Message* absl_nonnull, |
2914 | | google::protobuf::Arena* absl_nonnull, |
2915 | | Value* absl_nonnull); |
2916 | | |
2917 | | absl::StatusOr<MapFieldKeyAccessor> MapFieldKeyAccessorFor( |
2918 | | const google::protobuf::FieldDescriptor* absl_nonnull field); |
2919 | | |
2920 | | using MapFieldValueAccessor = void (*)( |
2921 | | const google::protobuf::MapValueConstRef&, const google::protobuf::Message* absl_nonnull, |
2922 | | const google::protobuf::FieldDescriptor* absl_nonnull, |
2923 | | const google::protobuf::DescriptorPool* absl_nonnull, |
2924 | | google::protobuf::MessageFactory* absl_nonnull, google::protobuf::Arena* absl_nonnull, |
2925 | | Value* absl_nonnull); |
2926 | | |
2927 | | absl::StatusOr<MapFieldValueAccessor> MapFieldValueAccessorFor( |
2928 | | const google::protobuf::FieldDescriptor* absl_nonnull field); |
2929 | | |
2930 | | using RepeatedFieldAccessor = |
2931 | | void (*)(int, const google::protobuf::Message* absl_nonnull, |
2932 | | const google::protobuf::FieldDescriptor* absl_nonnull, |
2933 | | const google::protobuf::Reflection* absl_nonnull, |
2934 | | const google::protobuf::DescriptorPool* absl_nonnull, |
2935 | | google::protobuf::MessageFactory* absl_nonnull, google::protobuf::Arena* absl_nonnull, |
2936 | | Value* absl_nonnull); |
2937 | | |
2938 | | absl::StatusOr<RepeatedFieldAccessor> RepeatedFieldAccessorFor( |
2939 | | const google::protobuf::FieldDescriptor* absl_nonnull field); |
2940 | | |
2941 | | } // namespace common_internal |
2942 | | |
2943 | | } // namespace cel |
2944 | | |
2945 | | #pragma pop_macro("GetMessage") |
2946 | | |
2947 | | #endif // THIRD_PARTY_CEL_CPP_COMMON_VALUE_H_ |