diff options
author | Jacques Lucke <jacques@blender.org> | 2022-07-07 20:19:01 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-07-07 20:19:18 +0300 |
commit | ba62e20af67e1de25f781456df7175fa1b31db67 (patch) | |
tree | 28e4dcd2701e94d4c4e5f9c2c41a9635da7e6389 /source/blender/blenlib/intern | |
parent | 7cfea48752ebc544104d57d19736c201a98bc3cd (diff) |
BLI: make some spans default constructible
`GSpan` and spans based on virtual arrays were not default constructible
before, which made them hard to use sometimes. It's generally fine for
spans to be empty.
The main thing the keep in mind is that the type pointer in `GSpan` may
be null now. Generally, code receiving spans as input can assume that
the type is not-null, but sometimes that may be valid. The old #type() method
that returned a reference to the type still exists. It asserts when the
type is null.
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/generic_virtual_array.cc | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/generic_virtual_array.cc b/source/blender/blenlib/intern/generic_virtual_array.cc index 532c7b9b626..28bc66e8524 100644 --- a/source/blender/blenlib/intern/generic_virtual_array.cc +++ b/source/blender/blenlib/intern/generic_virtual_array.cc @@ -287,8 +287,15 @@ template<int BufferSize> class GVArrayImpl_For_SmallTrivialSingleValue : public /** \name #GVArraySpan * \{ */ -GVArraySpan::GVArraySpan(GVArray varray) : GSpan(varray.type()), varray_(std::move(varray)) +GVArraySpan::GVArraySpan() = default; + +GVArraySpan::GVArraySpan(GVArray varray) + : GSpan(varray ? &varray.type() : nullptr), varray_(std::move(varray)) { + if (!varray_) { + return; + } + size_ = varray_.size(); const CommonVArrayInfo info = varray_.common_info(); if (info.type == CommonVArrayInfo::Type::Span) { @@ -302,8 +309,12 @@ GVArraySpan::GVArraySpan(GVArray varray) : GSpan(varray.type()), varray_(std::mo } GVArraySpan::GVArraySpan(GVArraySpan &&other) - : GSpan(other.type()), varray_(std::move(other.varray_)), owned_data_(other.owned_data_) + : GSpan(other.type_ptr()), varray_(std::move(other.varray_)), owned_data_(other.owned_data_) { + if (!varray_) { + return; + } + size_ = varray_.size(); const CommonVArrayInfo info = varray_.common_info(); if (info.type == CommonVArrayInfo::Type::Span) { @@ -340,9 +351,14 @@ GVArraySpan &GVArraySpan::operator=(GVArraySpan &&other) /** \name #GMutableVArraySpan * \{ */ +GMutableVArraySpan::GMutableVArraySpan() = default; + GMutableVArraySpan::GMutableVArraySpan(GVMutableArray varray, const bool copy_values_to_span) - : GMutableSpan(varray.type()), varray_(std::move(varray)) + : GMutableSpan(varray ? &varray.type() : nullptr), varray_(std::move(varray)) { + if (!varray_) { + return; + } size_ = varray_.size(); const CommonVArrayInfo info = varray_.common_info(); if (info.type == CommonVArrayInfo::Type::Span) { @@ -361,11 +377,14 @@ GMutableVArraySpan::GMutableVArraySpan(GVMutableArray varray, const bool copy_va } GMutableVArraySpan::GMutableVArraySpan(GMutableVArraySpan &&other) - : GMutableSpan(other.type()), + : GMutableSpan(other.type_ptr()), varray_(std::move(other.varray_)), owned_data_(other.owned_data_), show_not_saved_warning_(other.show_not_saved_warning_) { + if (!varray_) { + return; + } size_ = varray_.size(); const CommonVArrayInfo info = varray_.common_info(); if (info.type == CommonVArrayInfo::Type::Span) { @@ -417,6 +436,11 @@ void GMutableVArraySpan::disable_not_applied_warning() show_not_saved_warning_ = false; } +const GVMutableArray &GMutableVArraySpan::varray() const +{ + return varray_; +} + /** \} */ /* -------------------------------------------------------------------- */ |