Coverage Report

Created: 2026-07-11 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/eval/eval/iterator_stack.h
Line
Count
Source
1
// Copyright 2025 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_EVAL_EVAL_ITERATOR_STACK_H_
16
#define THIRD_PARTY_CEL_CPP_EVAL_EVAL_ITERATOR_STACK_H_
17
18
#include <cstddef>
19
#include <utility>
20
#include <vector>
21
22
#include "absl/base/nullability.h"
23
#include "absl/log/absl_check.h"
24
#include "common/value.h"
25
26
namespace cel::runtime_internal {
27
28
class IteratorStack final {
29
 public:
30
10.3k
  explicit IteratorStack(size_t max_size) : max_size_(max_size) {
31
10.3k
    iterators_.reserve(max_size_);
32
10.3k
  }
33
34
  IteratorStack(const IteratorStack&) = delete;
35
  IteratorStack(IteratorStack&&) = delete;
36
37
  IteratorStack& operator=(const IteratorStack&) = delete;
38
  IteratorStack& operator=(IteratorStack&&) = delete;
39
40
0
  size_t size() const { return iterators_.size(); }
41
42
0
  bool empty() const { return iterators_.empty(); }
43
44
0
  bool full() const { return iterators_.size() == max_size_; }
45
46
0
  size_t max_size() const { return max_size_; }
47
48
20.7k
  void Clear() { iterators_.clear(); }
49
50
53.8k
  void Push(absl_nonnull ValueIteratorPtr iterator) {
51
53.8k
    ABSL_DCHECK(!full());
52
53.8k
    ABSL_DCHECK(iterator != nullptr);
53
54
53.8k
    iterators_.push_back(std::move(iterator));
55
53.8k
  }
56
57
554k
  ValueIterator* absl_nonnull Peek() {
58
554k
    ABSL_DCHECK(!empty());
59
554k
    ABSL_DCHECK(iterators_.back() != nullptr);
60
61
554k
    return iterators_.back().get();
62
554k
  }
63
64
53.7k
  void Pop() {
65
53.7k
    ABSL_DCHECK(!empty());
66
67
53.7k
    iterators_.pop_back();
68
53.7k
  }
69
70
 private:
71
  std::vector<absl_nonnull ValueIteratorPtr> iterators_;
72
  size_t max_size_;
73
};
74
75
}  // namespace cel::runtime_internal
76
77
#endif  // THIRD_PARTY_CEL_CPP_EVAL_EVAL_ITERATOR_STACK_H_