/proc/self/cwd/common/values/map_value_variant.h
Line | Count | Source |
1 | | // Copyright 2025 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_VALUES_MAP_VALUE_VARIANT_H_ |
16 | | #define THIRD_PARTY_CEL_CPP_COMMON_VALUES_MAP_VALUE_VARIANT_H_ |
17 | | |
18 | | #include <cstddef> |
19 | | #include <cstdint> |
20 | | #include <type_traits> |
21 | | |
22 | | #include "absl/base/attributes.h" |
23 | | #include "absl/base/nullability.h" |
24 | | #include "absl/log/absl_check.h" |
25 | | #include "absl/meta/type_traits.h" |
26 | | #include "absl/utility/utility.h" |
27 | | #include "common/values/custom_map_value.h" |
28 | | #include "common/values/legacy_map_value.h" |
29 | | #include "common/values/parsed_json_map_value.h" |
30 | | #include "common/values/parsed_map_field_value.h" |
31 | | |
32 | | namespace cel::common_internal { |
33 | | |
34 | | enum class MapValueIndex : uint16_t { |
35 | | kCustom = 0, |
36 | | kParsedField, |
37 | | kParsedJson, |
38 | | kLegacy, |
39 | | }; |
40 | | |
41 | | template <typename T> |
42 | | struct MapValueAlternative; |
43 | | |
44 | | template <> |
45 | | struct MapValueAlternative<CustomMapValue> { |
46 | | static constexpr MapValueIndex kIndex = MapValueIndex::kCustom; |
47 | | }; |
48 | | |
49 | | template <> |
50 | | struct MapValueAlternative<ParsedMapFieldValue> { |
51 | | static constexpr MapValueIndex kIndex = MapValueIndex::kParsedField; |
52 | | }; |
53 | | |
54 | | template <> |
55 | | struct MapValueAlternative<ParsedJsonMapValue> { |
56 | | static constexpr MapValueIndex kIndex = MapValueIndex::kParsedJson; |
57 | | }; |
58 | | |
59 | | template <> |
60 | | struct MapValueAlternative<LegacyMapValue> { |
61 | | static constexpr MapValueIndex kIndex = MapValueIndex::kLegacy; |
62 | | }; |
63 | | |
64 | | template <typename T, typename = void> |
65 | | struct IsMapValueAlternative : std::false_type {}; |
66 | | |
67 | | template <typename T> |
68 | | struct IsMapValueAlternative<T, std::void_t<decltype(MapValueAlternative<T>{})>> |
69 | | : std::true_type {}; |
70 | | |
71 | | template <typename T> |
72 | | inline constexpr bool IsMapValueAlternativeV = IsMapValueAlternative<T>::value; |
73 | | |
74 | | inline constexpr size_t kMapValueVariantAlign = 8; |
75 | | inline constexpr size_t kMapValueVariantSize = 24; |
76 | | |
77 | | // MapValueVariant is a subset of alternatives from the main ValueVariant that |
78 | | // is only maps. It is not stored directly in ValueVariant. |
79 | | class alignas(kMapValueVariantAlign) MapValueVariant final { |
80 | | public: |
81 | 6.15k | MapValueVariant() : MapValueVariant(absl::in_place_type<CustomMapValue>) {} |
82 | | |
83 | | MapValueVariant(const MapValueVariant&) = default; |
84 | | MapValueVariant(MapValueVariant&&) = default; |
85 | | MapValueVariant& operator=(const MapValueVariant&) = default; |
86 | | MapValueVariant& operator=(MapValueVariant&&) = default; |
87 | | |
88 | | template <typename T, typename... Args> |
89 | | explicit MapValueVariant(absl::in_place_type_t<T>, Args&&... args) |
90 | 15.1k | : index_(MapValueAlternative<T>::kIndex) { |
91 | 15.1k | static_assert(alignof(T) <= kMapValueVariantAlign); |
92 | 15.1k | static_assert(sizeof(T) <= kMapValueVariantSize); |
93 | 15.1k | static_assert(std::is_trivially_copyable_v<T>); |
94 | | |
95 | 15.1k | ::new (static_cast<void*>(&raw_[0])) T(std::forward<Args>(args)...); |
96 | 15.1k | } cel::common_internal::MapValueVariant::MapValueVariant<cel::CustomMapValue>(std::__1::in_place_type_t<cel::CustomMapValue>) Line | Count | Source | 90 | 6.15k | : index_(MapValueAlternative<T>::kIndex) { | 91 | 6.15k | static_assert(alignof(T) <= kMapValueVariantAlign); | 92 | 6.15k | static_assert(sizeof(T) <= kMapValueVariantSize); | 93 | 6.15k | static_assert(std::is_trivially_copyable_v<T>); | 94 | | | 95 | 6.15k | ::new (static_cast<void*>(&raw_[0])) T(std::forward<Args>(args)...); | 96 | 6.15k | } |
cel::common_internal::MapValueVariant::MapValueVariant<cel::CustomMapValue, cel::CustomMapValue const&>(std::__1::in_place_type_t<cel::CustomMapValue>, cel::CustomMapValue const&) Line | Count | Source | 90 | 5.71k | : index_(MapValueAlternative<T>::kIndex) { | 91 | 5.71k | static_assert(alignof(T) <= kMapValueVariantAlign); | 92 | 5.71k | static_assert(sizeof(T) <= kMapValueVariantSize); | 93 | 5.71k | static_assert(std::is_trivially_copyable_v<T>); | 94 | | | 95 | 5.71k | ::new (static_cast<void*>(&raw_[0])) T(std::forward<Args>(args)...); | 96 | 5.71k | } |
cel::common_internal::MapValueVariant::MapValueVariant<cel::common_internal::LegacyMapValue, cel::common_internal::LegacyMapValue const&>(std::__1::in_place_type_t<cel::common_internal::LegacyMapValue>, cel::common_internal::LegacyMapValue const&) Line | Count | Source | 90 | 666 | : index_(MapValueAlternative<T>::kIndex) { | 91 | 666 | static_assert(alignof(T) <= kMapValueVariantAlign); | 92 | 666 | static_assert(sizeof(T) <= kMapValueVariantSize); | 93 | 666 | static_assert(std::is_trivially_copyable_v<T>); | 94 | | | 95 | 666 | ::new (static_cast<void*>(&raw_[0])) T(std::forward<Args>(args)...); | 96 | 666 | } |
Unexecuted instantiation: cel::common_internal::MapValueVariant::MapValueVariant<cel::ParsedJsonMapValue, cel::ParsedJsonMapValue const&>(std::__1::in_place_type_t<cel::ParsedJsonMapValue>, cel::ParsedJsonMapValue const&) Unexecuted instantiation: cel::common_internal::MapValueVariant::MapValueVariant<cel::ParsedMapFieldValue, cel::ParsedMapFieldValue const&>(std::__1::in_place_type_t<cel::ParsedMapFieldValue>, cel::ParsedMapFieldValue const&) cel::common_internal::MapValueVariant::MapValueVariant<cel::CustomMapValue, cel::CustomMapValue>(std::__1::in_place_type_t<cel::CustomMapValue>, cel::CustomMapValue&&) Line | Count | Source | 90 | 1.97k | : index_(MapValueAlternative<T>::kIndex) { | 91 | 1.97k | static_assert(alignof(T) <= kMapValueVariantAlign); | 92 | 1.97k | static_assert(sizeof(T) <= kMapValueVariantSize); | 93 | 1.97k | static_assert(std::is_trivially_copyable_v<T>); | 94 | | | 95 | 1.97k | ::new (static_cast<void*>(&raw_[0])) T(std::forward<Args>(args)...); | 96 | 1.97k | } |
cel::common_internal::MapValueVariant::MapValueVariant<cel::common_internal::LegacyMapValue, cel::common_internal::LegacyMapValue>(std::__1::in_place_type_t<cel::common_internal::LegacyMapValue>, cel::common_internal::LegacyMapValue&&) Line | Count | Source | 90 | 677 | : index_(MapValueAlternative<T>::kIndex) { | 91 | 677 | static_assert(alignof(T) <= kMapValueVariantAlign); | 92 | 677 | static_assert(sizeof(T) <= kMapValueVariantSize); | 93 | 677 | static_assert(std::is_trivially_copyable_v<T>); | 94 | | | 95 | 677 | ::new (static_cast<void*>(&raw_[0])) T(std::forward<Args>(args)...); | 96 | 677 | } |
Unexecuted instantiation: cel::common_internal::MapValueVariant::MapValueVariant<cel::ParsedJsonMapValue, cel::ParsedJsonMapValue>(std::__1::in_place_type_t<cel::ParsedJsonMapValue>, cel::ParsedJsonMapValue&&) Unexecuted instantiation: cel::common_internal::MapValueVariant::MapValueVariant<cel::ParsedMapFieldValue, cel::ParsedMapFieldValue>(std::__1::in_place_type_t<cel::ParsedMapFieldValue>, cel::ParsedMapFieldValue&&) |
97 | | |
98 | | template <typename T, typename = std::enable_if_t< |
99 | | IsMapValueAlternativeV<absl::remove_cvref_t<T>>>> |
100 | | explicit MapValueVariant(T&& value) |
101 | | : MapValueVariant(absl::in_place_type<absl::remove_cvref_t<T>>, |
102 | | std::forward<T>(value)) {} |
103 | | |
104 | | template <typename T> |
105 | | void Assign(T&& value) { |
106 | | using U = absl::remove_cvref_t<T>; |
107 | | |
108 | | static_assert(alignof(U) <= kMapValueVariantAlign); |
109 | | static_assert(sizeof(U) <= kMapValueVariantSize); |
110 | | static_assert(std::is_trivially_copyable_v<U>); |
111 | | |
112 | | index_ = MapValueAlternative<U>::kIndex; |
113 | | ::new (static_cast<void*>(&raw_[0])) U(std::forward<T>(value)); |
114 | | } |
115 | | |
116 | | template <typename T> |
117 | 0 | bool Is() const { |
118 | 0 | return index_ == MapValueAlternative<T>::kIndex; |
119 | 0 | } Unexecuted instantiation: bool cel::common_internal::MapValueVariant::Is<cel::CustomMapValue>() const Unexecuted instantiation: bool cel::common_internal::MapValueVariant::Is<cel::ParsedMapFieldValue>() const Unexecuted instantiation: bool cel::common_internal::MapValueVariant::Is<cel::ParsedJsonMapValue>() const Unexecuted instantiation: bool cel::common_internal::MapValueVariant::Is<cel::common_internal::LegacyMapValue>() const |
120 | | |
121 | | template <typename T> |
122 | | T& Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { |
123 | | ABSL_DCHECK(Is<T>()); |
124 | | |
125 | | return *At<T>(); |
126 | | } |
127 | | |
128 | | template <typename T> |
129 | 15.5k | const T& Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
130 | 15.5k | ABSL_DCHECK(Is<T>()); |
131 | | |
132 | 15.5k | return *At<T>(); |
133 | 15.5k | } Unexecuted instantiation: cel::ParsedMapFieldValue const& cel::common_internal::MapValueVariant::Get<cel::ParsedMapFieldValue>() const & Unexecuted instantiation: cel::ParsedJsonMapValue const& cel::common_internal::MapValueVariant::Get<cel::ParsedJsonMapValue>() const & cel::common_internal::LegacyMapValue const& cel::common_internal::MapValueVariant::Get<cel::common_internal::LegacyMapValue>() const & Line | Count | Source | 129 | 1.41k | const T& Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { | 130 | 1.41k | ABSL_DCHECK(Is<T>()); | 131 | | | 132 | 1.41k | return *At<T>(); | 133 | 1.41k | } |
cel::CustomMapValue const& cel::common_internal::MapValueVariant::Get<cel::CustomMapValue>() const & Line | Count | Source | 129 | 14.0k | const T& Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { | 130 | 14.0k | ABSL_DCHECK(Is<T>()); | 131 | | | 132 | 14.0k | return *At<T>(); | 133 | 14.0k | } |
|
134 | | |
135 | | template <typename T> |
136 | 0 | T&& Get() && ABSL_ATTRIBUTE_LIFETIME_BOUND { |
137 | 0 | ABSL_DCHECK(Is<T>()); |
138 | |
|
139 | 0 | return std::move(*At<T>()); |
140 | 0 | } |
141 | | |
142 | | template <typename T> |
143 | | const T&& Get() const&& ABSL_ATTRIBUTE_LIFETIME_BOUND { |
144 | | ABSL_DCHECK(Is<T>()); |
145 | | |
146 | | return std::move(*At<T>()); |
147 | | } |
148 | | |
149 | | template <typename T> |
150 | 0 | T* absl_nullable As() ABSL_ATTRIBUTE_LIFETIME_BOUND { |
151 | 0 | if (Is<T>()) { |
152 | 0 | return At<T>(); |
153 | 0 | } |
154 | 0 | return nullptr; |
155 | 0 | } |
156 | | |
157 | | template <typename T> |
158 | 0 | const T* absl_nullable As() const ABSL_ATTRIBUTE_LIFETIME_BOUND { |
159 | 0 | if (Is<T>()) { |
160 | 0 | return At<T>(); |
161 | 0 | } |
162 | 0 | return nullptr; |
163 | 0 | } |
164 | | |
165 | | template <typename Visitor> |
166 | 15.5k | decltype(auto) Visit(Visitor&& visitor) const { |
167 | 15.5k | switch (index_) { |
168 | 14.0k | case MapValueIndex::kCustom: |
169 | 14.0k | return std::forward<Visitor>(visitor)(Get<CustomMapValue>()); |
170 | 0 | case MapValueIndex::kParsedField: |
171 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedMapFieldValue>()); |
172 | 0 | case MapValueIndex::kParsedJson: |
173 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedJsonMapValue>()); |
174 | 1.41k | case MapValueIndex::kLegacy: |
175 | 1.41k | return std::forward<Visitor>(visitor)(Get<LegacyMapValue>()); |
176 | 15.5k | } |
177 | 15.5k | } Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::GetTypeId() const::$_0>(cel::MapValue::GetTypeId() const::$_0&&) const Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::DebugString() const::$_0>(cel::MapValue::DebugString() const::$_0&&) const Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::SerializeTo(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::io::ZeroCopyOutputStream*) const::$_0>(cel::MapValue::SerializeTo(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::io::ZeroCopyOutputStream*) const::$_0&&) const Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::ConvertToJson(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Message*) const::$_0>(cel::MapValue::ConvertToJson(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Message*) const::$_0&&) const Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::ConvertToJsonObject(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Message*) const::$_0>(cel::MapValue::ConvertToJsonObject(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Message*) const::$_0&&) const Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0>(cel::MapValue::Equal(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0&&) const Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::IsZeroValue() const::$_0>(cel::MapValue::IsZeroValue() const::$_0&&) const Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::IsEmpty() const::$_0>(cel::MapValue::IsEmpty() const::$_0&&) const map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::Size() const::$_0>(cel::MapValue::Size() const::$_0&&) const Line | Count | Source | 166 | 111 | decltype(auto) Visit(Visitor&& visitor) const { | 167 | 111 | switch (index_) { | 168 | 110 | case MapValueIndex::kCustom: | 169 | 110 | return std::forward<Visitor>(visitor)(Get<CustomMapValue>()); | 170 | 0 | case MapValueIndex::kParsedField: | 171 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedMapFieldValue>()); | 172 | 0 | case MapValueIndex::kParsedJson: | 173 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedJsonMapValue>()); | 174 | 1 | case MapValueIndex::kLegacy: | 175 | 1 | return std::forward<Visitor>(visitor)(Get<LegacyMapValue>()); | 176 | 111 | } | 177 | 111 | } |
map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::Get(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0>(cel::MapValue::Get(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0&&) const Line | Count | Source | 166 | 2.41k | decltype(auto) Visit(Visitor&& visitor) const { | 167 | 2.41k | switch (index_) { | 168 | 1.98k | case MapValueIndex::kCustom: | 169 | 1.98k | return std::forward<Visitor>(visitor)(Get<CustomMapValue>()); | 170 | 0 | case MapValueIndex::kParsedField: | 171 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedMapFieldValue>()); | 172 | 0 | case MapValueIndex::kParsedJson: | 173 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedJsonMapValue>()); | 174 | 433 | case MapValueIndex::kLegacy: | 175 | 433 | return std::forward<Visitor>(visitor)(Get<LegacyMapValue>()); | 176 | 2.41k | } | 177 | 2.41k | } |
map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::Find(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0>(cel::MapValue::Find(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0&&) const Line | Count | Source | 166 | 3.54k | decltype(auto) Visit(Visitor&& visitor) const { | 167 | 3.54k | switch (index_) { | 168 | 3.38k | case MapValueIndex::kCustom: | 169 | 3.38k | return std::forward<Visitor>(visitor)(Get<CustomMapValue>()); | 170 | 0 | case MapValueIndex::kParsedField: | 171 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedMapFieldValue>()); | 172 | 0 | case MapValueIndex::kParsedJson: | 173 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedJsonMapValue>()); | 174 | 158 | case MapValueIndex::kLegacy: | 175 | 158 | return std::forward<Visitor>(visitor)(Get<LegacyMapValue>()); | 176 | 3.54k | } | 177 | 3.54k | } |
map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::Has(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0>(cel::MapValue::Has(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0&&) const Line | Count | Source | 166 | 583 | decltype(auto) Visit(Visitor&& visitor) const { | 167 | 583 | switch (index_) { | 168 | 435 | case MapValueIndex::kCustom: | 169 | 435 | return std::forward<Visitor>(visitor)(Get<CustomMapValue>()); | 170 | 0 | case MapValueIndex::kParsedField: | 171 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedMapFieldValue>()); | 172 | 0 | case MapValueIndex::kParsedJson: | 173 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedJsonMapValue>()); | 174 | 148 | case MapValueIndex::kLegacy: | 175 | 148 | return std::forward<Visitor>(visitor)(Get<LegacyMapValue>()); | 176 | 583 | } | 177 | 583 | } |
Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::ListKeys(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::ListValue*) const::$_0>(cel::MapValue::ListKeys(google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::ListValue*) const::$_0&&) const Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::ForEach(absl::lts_20260107::FunctionRef<absl::lts_20260107::StatusOr<bool> (cel::Value const&, cel::Value const&)>, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*) const::$_0>(cel::MapValue::ForEach(absl::lts_20260107::FunctionRef<absl::lts_20260107::StatusOr<bool> (cel::Value const&, cel::Value const&)>, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*) const::$_0&&) const map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::NewIterator() const::$_0>(cel::MapValue::NewIterator() const::$_0&&) const Line | Count | Source | 166 | 45 | decltype(auto) Visit(Visitor&& visitor) const { | 167 | 45 | switch (index_) { | 168 | 45 | case MapValueIndex::kCustom: | 169 | 45 | return std::forward<Visitor>(visitor)(Get<CustomMapValue>()); | 170 | 0 | case MapValueIndex::kParsedField: | 171 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedMapFieldValue>()); | 172 | 0 | case MapValueIndex::kParsedJson: | 173 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedJsonMapValue>()); | 174 | 0 | case MapValueIndex::kLegacy: | 175 | 0 | return std::forward<Visitor>(visitor)(Get<LegacyMapValue>()); | 176 | 45 | } | 177 | 45 | } |
Unexecuted instantiation: map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::ToValueVariant() const &::$_0>(cel::MapValue::ToValueVariant() const &::$_0&&) const map_value.cc:decltype(auto) cel::common_internal::MapValueVariant::Visit<cel::MapValue::ToValueVariant() &&::$_0>(cel::MapValue::ToValueVariant() &&::$_0&&) const Line | Count | Source | 166 | 8.80k | decltype(auto) Visit(Visitor&& visitor) const { | 167 | 8.80k | switch (index_) { | 168 | 8.13k | case MapValueIndex::kCustom: | 169 | 8.13k | return std::forward<Visitor>(visitor)(Get<CustomMapValue>()); | 170 | 0 | case MapValueIndex::kParsedField: | 171 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedMapFieldValue>()); | 172 | 0 | case MapValueIndex::kParsedJson: | 173 | 0 | return std::forward<Visitor>(visitor)(Get<ParsedJsonMapValue>()); | 174 | 677 | case MapValueIndex::kLegacy: | 175 | 677 | return std::forward<Visitor>(visitor)(Get<LegacyMapValue>()); | 176 | 8.80k | } | 177 | 8.80k | } |
|
178 | | |
179 | 0 | friend void swap(MapValueVariant& lhs, MapValueVariant& rhs) noexcept { |
180 | 0 | using std::swap; |
181 | 0 | swap(lhs.index_, rhs.index_); |
182 | 0 | swap(lhs.raw_, rhs.raw_); |
183 | 0 | } |
184 | | |
185 | | private: |
186 | | template <typename T> |
187 | | ABSL_ATTRIBUTE_ALWAYS_INLINE T* absl_nonnull At() |
188 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
189 | 0 | static_assert(alignof(T) <= kMapValueVariantAlign); |
190 | 0 | static_assert(sizeof(T) <= kMapValueVariantSize); |
191 | 0 | static_assert(std::is_trivially_copyable_v<T>); |
192 | |
|
193 | 0 | return std::launder(reinterpret_cast<T*>(&raw_[0])); |
194 | 0 | } |
195 | | |
196 | | template <typename T> |
197 | | ABSL_ATTRIBUTE_ALWAYS_INLINE const T* absl_nonnull At() const |
198 | 15.5k | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
199 | 15.5k | static_assert(alignof(T) <= kMapValueVariantAlign); |
200 | 15.5k | static_assert(sizeof(T) <= kMapValueVariantSize); |
201 | 15.5k | static_assert(std::is_trivially_copyable_v<T>); |
202 | | |
203 | 15.5k | return std::launder(reinterpret_cast<const T*>(&raw_[0])); |
204 | 15.5k | } Unexecuted instantiation: cel::ParsedMapFieldValue const* cel::common_internal::MapValueVariant::At<cel::ParsedMapFieldValue>() const Unexecuted instantiation: cel::ParsedJsonMapValue const* cel::common_internal::MapValueVariant::At<cel::ParsedJsonMapValue>() const cel::common_internal::LegacyMapValue const* cel::common_internal::MapValueVariant::At<cel::common_internal::LegacyMapValue>() const Line | Count | Source | 198 | 1.41k | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 199 | 1.41k | static_assert(alignof(T) <= kMapValueVariantAlign); | 200 | 1.41k | static_assert(sizeof(T) <= kMapValueVariantSize); | 201 | 1.41k | static_assert(std::is_trivially_copyable_v<T>); | 202 | | | 203 | 1.41k | return std::launder(reinterpret_cast<const T*>(&raw_[0])); | 204 | 1.41k | } |
cel::CustomMapValue const* cel::common_internal::MapValueVariant::At<cel::CustomMapValue>() const Line | Count | Source | 198 | 14.0k | ABSL_ATTRIBUTE_LIFETIME_BOUND { | 199 | 14.0k | static_assert(alignof(T) <= kMapValueVariantAlign); | 200 | 14.0k | static_assert(sizeof(T) <= kMapValueVariantSize); | 201 | 14.0k | static_assert(std::is_trivially_copyable_v<T>); | 202 | | | 203 | 14.0k | return std::launder(reinterpret_cast<const T*>(&raw_[0])); | 204 | 14.0k | } |
|
205 | | |
206 | | MapValueIndex index_ = MapValueIndex::kCustom; |
207 | | alignas(8) std::byte raw_[kMapValueVariantSize]; |
208 | | }; |
209 | | |
210 | | } // namespace cel::common_internal |
211 | | |
212 | | #endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_MAP_VALUE_VARIANT_H_ |