C/C++ API Reference
Loading...
Searching...
No Matches
chunks.h
1// Copyright 2025 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// 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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <type_traits>
17
18#include "pw_multibuf/v2/internal/chunk_iterator.h"
19
20namespace pw::multibuf::v2 {
21
22// Forward declarations.
23namespace test {
24class IteratorTest;
25} // namespace test
26
27namespace internal {
28
44template <Mutability kMutability>
46 private:
48
49 public:
50 using size_type = Deque::size_type;
51 using value_type = Deque::value_type;
52 using difference_type = Deque::difference_type;
55
56 constexpr ChunksImpl() = default;
57
58 constexpr size_type size() const {
59 return static_cast<size_type>(std::distance(begin_, end_));
60 }
61
62 constexpr iterator begin() { return begin_; }
63 constexpr const_iterator begin() const { return begin_; }
64 constexpr const_iterator cbegin() const { return begin_; }
65
66 constexpr iterator end() { return end_; }
67 constexpr const_iterator end() const { return end_; }
68 constexpr const_iterator cend() const { return end_; }
69
70 private:
71 friend class GenericMultiBuf;
72
73 // For unit testing.
74 friend class test::IteratorTest;
75
76 constexpr ChunksImpl(const Deque& deque, size_type entries_per_chunk) {
77 begin_.deque_ = &deque;
78 begin_.entries_per_chunk_ = entries_per_chunk;
79 end_.deque_ = &deque;
80 end_.entries_per_chunk_ = entries_per_chunk;
81 end_.chunk_ = deque.size() / entries_per_chunk;
82 }
83
84 iterator begin_;
85 iterator end_;
86};
87
88} // namespace internal
89
92
93} // namespace pw::multibuf::v2
Definition: dynamic_deque.h:60
constexpr size_type size() const noexcept
Returns the number of elements in the deque.
Definition: generic_deque.h:69
Definition: chunk_iterator.h:45