Coverage Report

Created: 2026-10-09 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/values/unknown_value.h
Line
Count
Source
1
// Copyright 2024 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_UNKNOWN_VALUE_H_
19
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_UNKNOWN_VALUE_H_
20
21
#include <ostream>
22
#include <string>
23
#include <utility>
24
25
#include "absl/base/attributes.h"
26
#include "absl/base/nullability.h"
27
#include "absl/status/status.h"
28
#include "absl/strings/string_view.h"
29
#include "common/type.h"
30
#include "common/unknown.h"
31
#include "common/value_kind.h"
32
#include "common/values/values.h"
33
#include "google/protobuf/arena.h"
34
#include "google/protobuf/descriptor.h"
35
#include "google/protobuf/io/zero_copy_stream.h"
36
#include "google/protobuf/message.h"
37
38
namespace cel {
39
40
class Value;
41
class UnknownValue;
42
43
namespace common_internal {
44
[[nodiscard]]
45
UnknownValue MakeUnknownValue(Unknown value);
46
[[nodiscard]]
47
Unknown GetUnknown(const UnknownValue& value);
48
[[nodiscard]]
49
const FunctionResultSet& GetUnknownFunctionResultSet(
50
    const UnknownValue& value ABSL_ATTRIBUTE_LIFETIME_BOUND);
51
}  // namespace common_internal
52
53
// `UnknownValue` represents values of the primitive `duration` type.
54
class UnknownValue final : private common_internal::ValueMixin<UnknownValue> {
55
 public:
56
  static constexpr ValueKind kKind = ValueKind::kUnknown;
57
58
  UnknownValue() = default;
59
0
  UnknownValue(const UnknownValue&) = default;
60
0
  UnknownValue(UnknownValue&&) = default;
61
  UnknownValue& operator=(const UnknownValue&) = default;
62
0
  UnknownValue& operator=(UnknownValue&&) = default;
63
64
0
  constexpr ValueKind kind() const { return kKind; }
65
66
0
  absl::string_view GetTypeName() const { return UnknownType::kName; }
67
68
0
  std::string DebugString() const { return ""; }
69
70
  // See Value::SerializeTo().
71
  absl::Status SerializeTo(
72
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
73
      google::protobuf::MessageFactory* absl_nonnull message_factory,
74
      google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const;
75
76
  // See Value::ConvertToJson().
77
  absl::Status ConvertToJson(
78
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
79
      google::protobuf::MessageFactory* absl_nonnull message_factory,
80
      google::protobuf::Message* absl_nonnull json) const;
81
82
  absl::Status Equal(const Value& other,
83
                     const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
84
                     google::protobuf::MessageFactory* absl_nonnull message_factory,
85
                     google::protobuf::Arena* absl_nonnull arena,
86
                     Value* absl_nonnull result) const;
87
  using ValueMixin::Equal;
88
89
0
  bool IsZeroValue() const { return false; }
90
91
  [[nodiscard]]
92
0
  AttributeSet ToAttributeSet() const {
93
0
    return unknown_.unknown_attributes();
94
0
  }
95
96
0
  void swap(UnknownValue& other) noexcept {
97
0
    using std::swap;
98
0
    swap(unknown_, other.unknown_);
99
0
  }
100
101
 private:
102
  friend UnknownValue common_internal::MakeUnknownValue(Unknown value);
103
  friend Unknown common_internal::GetUnknown(const UnknownValue&);
104
  friend const FunctionResultSet& common_internal::GetUnknownFunctionResultSet(
105
      const UnknownValue& value);
106
  friend class common_internal::ValueMixin<UnknownValue>;
107
108
0
  explicit UnknownValue(Unknown unknown) : unknown_(std::move(unknown)) {}
109
110
  Unknown unknown_;
111
};
112
113
0
inline void swap(UnknownValue& lhs, UnknownValue& rhs) noexcept {
114
0
  lhs.swap(rhs);
115
0
}
116
117
0
inline std::ostream& operator<<(std::ostream& out, const UnknownValue& value) {
118
0
  return out << value.DebugString();
119
0
}
120
121
namespace common_internal {
122
123
[[nodiscard]]
124
0
inline UnknownValue MakeUnknownValue(Unknown value) {
125
0
  return UnknownValue(std::move(value));
126
0
}
127
128
[[nodiscard]]
129
0
inline Unknown GetUnknown(const UnknownValue& value) {
130
0
  return value.unknown_;
131
0
}
132
133
[[nodiscard]]
134
inline const FunctionResultSet& GetUnknownFunctionResultSet(
135
0
    const UnknownValue& value ABSL_ATTRIBUTE_LIFETIME_BOUND) {
136
0
  return value.unknown_.unknown_function_results();
137
0
}
138
139
}  // namespace common_internal
140
141
}  // namespace cel
142
143
#endif  // THIRD_PARTY_CEL_CPP_COMMON_VALUES_UNKNOWN_VALUE_H_