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