-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathvalues.h
More file actions
324 lines (253 loc) · 10.1 KB
/
values.h
File metadata and controls
324 lines (253 loc) · 10.1 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// 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
#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_VALUES_H_
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_VALUES_H_
#include <memory>
#include <type_traits>
#include "absl/status/status.h"
#include "absl/types/variant.h"
namespace cel {
class ValueManager;
class ValueInterface;
class ListValueInterface;
class MapValueInterface;
class StructValueInterface;
class Value;
class BoolValue;
class BytesValue;
class DoubleValue;
class DurationValue;
class ErrorValue;
class IntValue;
class ListValue;
class MapValue;
class NullValue;
class OpaqueValue;
class OptionalValue;
class StringValue;
class StructValue;
class TimestampValue;
class TypeValue;
class UintValue;
class UnknownValue;
class ParsedMessageValue;
class ParsedMapFieldValue;
class ParsedRepeatedFieldValue;
class ParsedJsonListValue;
class ParsedJsonMapValue;
class EnumValue;
class CustomListValue;
class CustomListValueInterface;
class CustomMapValue;
class CustomMapValueInterface;
class CustomStructValue;
class CustomStructValueInterface;
class ValueIterator;
using ValueIteratorPtr = std::unique_ptr<ValueIterator>;
namespace common_internal {
class SharedByteString;
class SharedByteStringView;
class LegacyListValue;
class LegacyMapValue;
class LegacyStructValue;
template <typename T>
struct IsListValueInterface
: std::bool_constant<
std::conjunction_v<std::negation<std::is_same<ListValueInterface, T>>,
std::is_base_of<ListValueInterface, T>>> {};
template <typename T>
inline constexpr bool IsListValueInterfaceV = IsListValueInterface<T>::value;
template <typename T>
struct IsListValueAlternative
: std::bool_constant<std::disjunction_v<std::is_base_of<CustomListValue, T>,
std::is_same<LegacyListValue, T>>> {
};
template <typename T>
inline constexpr bool IsListValueAlternativeV =
IsListValueAlternative<T>::value;
using ListValueVariant =
absl::variant<CustomListValue, LegacyListValue, ParsedRepeatedFieldValue,
ParsedJsonListValue>;
template <typename T>
struct IsMapValueInterface
: std::bool_constant<
std::conjunction_v<std::negation<std::is_same<MapValueInterface, T>>,
std::is_base_of<MapValueInterface, T>>> {};
template <typename T>
inline constexpr bool IsMapValueInterfaceV = IsMapValueInterface<T>::value;
template <typename T>
struct IsMapValueAlternative
: std::bool_constant<std::disjunction_v<std::is_base_of<CustomMapValue, T>,
std::is_same<LegacyMapValue, T>>> {
};
template <typename T>
inline constexpr bool IsMapValueAlternativeV = IsMapValueAlternative<T>::value;
using MapValueVariant = absl::variant<CustomMapValue, LegacyMapValue,
ParsedMapFieldValue, ParsedJsonMapValue>;
template <typename T>
struct IsStructValueInterface
: std::bool_constant<std::conjunction_v<
std::negation<std::is_same<StructValueInterface, T>>,
std::is_base_of<StructValueInterface, T>>> {};
template <typename T>
inline constexpr bool IsStructValueInterfaceV =
IsStructValueInterface<T>::value;
template <typename T>
struct IsStructValueAlternative
: std::bool_constant<
std::disjunction_v<std::is_base_of<CustomStructValue, T>,
std::is_same<LegacyStructValue, T>>> {};
template <typename T>
inline constexpr bool IsStructValueAlternativeV =
IsStructValueAlternative<T>::value;
using StructValueVariant = absl::variant<absl::monostate, CustomStructValue,
LegacyStructValue, ParsedMessageValue>;
template <typename T>
struct IsValueInterface
: std::bool_constant<
std::conjunction_v<std::negation<std::is_same<ValueInterface, T>>,
std::is_base_of<ValueInterface, T>>> {};
template <typename T>
inline constexpr bool IsValueInterfaceV = IsValueInterface<T>::value;
template <typename T>
struct IsValueAlternative
: std::bool_constant<std::disjunction_v<
std::is_same<BoolValue, T>, std::is_same<BytesValue, T>,
std::is_same<DoubleValue, T>, std::is_same<DurationValue, T>,
std::is_same<ErrorValue, T>, std::is_same<IntValue, T>,
IsListValueAlternative<T>, IsMapValueAlternative<T>,
std::is_same<NullValue, T>, std::is_base_of<OpaqueValue, T>,
std::is_same<StringValue, T>, IsStructValueAlternative<T>,
std::is_same<TimestampValue, T>, std::is_same<TypeValue, T>,
std::is_same<UintValue, T>, std::is_same<UnknownValue, T>,
std::is_same<EnumValue, T>>> {};
template <typename T>
inline constexpr bool IsValueAlternativeV = IsValueAlternative<T>::value;
using ValueVariant =
absl::variant<absl::monostate, BoolValue, BytesValue, DoubleValue,
DurationValue, ErrorValue, IntValue, LegacyListValue,
CustomListValue, ParsedRepeatedFieldValue,
ParsedJsonListValue, LegacyMapValue, CustomMapValue,
ParsedMapFieldValue, ParsedJsonMapValue, NullValue,
OpaqueValue, StringValue, LegacyStructValue,
CustomStructValue, ParsedMessageValue, TimestampValue,
TypeValue, UintValue, UnknownValue, EnumValue>;
// Get the base type alternative for the given alternative or interface. The
// base type alternative is the type stored in the `ValueVariant`.
template <typename T, typename = void>
struct BaseValueAlternativeFor {
static_assert(IsValueAlternativeV<T>);
using type = T;
};
template <typename T>
struct BaseValueAlternativeFor<T, std::enable_if_t<IsValueInterfaceV<T>>>
: BaseValueAlternativeFor<typename T::alternative_type> {};
template <typename T>
struct BaseValueAlternativeFor<
T, std::enable_if_t<std::is_base_of_v<CustomListValue, T>>> {
using type = CustomListValue;
};
template <typename T>
struct BaseValueAlternativeFor<
T, std::enable_if_t<std::is_base_of_v<OpaqueValue, T>>> {
using type = OpaqueValue;
};
template <typename T>
struct BaseValueAlternativeFor<
T, std::enable_if_t<std::is_base_of_v<CustomMapValue, T>>> {
using type = CustomMapValue;
};
template <typename T>
struct BaseValueAlternativeFor<
T, std::enable_if_t<std::is_base_of_v<CustomStructValue, T>>> {
using type = CustomStructValue;
};
template <typename T>
using BaseValueAlternativeForT = typename BaseValueAlternativeFor<T>::type;
template <typename T, typename = void>
struct BaseListValueAlternativeFor {
static_assert(IsListValueAlternativeV<T>);
using type = T;
};
template <typename T>
struct BaseListValueAlternativeFor<T,
std::enable_if_t<IsListValueInterfaceV<T>>>
: BaseValueAlternativeFor<typename T::alternative_type> {};
template <typename T>
struct BaseListValueAlternativeFor<
T, std::enable_if_t<std::is_base_of_v<CustomListValue, T>>> {
using type = CustomListValue;
};
template <typename T>
using BaseListValueAlternativeForT =
typename BaseListValueAlternativeFor<T>::type;
template <typename T, typename = void>
struct BaseMapValueAlternativeFor {
static_assert(IsMapValueAlternativeV<T>);
using type = T;
};
template <typename T>
struct BaseMapValueAlternativeFor<T, std::enable_if_t<IsMapValueInterfaceV<T>>>
: BaseValueAlternativeFor<typename T::alternative_type> {};
template <typename T>
struct BaseMapValueAlternativeFor<
T, std::enable_if_t<std::is_base_of_v<CustomMapValue, T>>> {
using type = CustomMapValue;
};
template <typename T>
using BaseMapValueAlternativeForT =
typename BaseMapValueAlternativeFor<T>::type;
template <typename T, typename = void>
struct BaseStructValueAlternativeFor {
static_assert(IsStructValueAlternativeV<T>);
using type = T;
};
template <typename T>
struct BaseStructValueAlternativeFor<
T, std::enable_if_t<IsStructValueInterfaceV<T>>>
: BaseValueAlternativeFor<typename T::alternative_type> {};
template <typename T>
struct BaseStructValueAlternativeFor<
T, std::enable_if_t<std::is_base_of_v<CustomStructValue, T>>> {
using type = CustomStructValue;
};
template <typename T>
using BaseStructValueAlternativeForT =
typename BaseStructValueAlternativeFor<T>::type;
ErrorValue GetDefaultErrorValue();
CustomListValue GetEmptyDynListValue();
CustomMapValue GetEmptyDynDynMapValue();
OptionalValue GetEmptyDynOptionalValue();
absl::Status ListValueEqual(ValueManager& value_manager, const ListValue& lhs,
const ListValue& rhs, Value& result);
absl::Status ListValueEqual(ValueManager& value_manager,
const CustomListValueInterface& lhs,
const ListValue& rhs, Value& result);
absl::Status MapValueEqual(ValueManager& value_manager, const MapValue& lhs,
const MapValue& rhs, Value& result);
absl::Status MapValueEqual(ValueManager& value_manager,
const CustomMapValueInterface& lhs,
const MapValue& rhs, Value& result);
absl::Status StructValueEqual(ValueManager& value_manager,
const StructValue& lhs, const StructValue& rhs,
Value& result);
absl::Status StructValueEqual(ValueManager& value_manager,
const CustomStructValueInterface& lhs,
const StructValue& rhs, Value& result);
const SharedByteString& AsSharedByteString(const BytesValue& value);
const SharedByteString& AsSharedByteString(const StringValue& value);
} // namespace common_internal
} // namespace cel
#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_VALUES_H_