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/double_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_DOUBLE_VALUE_H_
19
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_DOUBLE_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 DoubleValue;
39
40
class DoubleValue final : private common_internal::ValueMixin<DoubleValue> {
41
 public:
42
  static constexpr ValueKind kKind = ValueKind::kDouble;
43
44
17.0k
  explicit DoubleValue(double value) noexcept : value_(value) {}
45
46
  DoubleValue() = default;
47
  DoubleValue(const DoubleValue&) = default;
48
  DoubleValue(DoubleValue&&) = default;
49
  DoubleValue& operator=(const DoubleValue&) = default;
50
  DoubleValue& operator=(DoubleValue&&) = default;
51
52
0
  ValueKind kind() const { return kKind; }
53
54
0
  absl::string_view GetTypeName() const { return DoubleType::kName; }
55
56
  std::string DebugString() const;
57
58
  // See Value::SerializeTo().
59
  absl::Status SerializeTo(
60
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
61
      google::protobuf::MessageFactory* absl_nonnull message_factory,
62
      google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const;
63
64
  // See Value::ConvertToJson().
65
  absl::Status ConvertToJson(
66
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
67
      google::protobuf::MessageFactory* absl_nonnull message_factory,
68
      google::protobuf::Message* absl_nonnull json) const;
69
70
  absl::Status Equal(const Value& other,
71
                     const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
72
                     google::protobuf::MessageFactory* absl_nonnull message_factory,
73
                     google::protobuf::Arena* absl_nonnull arena,
74
                     Value* absl_nonnull result) const;
75
  using ValueMixin::Equal;
76
77
0
  bool IsZeroValue() const { return NativeValue() == 0.0; }
78
79
18.2k
  double NativeValue() const { return static_cast<double>(*this); }
80
81
  // NOLINTNEXTLINE(google-explicit-constructor)
82
18.2k
  operator double() const noexcept { return value_; }
83
84
0
  friend void swap(DoubleValue& lhs, DoubleValue& rhs) noexcept {
85
0
    using std::swap;
86
0
    swap(lhs.value_, rhs.value_);
87
0
  }
88
89
 private:
90
  friend class common_internal::ValueMixin<DoubleValue>;
91
92
  double value_ = 0.0;
93
};
94
95
0
inline std::ostream& operator<<(std::ostream& out, DoubleValue value) {
96
0
  return out << value.DebugString();
97
0
}
98
99
}  // namespace cel
100
101
#endif  // THIRD_PARTY_CEL_CPP_COMMON_VALUES_DOUBLE_VALUE_H_