/proc/self/cwd/common/values/unknown_value.h
Line | Count | Source |
1 | | // Copyright 2024 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | // IWYU pragma: private, include "common/value.h" |
16 | | // IWYU pragma: friend "common/value.h" |
17 | | |
18 | | #ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_UNKNOWN_VALUE_H_ |
19 | | #define THIRD_PARTY_CEL_CPP_COMMON_VALUES_UNKNOWN_VALUE_H_ |
20 | | |
21 | | #include <ostream> |
22 | | #include <string> |
23 | | #include <utility> |
24 | | |
25 | | #include "absl/base/attributes.h" |
26 | | #include "absl/base/nullability.h" |
27 | | #include "absl/status/status.h" |
28 | | #include "absl/strings/string_view.h" |
29 | | #include "common/type.h" |
30 | | #include "common/unknown.h" |
31 | | #include "common/value_kind.h" |
32 | | #include "common/values/values.h" |
33 | | #include "google/protobuf/arena.h" |
34 | | #include "google/protobuf/descriptor.h" |
35 | | #include "google/protobuf/io/zero_copy_stream.h" |
36 | | #include "google/protobuf/message.h" |
37 | | |
38 | | namespace cel { |
39 | | |
40 | | class Value; |
41 | | class UnknownValue; |
42 | | |
43 | | // `UnknownValue` represents values of the primitive `duration` type. |
44 | | class UnknownValue final : private common_internal::ValueMixin<UnknownValue> { |
45 | | public: |
46 | | static constexpr ValueKind kKind = ValueKind::kUnknown; |
47 | | |
48 | 0 | explicit UnknownValue(Unknown unknown) : unknown_(std::move(unknown)) {} |
49 | | |
50 | | UnknownValue() = default; |
51 | 0 | UnknownValue(const UnknownValue&) = default; |
52 | 0 | UnknownValue(UnknownValue&&) = default; |
53 | | UnknownValue& operator=(const UnknownValue&) = default; |
54 | 0 | UnknownValue& operator=(UnknownValue&&) = default; |
55 | | |
56 | 0 | constexpr ValueKind kind() const { return kKind; } |
57 | | |
58 | 0 | absl::string_view GetTypeName() const { return UnknownType::kName; } |
59 | | |
60 | 0 | std::string DebugString() const { return ""; } |
61 | | |
62 | | // See Value::SerializeTo(). |
63 | | absl::Status SerializeTo( |
64 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
65 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
66 | | google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const; |
67 | | |
68 | | // See Value::ConvertToJson(). |
69 | | absl::Status ConvertToJson( |
70 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
71 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
72 | | google::protobuf::Message* absl_nonnull json) const; |
73 | | |
74 | | absl::Status Equal(const Value& other, |
75 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
76 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
77 | | google::protobuf::Arena* absl_nonnull arena, |
78 | | Value* absl_nonnull result) const; |
79 | | using ValueMixin::Equal; |
80 | | |
81 | 0 | bool IsZeroValue() const { return false; } |
82 | | |
83 | 0 | void swap(UnknownValue& other) noexcept { |
84 | 0 | using std::swap; |
85 | 0 | swap(unknown_, other.unknown_); |
86 | 0 | } |
87 | | |
88 | 0 | const Unknown& NativeValue() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
89 | 0 | return unknown_; |
90 | 0 | } |
91 | | |
92 | 0 | Unknown NativeValue() && { |
93 | 0 | Unknown unknown = std::move(unknown_); |
94 | 0 | return unknown; |
95 | 0 | } |
96 | | |
97 | 0 | const AttributeSet& attribute_set() const { |
98 | 0 | return unknown_.unknown_attributes(); |
99 | 0 | } |
100 | | |
101 | 0 | const FunctionResultSet& function_result_set() const { |
102 | 0 | return unknown_.unknown_function_results(); |
103 | 0 | } |
104 | | |
105 | | private: |
106 | | friend class common_internal::ValueMixin<UnknownValue>; |
107 | | |
108 | | Unknown unknown_; |
109 | | }; |
110 | | |
111 | 0 | inline void swap(UnknownValue& lhs, UnknownValue& rhs) noexcept { |
112 | 0 | lhs.swap(rhs); |
113 | 0 | } |
114 | | |
115 | 0 | inline std::ostream& operator<<(std::ostream& out, const UnknownValue& value) { |
116 | 0 | return out << value.DebugString(); |
117 | 0 | } |
118 | | |
119 | | } // namespace cel |
120 | | |
121 | | #endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_UNKNOWN_VALUE_H_ |