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/null_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/value.h"
16
// IWYU pragma: friend "common/value.h"
17
18
#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_NULL_VALUE_H_
19
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_NULL_VALUE_H_
20
21
#include <ostream>
22
#include <string>
23
24
#include "absl/base/nullability.h"
25
#include "absl/status/status.h"
26
#include "absl/strings/string_view.h"
27
#include "common/type.h"
28
#include "common/value_kind.h"
29
#include "common/values/values.h"
30
#include "google/protobuf/arena.h"
31
#include "google/protobuf/descriptor.h"
32
#include "google/protobuf/io/zero_copy_stream.h"
33
#include "google/protobuf/message.h"
34
35
namespace cel {
36
37
class Value;
38
class NullValue;
39
40
// `NullValue` represents the CEL `null` value.
41
class NullValue final : private common_internal::ValueMixin<NullValue> {
42
 public:
43
  static constexpr ValueKind kKind = ValueKind::kNull;
44
45
  NullValue() = default;
46
  NullValue(const NullValue&) = default;
47
  NullValue(NullValue&&) = default;
48
  NullValue& operator=(const NullValue&) = default;
49
  NullValue& operator=(NullValue&&) = default;
50
51
0
  constexpr ValueKind kind() const { return kKind; }
52
53
0
  absl::string_view GetTypeName() const { return NullType::kName; }
54
55
0
  std::string DebugString() const { return "null"; }
56
57
  // See Value::SerializeTo().
58
  absl::Status SerializeTo(
59
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
60
      google::protobuf::MessageFactory* absl_nonnull message_factory,
61
      google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const;
62
63
  // See Value::ConvertToJson().
64
  absl::Status ConvertToJson(
65
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
66
      google::protobuf::MessageFactory* absl_nonnull message_factory,
67
      google::protobuf::Message* absl_nonnull json) const;
68
69
  absl::Status Equal(const Value& other,
70
                     const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
71
                     google::protobuf::MessageFactory* absl_nonnull message_factory,
72
                     google::protobuf::Arena* absl_nonnull arena,
73
                     Value* absl_nonnull result) const;
74
  using ValueMixin::Equal;
75
76
0
  bool IsZeroValue() const { return true; }
77
78
0
  friend void swap(NullValue&, NullValue&) noexcept {}
79
80
 private:
81
  friend class common_internal::ValueMixin<NullValue>;
82
};
83
84
0
inline bool operator==(NullValue, NullValue) { return true; }
85
86
0
inline bool operator!=(NullValue lhs, NullValue rhs) {
87
0
  return !operator==(lhs, rhs);
88
0
}
89
90
0
inline std::ostream& operator<<(std::ostream& out, const NullValue& value) {
91
0
  return out << value.DebugString();
92
0
}
93
94
}  // namespace cel
95
96
#endif  // THIRD_PARTY_CEL_CPP_COMMON_VALUES_NULL_VALUE_H_