Changeset View
Changeset View
Standalone View
Standalone View
source/blender/functions/FN_generic_span.hh
| Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | public: | ||||
| GSpan slice(const int64_t start, int64_t size) const | GSpan slice(const int64_t start, int64_t size) const | ||||
| { | { | ||||
| BLI_assert(start >= 0); | BLI_assert(start >= 0); | ||||
| BLI_assert(size >= 0); | BLI_assert(size >= 0); | ||||
| const int64_t new_size = std::max<int64_t>(0, std::min(size, size_ - start)); | const int64_t new_size = std::max<int64_t>(0, std::min(size, size_ - start)); | ||||
| return GSpan(*type_, POINTER_OFFSET(data_, type_->size() * start), new_size); | return GSpan(*type_, POINTER_OFFSET(data_, type_->size() * start), new_size); | ||||
| } | } | ||||
| GSpan slice(const IndexRange range) const | |||||
| { | |||||
| return this->slice(range.start(), range.size()); | |||||
| } | |||||
| }; | }; | ||||
| /** | /** | ||||
| * A generic mutable span. It behaves just like a blender::MutableSpan<T>, but the type is only | * A generic mutable span. It behaves just like a blender::MutableSpan<T>, but the type is only | ||||
| * known at run-time. | * known at run-time. | ||||
| */ | */ | ||||
| class GMutableSpan { | class GMutableSpan { | ||||
| protected: | protected: | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | public: | ||||
| GMutableSpan slice(const int64_t start, int64_t size) const | GMutableSpan slice(const int64_t start, int64_t size) const | ||||
| { | { | ||||
| BLI_assert(start >= 0); | BLI_assert(start >= 0); | ||||
| BLI_assert(size >= 0); | BLI_assert(size >= 0); | ||||
| const int64_t new_size = std::max<int64_t>(0, std::min(size, size_ - start)); | const int64_t new_size = std::max<int64_t>(0, std::min(size, size_ - start)); | ||||
| return GMutableSpan(*type_, POINTER_OFFSET(data_, type_->size() * start), new_size); | return GMutableSpan(*type_, POINTER_OFFSET(data_, type_->size() * start), new_size); | ||||
| } | } | ||||
| GMutableSpan slice(IndexRange range) const | |||||
| { | |||||
| return this->slice(range.start(), range.size()); | |||||
| } | |||||
| }; | }; | ||||
| } // namespace blender::fn | } // namespace blender::fn | ||||