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