Blender V4.3
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
5#pragma once
6
8#include "BLI_span.hh"
9
10namespace blender {
11
17template<typename T, typename BaseT> class OffsetSpan {
18 private:
20 T offset_ = 0;
22 Span<BaseT> data_;
23
24 public:
25 OffsetSpan() = default;
26 OffsetSpan(const T offset, const Span<BaseT> data) : offset_(offset), data_(data) {}
27
30 {
31 return data_;
32 }
33
34 T offset() const
35 {
36 return offset_;
37 }
38
39 bool is_empty() const
40 {
41 return data_.is_empty();
42 }
43
44 int64_t size() const
45 {
46 return data_.size();
47 }
48
49 T last(const int64_t n = 0) const
50 {
51 return offset_ + data_.last(n);
52 }
53
55 {
56 return data_.index_range();
57 }
58
59 T operator[](const int64_t i) const
60 {
61 return T(data_[i]) + offset_;
62 }
63
64 OffsetSpan slice(const IndexRange &range) const
65 {
66 return {offset_, data_.slice(range)};
67 }
68
69 OffsetSpan slice(const int64_t start, const int64_t size) const
70 {
71 return {offset_, data_.slice(start, size)};
72 }
73
75 public:
76 using value_type = T;
77 using pointer = const T *;
78 using reference = T;
79
80 private:
81 T offset_;
82 const BaseT *data_;
83
84 public:
85 Iterator(const T offset, const BaseT *data) : offset_(offset), data_(data) {}
86
87 T operator*() const
88 {
89 return T(*data_) + offset_;
90 }
91
92 const BaseT *const &iter_prop() const
93 {
94 return data_;
95 }
96 };
97
99 {
100 return {offset_, data_.begin()};
101 }
102
103 Iterator end() const
104 {
105 return {offset_, data_.end()};
106 }
107};
108
109} // namespace blender
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:138
constexpr int64_t size() const
Definition BLI_span.hh:253
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:326
constexpr const T * end() const
Definition BLI_span.hh:225
constexpr IndexRange index_range() const
Definition BLI_span.hh:402
constexpr const T * begin() const
Definition BLI_span.hh:221
constexpr bool is_empty() const
Definition BLI_span.hh:261
#define T
__int64 int64_t
Definition stdint.h:89