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/uint_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_UINT_VALUE_H_
19
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_UINT_VALUE_H_
20
21
#include <cstdint>
22
#include <ostream>
23
#include <string>
24
25
#include "absl/base/nullability.h"
26
#include "absl/status/status.h"
27
#include "absl/strings/cord.h"
28
#include "absl/strings/string_view.h"
29
#include "common/type.h"
30
#include "common/value_kind.h"
31
#include "common/values/values.h"
32
#include "google/protobuf/arena.h"
33
#include "google/protobuf/descriptor.h"
34
#include "google/protobuf/io/zero_copy_stream.h"
35
#include "google/protobuf/message.h"
36
37
namespace cel {
38
39
class Value;
40
class UintValue;
41
42
// `UintValue` represents values of the primitive `uint` type.
43
class UintValue final : private common_internal::ValueMixin<UintValue> {
44
 public:
45
  static constexpr ValueKind kKind = ValueKind::kUint;
46
47
19.6k
  explicit UintValue(uint64_t value) noexcept : value_(value) {}
48
49
  UintValue() = default;
50
  UintValue(const UintValue&) = default;
51
  UintValue(UintValue&&) = default;
52
  UintValue& operator=(const UintValue&) = default;
53
  UintValue& operator=(UintValue&&) = default;
54
55
0
  constexpr ValueKind kind() const { return kKind; }
56
57
0
  absl::string_view GetTypeName() const { return UintType::kName; }
58
59
  std::string DebugString() const;
60
61
  // See Value::SerializeTo().
62
  absl::Status SerializeTo(
63
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
64
      google::protobuf::MessageFactory* absl_nonnull message_factory,
65
      google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const;
66
67
  // See Value::ConvertToJson().
68
  absl::Status ConvertToJson(
69
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
70
      google::protobuf::MessageFactory* absl_nonnull message_factory,
71
      google::protobuf::Message* absl_nonnull json) const;
72
73
  absl::Status Equal(const Value& other,
74
                     const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
75
                     google::protobuf::MessageFactory* absl_nonnull message_factory,
76
                     google::protobuf::Arena* absl_nonnull arena,
77
                     Value* absl_nonnull result) const;
78
  using ValueMixin::Equal;
79
80
0
  bool IsZeroValue() const { return NativeValue() == 0; }
81
82
17.0k
  constexpr uint64_t NativeValue() const {
83
17.0k
    return static_cast<uint64_t>(*this);
84
17.0k
  }
85
86
  // NOLINTNEXTLINE(google-explicit-constructor)
87
17.0k
  constexpr operator uint64_t() const noexcept { return value_; }
88
89
0
  friend void swap(UintValue& lhs, UintValue& rhs) noexcept {
90
0
    using std::swap;
91
0
    swap(lhs.value_, rhs.value_);
92
0
  }
93
94
 private:
95
  friend class common_internal::ValueMixin<UintValue>;
96
97
  uint64_t value_ = 0;
98
};
99
100
template <typename H>
101
H AbslHashValue(H state, UintValue value) {
102
  return H::combine(std::move(state), value.NativeValue());
103
}
104
105
3
constexpr bool operator==(UintValue lhs, UintValue rhs) {
106
3
  return lhs.NativeValue() == rhs.NativeValue();
107
3
}
108
109
0
constexpr bool operator!=(UintValue lhs, UintValue rhs) {
110
0
  return !operator==(lhs, rhs);
111
0
}
112
113
0
inline std::ostream& operator<<(std::ostream& out, UintValue value) {
114
0
  return out << value.DebugString();
115
0
}
116
117
}  // namespace cel
118
119
#endif  // THIRD_PARTY_CEL_CPP_COMMON_VALUES_UINT_VALUE_H_