Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/base/function_result_set.h
Line
Count
Source
1
// Copyright 2022 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
#ifndef THIRD_PARTY_CEL_CPP_BASE_FUNCTION_RESULT_SET_H_
16
#define THIRD_PARTY_CEL_CPP_BASE_FUNCTION_RESULT_SET_H_
17
18
#include <initializer_list>
19
#include <utility>
20
21
#include "absl/container/btree_set.h"
22
#include "base/function_result.h"
23
24
namespace google::api::expr::runtime {
25
class AttributeUtility;
26
}  // namespace google::api::expr::runtime
27
28
namespace cel {
29
30
class UnknownValue;
31
namespace base_internal {
32
class UnknownSet;
33
}
34
35
// Represents a collection of unknown function results at a particular point in
36
// execution. Execution should advance further if this set of unknowns are
37
// provided. It may not advance if only a subset are provided.
38
// Set semantics use |IsEqualTo()| defined on |FunctionResult|.
39
class FunctionResultSet final {
40
 private:
41
  using Container = absl::btree_set<FunctionResult>;
42
43
 public:
44
  using value_type = typename Container::value_type;
45
  using size_type = typename Container::size_type;
46
  using iterator = typename Container::const_iterator;
47
  using const_iterator = typename Container::const_iterator;
48
49
0
  FunctionResultSet() = default;
50
0
  FunctionResultSet(const FunctionResultSet&) = default;
51
0
  FunctionResultSet(FunctionResultSet&&) = default;
52
  FunctionResultSet& operator=(const FunctionResultSet&) = default;
53
  FunctionResultSet& operator=(FunctionResultSet&&) = default;
54
55
  // Merge constructor -- effectively union(lhs, rhs).
56
  FunctionResultSet(const FunctionResultSet& lhs, const FunctionResultSet& rhs);
57
58
  // Initialize with a single FunctionResult.
59
  explicit FunctionResultSet(FunctionResult initial)
60
0
      : function_results_{std::move(initial)} {}
61
62
  FunctionResultSet(std::initializer_list<FunctionResult> il)
63
0
      : function_results_(il) {}
64
65
0
  iterator begin() const { return function_results_.begin(); }
66
67
0
  const_iterator cbegin() const { return function_results_.cbegin(); }
68
69
0
  iterator end() const { return function_results_.end(); }
70
71
0
  const_iterator cend() const { return function_results_.cend(); }
72
73
0
  size_type size() const { return function_results_.size(); }
74
75
0
  bool empty() const { return function_results_.empty(); }
76
77
0
  bool operator==(const FunctionResultSet& other) const {
78
0
    return this == &other || function_results_ == other.function_results_;
79
0
  }
80
81
0
  bool operator!=(const FunctionResultSet& other) const {
82
0
    return !operator==(other);
83
0
  }
84
85
 private:
86
  friend class google::api::expr::runtime::AttributeUtility;
87
  friend class UnknownValue;
88
  friend class base_internal::UnknownSet;
89
90
0
  void Add(const FunctionResult& function_result) {
91
0
    function_results_.insert(function_result);
92
0
  }
93
94
0
  void Add(const FunctionResultSet& other) {
95
0
    for (const auto& function_result : other) {
96
0
      Add(function_result);
97
0
    }
98
0
  }
99
100
  Container function_results_;
101
};
102
103
}  // namespace cel
104
105
#endif  // THIRD_PARTY_CEL_CPP_BASE_FUNCTION_RESULT_SET_H_