Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/base/attribute_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_ATTRIBUTE_SET_H_
16
#define THIRD_PARTY_CEL_CPP_BASE_ATTRIBUTE_SET_H_
17
18
#include "absl/container/btree_set.h"
19
#include "absl/types/span.h"
20
#include "base/attribute.h"
21
22
namespace google::api::expr::runtime {
23
class AttributeUtility;
24
}  // namespace google::api::expr::runtime
25
26
namespace cel {
27
28
class UnknownValue;
29
namespace base_internal {
30
class UnknownSet;
31
}
32
33
// AttributeSet is a container for CEL attributes that are identified as
34
// unknown during expression evaluation.
35
class AttributeSet final {
36
 private:
37
  using Container = absl::btree_set<Attribute>;
38
39
 public:
40
  using value_type = typename Container::value_type;
41
  using size_type = typename Container::size_type;
42
  using iterator = typename Container::const_iterator;
43
  using const_iterator = typename Container::const_iterator;
44
45
0
  AttributeSet() = default;
46
0
  AttributeSet(const AttributeSet&) = default;
47
0
  AttributeSet(AttributeSet&&) = default;
48
  AttributeSet& operator=(const AttributeSet&) = default;
49
  AttributeSet& operator=(AttributeSet&&) = default;
50
51
0
  explicit AttributeSet(absl::Span<const Attribute> attributes) {
52
0
    for (const auto& attr : attributes) {
53
0
      Add(attr);
54
0
    }
55
0
  }
56
57
  AttributeSet(const AttributeSet& set1, const AttributeSet& set2)
58
0
      : attributes_(set1.attributes_) {
59
0
    for (const auto& attr : set2.attributes_) {
60
0
      Add(attr);
61
0
    }
62
0
  }
63
64
0
  iterator begin() const { return attributes_.begin(); }
65
66
0
  const_iterator cbegin() const { return attributes_.cbegin(); }
67
68
0
  iterator end() const { return attributes_.end(); }
69
70
0
  const_iterator cend() const { return attributes_.cend(); }
71
72
0
  size_type size() const { return attributes_.size(); }
73
74
0
  bool empty() const { return attributes_.empty(); }
75
76
0
  bool operator==(const AttributeSet& other) const {
77
0
    return this == &other || attributes_ == other.attributes_;
78
0
  }
79
80
0
  bool operator!=(const AttributeSet& other) const {
81
0
    return !operator==(other);
82
0
  }
83
84
  static AttributeSet Merge(const AttributeSet& set1,
85
0
                            const AttributeSet& set2) {
86
0
    return AttributeSet(set1, set2);
87
0
  }
88
89
 private:
90
  friend class google::api::expr::runtime::AttributeUtility;
91
  friend class UnknownValue;
92
  friend class base_internal::UnknownSet;
93
94
0
  void Add(const Attribute& attribute) { attributes_.insert(attribute); }
95
96
0
  void Add(const AttributeSet& other) {
97
0
    for (const auto& attribute : other) {
98
0
      Add(attribute);
99
0
    }
100
0
  }
101
102
  // Attribute container.
103
  Container attributes_;
104
};
105
106
}  // namespace cel
107
108
#endif  // THIRD_PARTY_CEL_CPP_BASE_ATTRIBUTE_SET_H_