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/int_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_INT_VALUE_H_
19
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_INT_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 IntValue;
41
42
// `IntValue` represents values of the primitive `int` type.
43
class IntValue final : private common_internal::ValueMixin<IntValue> {
44
 public:
45
  static constexpr ValueKind kKind = ValueKind::kInt;
46
47
91.7k
  explicit IntValue(int64_t value) noexcept : value_(value) {}
48
49
  IntValue() = default;
50
  IntValue(const IntValue&) = default;
51
  IntValue(IntValue&&) = default;
52
  IntValue& operator=(const IntValue&) = default;
53
  IntValue& operator=(IntValue&&) = default;
54
55
0
  ValueKind kind() const { return kKind; }
56
57
0
  absl::string_view GetTypeName() const { return IntType::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
40.3k
  int64_t NativeValue() const { return static_cast<int64_t>(*this); }
83
84
  // NOLINTNEXTLINE(google-explicit-constructor)
85
41.9k
  operator int64_t() const noexcept { return value_; }
86
87
0
  friend void swap(IntValue& lhs, IntValue& rhs) noexcept {
88
0
    using std::swap;
89
0
    swap(lhs.value_, rhs.value_);
90
0
  }
91
92
 private:
93
  friend class common_internal::ValueMixin<IntValue>;
94
95
  int64_t value_ = 0;
96
};
97
98
template <typename H>
99
H AbslHashValue(H state, IntValue value) {
100
  return H::combine(std::move(state), value.NativeValue());
101
}
102
103
132
inline bool operator==(IntValue lhs, IntValue rhs) {
104
132
  return lhs.NativeValue() == rhs.NativeValue();
105
132
}
106
107
0
inline bool operator!=(IntValue lhs, IntValue rhs) {
108
0
  return !operator==(lhs, rhs);
109
0
}
110
111
0
inline std::ostream& operator<<(std::ostream& out, IntValue value) {
112
0
  return out << value.DebugString();
113
0
}
114
115
}  // namespace cel
116
117
#endif  // THIRD_PARTY_CEL_CPP_COMMON_VALUES_INT_VALUE_H_