Blender V4.5
BLI_offset_span.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
12#include "BLI_span.hh"
13
14namespace blender {
15
21template<typename T, typename BaseT> class OffsetSpan {
22 private:
24 T offset_ = 0;
26 Span<BaseT> data_;
27
28 public:
29 OffsetSpan() = default;
30 OffsetSpan(const T offset, const Span<BaseT> data) : offset_(offset), data_(data) {}
31
34 {
35 return data_;
36 }
37
38 T offset() const
39 {
40 return offset_;
41 }
42
43 bool is_empty() const
44 {
45 return data_.is_empty();
46 }
47
48 int64_t size() const
49 {
50 return data_.size();
51 }
52
53 T last(const int64_t n = 0) const
54 {
55 return offset_ + data_.last(n);
56 }
57
59 {
60 return data_.index_range();
61 }
62
63 T operator[](const int64_t i) const
64 {
65 return T(data_[i]) + offset_;
66 }
67
69 {
70 return {offset_, data_.slice(range)};
71 }
72
73 OffsetSpan slice(const int64_t start, const int64_t size) const
74 {
75 return {offset_, data_.slice(start, size)};
76 }
77
79 public:
80 using value_type = T;
81 using pointer = const T *;
82 using reference = T;
83
84 private:
85 T offset_;
86 const BaseT *data_;
87
88 public:
89 Iterator(const T offset, const BaseT *data) : offset_(offset), data_(data) {}
90
91 T operator*() const
92 {
93 return T(*data_) + offset_;
94 }
95
96 const BaseT *const &iter_prop() const
97 {
98 return data_;
99 }
100 };
101
103 {
104 return {offset_, data_.begin()};
105 }
106
107 Iterator end() const
108 {
109 return {offset_, data_.end()};
110 }
111};
112
113} // namespace blender
std::string data
Iterator(const T offset, const BaseT *data)
const BaseT *const & iter_prop() const
Iterator begin() const
int64_t size() const
OffsetSpan(const T offset, const Span< BaseT > data)
Iterator end() const
OffsetSpan slice(const int64_t start, const int64_t size) const
IndexRange index_range() const
T last(const int64_t n=0) const
OffsetSpan slice(const IndexRange &range) const
Span< BaseT > base_span() const
T operator[](const int64_t i) const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:137
constexpr int64_t size() const
Definition BLI_span.hh:252
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:325
constexpr const T * end() const
Definition BLI_span.hh:224
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
constexpr const T * begin() const
Definition BLI_span.hh:220
constexpr bool is_empty() const
Definition BLI_span.hh:260
IndexRange range
#define T
__int64 int64_t
Definition stdint.h:89