Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/values/legacy_map_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
// IWYU pragma: private, include "common/values/map_value.h"
16
// IWYU pragma: friend "common/values/map_value.h"
17
18
#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_MAP_VALUE_H_
19
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_MAP_VALUE_H_
20
21
#include <cstddef>
22
#include <ostream>
23
#include <string>
24
25
#include "absl/base/nullability.h"
26
#include "absl/status/status.h"
27
#include "absl/status/statusor.h"
28
#include "absl/strings/cord.h"
29
#include "absl/strings/string_view.h"
30
#include "absl/types/optional.h"
31
#include "common/value_kind.h"
32
#include "common/values/custom_map_value.h"
33
#include "common/values/values.h"
34
#include "google/protobuf/arena.h"
35
#include "google/protobuf/descriptor.h"
36
#include "google/protobuf/io/zero_copy_stream.h"
37
#include "google/protobuf/message.h"
38
39
namespace google::api::expr::runtime {
40
class CelMap;
41
}
42
43
namespace cel {
44
45
class Value;
46
47
namespace common_internal {
48
49
class LegacyMapValue;
50
51
class LegacyMapValue final
52
    : private common_internal::MapValueMixin<LegacyMapValue> {
53
 public:
54
  static constexpr ValueKind kKind = ValueKind::kMap;
55
56
  explicit LegacyMapValue(
57
      const google::api::expr::runtime::CelMap* absl_nullability_unknown impl)
58
720
      : impl_(impl) {}
59
60
  // By default, this creates an empty map whose type is `map(dyn, dyn)`.
61
  // Unless you can help it, you should use a more specific typed map value.
62
  LegacyMapValue() = default;
63
  LegacyMapValue(const LegacyMapValue&) = default;
64
  LegacyMapValue(LegacyMapValue&&) = default;
65
  LegacyMapValue& operator=(const LegacyMapValue&) = default;
66
  LegacyMapValue& operator=(LegacyMapValue&&) = default;
67
68
0
  constexpr ValueKind kind() const { return kKind; }
69
70
0
  absl::string_view GetTypeName() const { return "map"; }
71
72
  std::string DebugString() const;
73
74
  // See Value::SerializeTo().
75
  absl::Status SerializeTo(
76
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
77
      google::protobuf::MessageFactory* absl_nonnull message_factory,
78
      google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const;
79
80
  // See Value::ConvertToJson().
81
  absl::Status ConvertToJson(
82
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
83
      google::protobuf::MessageFactory* absl_nonnull message_factory,
84
      google::protobuf::Message* absl_nonnull json) const;
85
86
  // See Value::ConvertToJsonObject().
87
  absl::Status ConvertToJsonObject(
88
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
89
      google::protobuf::MessageFactory* absl_nonnull message_factory,
90
      google::protobuf::Message* absl_nonnull json) const;
91
92
  absl::Status Equal(const Value& other,
93
                     const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
94
                     google::protobuf::MessageFactory* absl_nonnull message_factory,
95
                     google::protobuf::Arena* absl_nonnull arena,
96
                     Value* absl_nonnull result) const;
97
  using MapValueMixin::Equal;
98
99
0
  bool IsZeroValue() const { return IsEmpty(); }
100
101
  bool IsEmpty() const;
102
103
  size_t Size() const;
104
105
  // See the corresponding member function of `MapValue` for
106
  // documentation.
107
  absl::Status Get(const Value& key,
108
                   const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
109
                   google::protobuf::MessageFactory* absl_nonnull message_factory,
110
                   google::protobuf::Arena* absl_nonnull arena,
111
                   Value* absl_nonnull result) const;
112
  using MapValueMixin::Get;
113
114
  // See the corresponding member function of `MapValue` for
115
  // documentation.
116
  absl::StatusOr<bool> Find(
117
      const Value& key,
118
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
119
      google::protobuf::MessageFactory* absl_nonnull message_factory,
120
      google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const;
121
  using MapValueMixin::Find;
122
123
  // See the corresponding member function of `MapValue` for
124
  // documentation.
125
  absl::Status Has(const Value& key,
126
                   const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
127
                   google::protobuf::MessageFactory* absl_nonnull message_factory,
128
                   google::protobuf::Arena* absl_nonnull arena,
129
                   Value* absl_nonnull result) const;
130
  using MapValueMixin::Has;
131
132
  // See the corresponding member function of `MapValue` for
133
  // documentation.
134
  absl::Status ListKeys(
135
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
136
      google::protobuf::MessageFactory* absl_nonnull message_factory,
137
      google::protobuf::Arena* absl_nonnull arena, ListValue* absl_nonnull result) const;
138
  using MapValueMixin::ListKeys;
139
140
  // See the corresponding type declaration of `MapValue` for
141
  // documentation.
142
  using ForEachCallback = typename CustomMapValueInterface::ForEachCallback;
143
144
  // See the corresponding member function of `MapValue` for
145
  // documentation.
146
  absl::Status ForEach(
147
      ForEachCallback callback,
148
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
149
      google::protobuf::MessageFactory* absl_nonnull message_factory,
150
      google::protobuf::Arena* absl_nonnull arena) const;
151
152
  absl::StatusOr<absl_nonnull ValueIteratorPtr> NewIterator() const;
153
154
44
  const google::api::expr::runtime::CelMap* absl_nonnull cel_map() const {
155
44
    return impl_;
156
44
  }
157
158
0
  friend void swap(LegacyMapValue& lhs, LegacyMapValue& rhs) noexcept {
159
0
    using std::swap;
160
0
    swap(lhs.impl_, rhs.impl_);
161
0
  }
162
163
 private:
164
  friend class common_internal::ValueMixin<LegacyMapValue>;
165
  friend class common_internal::MapValueMixin<LegacyMapValue>;
166
167
  const google::api::expr::runtime::CelMap* absl_nullability_unknown impl_ =
168
      nullptr;
169
};
170
171
0
inline std::ostream& operator<<(std::ostream& out, const LegacyMapValue& type) {
172
0
  return out << type.DebugString();
173
0
}
174
175
bool IsLegacyMapValue(const Value& value);
176
177
LegacyMapValue GetLegacyMapValue(const Value& value);
178
179
absl::optional<LegacyMapValue> AsLegacyMapValue(const Value& value);
180
181
}  // namespace common_internal
182
183
}  // namespace cel
184
185
#endif  // THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_MAP_VALUE_H_