Blender V4.3
BLI_generic_virtual_array.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
14#include "BLI_generic_array.hh"
15#include "BLI_generic_span.hh"
16#include "BLI_timeit.hh"
17#include "BLI_virtual_array.hh"
18
19namespace blender {
20
21/* -------------------------------------------------------------------- */
25class GVArray;
26class GVArrayImpl;
27class GVMutableArray;
28class GVMutableArrayImpl;
29
30/* A generically typed version of #VArrayImpl. */
32 protected:
33 const CPPType *type_;
35
36 public:
37 GVArrayImpl(const CPPType &type, int64_t size);
38 virtual ~GVArrayImpl() = default;
39
40 const CPPType &type() const;
41
42 int64_t size() const;
43
44 virtual void get(int64_t index, void *r_value) const;
45 virtual void get_to_uninitialized(int64_t index, void *r_value) const = 0;
46
47 virtual CommonVArrayInfo common_info() const;
48
49 virtual void materialize(const IndexMask &mask, void *dst) const;
50 virtual void materialize_to_uninitialized(const IndexMask &mask, void *dst) const;
51
52 virtual void materialize_compressed(const IndexMask &mask, void *dst) const;
53 virtual void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const;
54
55 virtual bool try_assign_VArray(void *varray) const;
56};
57
58/* A generic version of #VMutableArrayImpl. */
60 public:
61 GVMutableArrayImpl(const CPPType &type, int64_t size) : GVArrayImpl(type, size) {}
62
63 virtual void set_by_copy(int64_t index, const void *value);
64 virtual void set_by_relocate(int64_t index, void *value);
65 virtual void set_by_move(int64_t index, void *value) = 0;
66
67 virtual void set_all(const void *src);
68
69 virtual bool try_assign_VMutableArray(void *varray) const;
70};
71
74/* -------------------------------------------------------------------- */
78namespace detail {
80 const GVArrayImpl *(*get_varray)(const void *buffer) =
81 [](const void * /*buffer*/) -> const GVArrayImpl * { return nullptr; };
82
83 template<typename StorageT> static constexpr GVArrayAnyExtraInfo get();
84};
85} // namespace detail
86
87class GVMutableArray;
88
94 protected:
100
101 const GVArrayImpl *impl_ = nullptr;
103
104 protected:
105 GVArrayCommon() = default;
106 GVArrayCommon(const GVArrayCommon &other);
107 GVArrayCommon(GVArrayCommon &&other) noexcept;
109 GVArrayCommon(std::shared_ptr<const GVArrayImpl> impl);
111
112 template<typename ImplT, typename... Args> void emplace(Args &&...args);
113
114 void copy_from(const GVArrayCommon &other);
115 void move_from(GVArrayCommon &&other) noexcept;
116
117 const GVArrayImpl *impl_from_storage() const;
118
119 public:
120 const CPPType &type() const;
121 operator bool() const;
122
123 int64_t size() const;
124 bool is_empty() const;
125 IndexRange index_range() const;
126
127 template<typename T> bool try_assign_VArray(VArray<T> &varray) const;
128 bool may_have_ownership() const;
129
130 void materialize(void *dst) const;
131 void materialize(const IndexMask &mask, void *dst) const;
132
133 void materialize_to_uninitialized(void *dst) const;
134 void materialize_to_uninitialized(const IndexMask &mask, void *dst) const;
135
136 void materialize_compressed(const IndexMask &mask, void *dst) const;
137 void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const;
138
140
144 bool is_span() const;
149 GSpan get_internal_span() const;
150
154 bool is_single() const;
160 void get_internal_single(void *r_value) const;
164 void get_internal_single_to_uninitialized(void *r_value) const;
165
166 void get(int64_t index, void *r_value) const;
171 template<typename T> T get(int64_t index) const;
172 void get_to_uninitialized(int64_t index, void *r_value) const;
173};
174
176class GVArray : public GVArrayCommon {
177 private:
178 friend GVMutableArray;
179
180 public:
181 GVArray() = default;
182
183 GVArray(const GVArray &other);
184 GVArray(GVArray &&other) noexcept;
185 GVArray(const GVArrayImpl *impl);
186 GVArray(std::shared_ptr<const GVArrayImpl> impl);
187
188 GVArray(varray_tag::span /*tag*/, GSpan span);
189 GVArray(varray_tag::single_ref /*tag*/, const CPPType &type, int64_t size, const void *value);
190 GVArray(varray_tag::single /*tag*/, const CPPType &type, int64_t size, const void *value);
191
192 template<typename T> GVArray(const VArray<T> &varray);
193 template<typename T> GVArray(VArray<T> &&varray);
194 template<typename T> VArray<T> typed() const;
195
196 template<typename ImplT, typename... Args> static GVArray For(Args &&...args);
197
198 static GVArray ForSingle(const CPPType &type, int64_t size, const void *value);
199 static GVArray ForSingleRef(const CPPType &type, int64_t size, const void *value);
200 static GVArray ForSingleDefault(const CPPType &type, int64_t size);
201 static GVArray ForSpan(GSpan span);
203 static GVArray ForEmpty(const CPPType &type);
204
206
207 GVArray &operator=(const GVArray &other);
208 GVArray &operator=(GVArray &&other) noexcept;
209
211 {
212 return impl_;
213 }
214};
215
218 public:
219 GVMutableArray() = default;
223 GVMutableArray(std::shared_ptr<GVMutableArrayImpl> impl);
224
225 template<typename T> GVMutableArray(const VMutableArray<T> &varray);
226 template<typename T> VMutableArray<T> typed() const;
227
228 template<typename ImplT, typename... Args> static GVMutableArray For(Args &&...args);
229
231
232 operator GVArray() const &;
233 operator GVArray() && noexcept;
234
235 GVMutableArray &operator=(const GVMutableArray &other);
236 GVMutableArray &operator=(GVMutableArray &&other) noexcept;
237
239
240 template<typename T> bool try_assign_VMutableArray(VMutableArray<T> &varray) const;
241
242 void set_by_copy(int64_t index, const void *value);
243 void set_by_move(int64_t index, void *value);
244 void set_by_relocate(int64_t index, void *value);
245
246 void fill(const void *value);
250 void set_all(const void *src);
251
253
254 private:
255 GVMutableArrayImpl *get_impl() const;
256};
257
260/* -------------------------------------------------------------------- */
264/* A generic version of VArraySpan. */
265class GVArraySpan : public GSpan {
266 private:
267 GVArray varray_;
268 void *owned_data_ = nullptr;
269
270 public:
272 GVArraySpan(GVArray varray);
273 GVArraySpan(GVArraySpan &&other);
274 ~GVArraySpan();
276};
277
278/* A generic version of MutableVArraySpan. */
280 private:
281 GVMutableArray varray_;
282 void *owned_data_ = nullptr;
283 bool save_has_been_called_ = false;
284 bool show_not_saved_warning_ = true;
285
286 public:
288 GMutableVArraySpan(GVMutableArray varray, bool copy_values_to_span = true);
292
293 const GVMutableArray &varray() const;
294
295 void save();
296 void disable_not_applied_warning();
297};
298
301/* -------------------------------------------------------------------- */
305/* Used to convert a typed virtual array into a generic one. */
306template<typename T> class GVArrayImpl_For_VArray : public GVArrayImpl {
307 protected:
309
310 public:
312 : GVArrayImpl(CPPType::get<T>(), varray.size()), varray_(std::move(varray))
313 {
314 }
315
316 protected:
317 void get(const int64_t index, void *r_value) const override
318 {
319 *static_cast<T *>(r_value) = varray_[index];
320 }
321
322 void get_to_uninitialized(const int64_t index, void *r_value) const override
323 {
324 new (r_value) T(varray_[index]);
325 }
326
327 void materialize(const IndexMask &mask, void *dst) const override
328 {
329 varray_.materialize(mask, MutableSpan(static_cast<T *>(dst), mask.min_array_size()));
330 }
331
332 void materialize_to_uninitialized(const IndexMask &mask, void *dst) const override
333 {
335 mask, MutableSpan(static_cast<T *>(dst), mask.min_array_size()));
336 }
337
338 void materialize_compressed(const IndexMask &mask, void *dst) const override
339 {
340 varray_.materialize_compressed(mask, MutableSpan(static_cast<T *>(dst), mask.size()));
341 }
342
343 void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const override
344 {
346 mask, MutableSpan(static_cast<T *>(dst), mask.size()));
347 }
348
349 bool try_assign_VArray(void *varray) const override
350 {
351 *(VArray<T> *)varray = varray_;
352 return true;
353 }
354
356 {
357 return varray_.common_info();
358 }
359};
360
361/* Used to convert any generic virtual array into a typed one. */
362template<typename T> class VArrayImpl_For_GVArray : public VArrayImpl<T> {
363 protected:
365
366 public:
367 VArrayImpl_For_GVArray(GVArray varray) : VArrayImpl<T>(varray.size()), varray_(std::move(varray))
368 {
369 BLI_assert(varray_);
370 BLI_assert(varray_.type().template is<T>());
371 }
372
373 protected:
374 T get(const int64_t index) const override
375 {
376 T value;
377 varray_.get(index, &value);
378 return value;
379 }
380
382 {
383 return varray_.common_info();
384 }
385
386 bool try_assign_GVArray(GVArray &varray) const override
387 {
388 varray = varray_;
389 return true;
390 }
391
392 void materialize(const IndexMask &mask, T *dst) const override
393 {
394 varray_.materialize(mask, dst);
395 }
396
397 void materialize_to_uninitialized(const IndexMask &mask, T *dst) const override
398 {
399 varray_.materialize_to_uninitialized(mask, dst);
400 }
401
402 void materialize_compressed(const IndexMask &mask, T *dst) const override
403 {
404 varray_.materialize_compressed(mask, dst);
405 }
406
407 void materialize_compressed_to_uninitialized(const IndexMask &mask, T *dst) const override
408 {
410 }
411};
412
413/* Used to convert any typed virtual mutable array into a generic one. */
414template<typename T> class GVMutableArrayImpl_For_VMutableArray : public GVMutableArrayImpl {
415 protected:
417
418 public:
420 : GVMutableArrayImpl(CPPType::get<T>(), varray.size()), varray_(std::move(varray))
421 {
422 }
423
424 protected:
425 void get(const int64_t index, void *r_value) const override
426 {
427 *static_cast<T *>(r_value) = varray_[index];
428 }
429
430 void get_to_uninitialized(const int64_t index, void *r_value) const override
431 {
432 new (r_value) T(varray_[index]);
433 }
434
436 {
437 return varray_.common_info();
438 }
439
440 void set_by_copy(const int64_t index, const void *value) override
441 {
442 const T &value_ = *(const T *)value;
443 varray_.set(index, value_);
444 }
445
446 void set_by_relocate(const int64_t index, void *value) override
447 {
448 T &value_ = *static_cast<T *>(value);
449 varray_.set(index, std::move(value_));
450 value_.~T();
451 }
452
453 void set_by_move(const int64_t index, void *value) override
454 {
455 T &value_ = *static_cast<T *>(value);
456 varray_.set(index, std::move(value_));
457 }
458
459 void set_all(const void *src) override
460 {
461 varray_.set_all(Span(static_cast<const T *>(src), size_));
462 }
463
464 void materialize(const IndexMask &mask, void *dst) const override
465 {
466 varray_.materialize(mask, MutableSpan(static_cast<T *>(dst), mask.min_array_size()));
467 }
468
469 void materialize_to_uninitialized(const IndexMask &mask, void *dst) const override
470 {
472 mask, MutableSpan(static_cast<T *>(dst), mask.min_array_size()));
473 }
474
475 void materialize_compressed(const IndexMask &mask, void *dst) const override
476 {
477 varray_.materialize_compressed(mask, MutableSpan(static_cast<T *>(dst), mask.size()));
478 }
479
480 void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const override
481 {
483 mask, MutableSpan(static_cast<T *>(dst), mask.size()));
484 }
485
486 bool try_assign_VArray(void *varray) const override
487 {
488 *(VArray<T> *)varray = varray_;
489 return true;
490 }
491
492 bool try_assign_VMutableArray(void *varray) const override
493 {
494 *(VMutableArray<T> *)varray = varray_;
495 return true;
496 }
497};
498
499/* Used to convert an generic mutable virtual array into a typed one. */
500template<typename T> class VMutableArrayImpl_For_GVMutableArray : public VMutableArrayImpl<T> {
501 protected:
503
504 public:
506 : VMutableArrayImpl<T>(varray.size()), varray_(varray)
507 {
508 BLI_assert(varray_);
509 BLI_assert(varray_.type().template is<T>());
510 }
511
512 private:
513 T get(const int64_t index) const override
514 {
515 T value;
516 varray_.get(index, &value);
517 return value;
518 }
519
520 void set(const int64_t index, T value) override
521 {
522 varray_.set_by_relocate(index, &value);
523 }
524
525 CommonVArrayInfo common_info() const override
526 {
527 return varray_.common_info();
528 }
529
530 bool try_assign_GVArray(GVArray &varray) const override
531 {
532 varray = varray_;
533 return true;
534 }
535
536 bool try_assign_GVMutableArray(GVMutableArray &varray) const override
537 {
538 varray = varray_;
539 return true;
540 }
541
542 void materialize(const IndexMask &mask, T *dst) const override
543 {
544 varray_.materialize(mask, dst);
545 }
546
547 void materialize_to_uninitialized(const IndexMask &mask, T *dst) const override
548 {
549 varray_.materialize_to_uninitialized(mask, dst);
550 }
551
552 void materialize_compressed(const IndexMask &mask, T *dst) const override
553 {
554 varray_.materialize_compressed(mask, dst);
555 }
556
557 void materialize_compressed_to_uninitialized(const IndexMask &mask, T *dst) const override
558 {
560 }
561};
562
565/* -------------------------------------------------------------------- */
570 protected:
571 void *data_ = nullptr;
573
574 public:
576 : GVMutableArrayImpl(span.type(), span.size()),
577 data_(span.data()),
578 element_size_(span.type().size())
579 {
580 }
581
582 protected:
584 : GVMutableArrayImpl(type, size), element_size_(type.size())
585 {
586 }
587
588 public:
589 void get(int64_t index, void *r_value) const override;
590 void get_to_uninitialized(int64_t index, void *r_value) const override;
591
592 void set_by_copy(int64_t index, const void *value) override;
593 void set_by_move(int64_t index, void *value) override;
594 void set_by_relocate(int64_t index, void *value) override;
595
596 CommonVArrayInfo common_info() const override;
597
598 virtual void materialize(const IndexMask &mask, void *dst) const override;
599 virtual void materialize_to_uninitialized(const IndexMask &mask, void *dst) const override;
600
601 virtual void materialize_compressed(const IndexMask &mask, void *dst) const override;
602 virtual void materialize_compressed_to_uninitialized(const IndexMask &mask,
603 void *dst) const override;
604};
605
607 public:
608 using GVArrayImpl_For_GSpan::GVArrayImpl_For_GSpan;
609
610 private:
611 CommonVArrayInfo common_info() const override;
612};
613
614template<> inline constexpr bool is_trivial_extended_v<GVArrayImpl_For_GSpan_final> = true;
615
618/* -------------------------------------------------------------------- */
623 protected:
624 const void *value_ = nullptr;
625
626 public:
627 GVArrayImpl_For_SingleValueRef(const CPPType &type, const int64_t size, const void *value)
628 : GVArrayImpl(type, size), value_(value)
629 {
630 }
631
632 protected:
633 GVArrayImpl_For_SingleValueRef(const CPPType &type, const int64_t size) : GVArrayImpl(type, size)
634 {
635 }
636
637 void get(const int64_t index, void *r_value) const override;
638 void get_to_uninitialized(const int64_t index, void *r_value) const override;
639 CommonVArrayInfo common_info() const override;
640 void materialize(const IndexMask &mask, void *dst) const override;
641 void materialize_to_uninitialized(const IndexMask &mask, void *dst) const override;
642 void materialize_compressed(const IndexMask &mask, void *dst) const override;
643 void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const override;
644};
645
647 public:
648 using GVArrayImpl_For_SingleValueRef::GVArrayImpl_For_SingleValueRef;
649
650 private:
651 CommonVArrayInfo common_info() const override;
652};
653
654template<>
656
659/* -------------------------------------------------------------------- */
663inline GVArrayImpl::GVArrayImpl(const CPPType &type, const int64_t size)
664 : type_(&type), size_(size)
665{
666 BLI_assert(size_ >= 0);
667}
668
669inline const CPPType &GVArrayImpl::type() const
670{
671 return *type_;
672}
673
675{
676 return size_;
677}
678
681/* -------------------------------------------------------------------- */
685inline void GVMutableArray::set_by_copy(const int64_t index, const void *value)
686{
687 BLI_assert(index >= 0);
688 BLI_assert(index < this->size());
689 this->get_impl()->set_by_copy(index, value);
690}
691
692inline void GVMutableArray::set_by_move(const int64_t index, void *value)
693{
694 BLI_assert(index >= 0);
695 BLI_assert(index < this->size());
696 this->get_impl()->set_by_move(index, value);
697}
698
699inline void GVMutableArray::set_by_relocate(const int64_t index, void *value)
700{
701 BLI_assert(index >= 0);
702 BLI_assert(index < this->size());
703 this->get_impl()->set_by_relocate(index, value);
704}
705
706template<typename T>
708{
709 BLI_assert(impl_->type().is<T>());
710 return this->get_impl()->try_assign_VMutableArray(&varray);
711}
712
713inline GVMutableArrayImpl *GVMutableArray::get_impl() const
714{
715 return const_cast<GVMutableArrayImpl *>(static_cast<const GVMutableArrayImpl *>(impl_));
716}
717
720/* -------------------------------------------------------------------- */
724template<typename ImplT, typename... Args> inline void GVArrayCommon::emplace(Args &&...args)
725{
726 static_assert(std::is_base_of_v<GVArrayImpl, ImplT>);
727 if constexpr (std::is_copy_constructible_v<ImplT> && Storage::template is_inline_v<ImplT>) {
728 impl_ = &storage_.template emplace<ImplT>(std::forward<Args>(args)...);
729 }
730 else {
731 std::shared_ptr<const GVArrayImpl> ptr = std::make_shared<ImplT>(std::forward<Args>(args)...);
732 impl_ = &*ptr;
733 storage_ = std::move(ptr);
734 }
735}
736
737/* Copies the value at the given index into the provided storage. The `r_value` pointer is
738 * expected to point to initialized memory. */
739inline void GVArrayCommon::get(const int64_t index, void *r_value) const
740{
741 BLI_assert(index >= 0);
742 BLI_assert(index < this->size());
743 impl_->get(index, r_value);
744}
745
746template<typename T> inline T GVArrayCommon::get(const int64_t index) const
747{
748 BLI_assert(index >= 0);
749 BLI_assert(index < this->size());
750 BLI_assert(this->type().is<T>());
751 T value{};
752 impl_->get(index, &value);
753 return value;
754}
755
756/* Same as `get`, but `r_value` is expected to point to uninitialized memory. */
757inline void GVArrayCommon::get_to_uninitialized(const int64_t index, void *r_value) const
758{
759 BLI_assert(index >= 0);
760 BLI_assert(index < this->size());
761 impl_->get_to_uninitialized(index, r_value);
762}
763
764template<typename T> inline bool GVArrayCommon::try_assign_VArray(VArray<T> &varray) const
765{
766 BLI_assert(impl_->type().is<T>());
767 return impl_->try_assign_VArray(&varray);
768}
769
770inline const CPPType &GVArrayCommon::type() const
771{
772 return impl_->type();
773}
774
775inline GVArrayCommon::operator bool() const
776{
777 return impl_ != nullptr;
778}
779
781{
782 return impl_->common_info();
783}
784
786{
787 if (impl_ == nullptr) {
788 return 0;
789 }
790 return impl_->size();
791}
792
793inline bool GVArrayCommon::is_empty() const
794{
795 return this->size() == 0;
796}
797
801template<typename T, bool UseSingle, bool UseSpan> struct GVArrayDevirtualizer {
803
804 template<typename Fn> bool devirtualize(const Fn &fn) const
805 {
806 const CommonVArrayInfo info = this->varray_impl.common_info();
807 const int64_t size = this->varray_impl.size();
808 if constexpr (UseSingle) {
810 return fn(SingleAsSpan<T>(*static_cast<const T *>(info.data), size));
811 }
812 }
813 if constexpr (UseSpan) {
815 return fn(Span<T>(static_cast<const T *>(info.data), size));
816 }
817 }
818 return false;
819 }
820};
821
822/* -------------------------------------------------------------------- */
826inline GVArray::GVArray(varray_tag::span /*tag*/, const GSpan span)
827{
828 /* Use const-cast because the underlying virtual array implementation is shared between const
829 * and non const data. */
830 GMutableSpan mutable_span{span.type(), const_cast<void *>(span.data()), span.size()};
831 this->emplace<GVArrayImpl_For_GSpan_final>(mutable_span);
832}
833
835 const CPPType &type,
836 const int64_t size,
837 const void *value)
838{
839 this->emplace<GVArrayImpl_For_SingleValueRef_final>(type, size, value);
840}
841
842namespace detail {
843template<typename StorageT> constexpr GVArrayAnyExtraInfo GVArrayAnyExtraInfo::get()
844{
845 static_assert(std::is_base_of_v<GVArrayImpl, StorageT> ||
847
848 if constexpr (std::is_base_of_v<GVArrayImpl, StorageT>) {
849 return {[](const void *buffer) {
850 return static_cast<const GVArrayImpl *>((const StorageT *)buffer);
851 }};
852 }
853 else if constexpr (std::is_same_v<StorageT, const GVArrayImpl *>) {
854 return {[](const void *buffer) { return *(const StorageT *)buffer; }};
855 }
856 else if constexpr (std::is_same_v<StorageT, std::shared_ptr<const GVArrayImpl>>) {
857 return {[](const void *buffer) { return ((const StorageT *)buffer)->get(); }};
858 }
859 else {
861 return {};
862 }
863}
864} // namespace detail
865
866template<typename ImplT, typename... Args> inline GVArray GVArray::For(Args &&...args)
867{
868 static_assert(std::is_base_of_v<GVArrayImpl, ImplT>);
869 GVArray varray;
870 varray.template emplace<ImplT>(std::forward<Args>(args)...);
871 return varray;
872}
873
874template<typename T> inline GVArray::GVArray(const VArray<T> &varray) : GVArray(VArray<T>(varray))
875{
876}
877
878template<typename T> inline GVArray::GVArray(VArray<T> &&varray)
879{
880 if (!varray) {
881 return;
882 }
883 const CommonVArrayInfo info = varray.common_info();
885 *this = GVArray::ForSingle(CPPType::get<T>(), varray.size(), info.data);
886 return;
887 }
888 /* Need to check for ownership, because otherwise the referenced data can be destructed when
889 * #this is destructed. */
891 *this = GVArray::ForSpan(GSpan(CPPType::get<T>(), info.data, varray.size()));
892 return;
893 }
894 if (varray.try_assign_GVArray(*this)) {
895 return;
896 }
897 *this = GVArray::For<GVArrayImpl_For_VArray<T>>(std::move(varray));
898}
899
900template<typename T> inline VArray<T> GVArray::typed() const
901{
902 if (!*this) {
903 return {};
904 }
905 BLI_assert(impl_->type().is<T>());
906 const CommonVArrayInfo info = this->common_info();
908 return VArray<T>::ForSingle(*static_cast<const T *>(info.data), this->size());
909 }
910 /* Need to check for ownership, because otherwise the referenced data can be destructed when
911 * #this is destructed. */
913 return VArray<T>::ForSpan(Span<T>(static_cast<const T *>(info.data), this->size()));
914 }
915 VArray<T> varray;
916 if (this->try_assign_VArray(varray)) {
917 return varray;
918 }
919 return VArray<T>::template For<VArrayImpl_For_GVArray<T>>(*this);
920}
921
924/* -------------------------------------------------------------------- */
928template<typename ImplT, typename... Args>
930{
931 static_assert(std::is_base_of_v<GVMutableArrayImpl, ImplT>);
932 GVMutableArray varray;
933 varray.emplace<ImplT>(std::forward<Args>(args)...);
934 return varray;
935}
936
937template<typename T> inline GVMutableArray::GVMutableArray(const VMutableArray<T> &varray)
938{
939 if (!varray) {
940 return;
941 }
942 const CommonVArrayInfo info = varray.common_info();
945 GMutableSpan(CPPType::get<T>(), const_cast<void *>(info.data), varray.size()));
946 return;
947 }
948 if (varray.try_assign_GVMutableArray(*this)) {
949 return;
950 }
952}
953
954template<typename T> inline VMutableArray<T> GVMutableArray::typed() const
955{
956 if (!*this) {
957 return {};
958 }
959 BLI_assert(this->type().is<T>());
960 const CommonVArrayInfo info = this->common_info();
963 MutableSpan<T>(const_cast<T *>(static_cast<const T *>(info.data)), this->size()));
964 }
965 VMutableArray<T> varray;
966 if (this->try_assign_VMutableArray(varray)) {
967 return varray;
968 }
969 return VMutableArray<T>::template For<VMutableArrayImpl_For_GVMutableArray<T>>(*this);
970}
971
974} // namespace blender
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define BLI_assert(a)
Definition BLI_assert.h:50
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
static const CPPType & get()
bool is() const
int64_t size() const
const CPPType & type() const
const void * data() const
int64_t size() const
CommonVArrayInfo common_info() const
bool may_have_ownership() const
void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const
const GVArrayImpl * impl_from_storage() const
bool try_assign_VArray(VArray< T > &varray) const
void copy_from(const GVArrayCommon &other)
void move_from(GVArrayCommon &&other) noexcept
void get_to_uninitialized(int64_t index, void *r_value) const
void materialize(void *dst) const
void get_internal_single_to_uninitialized(void *r_value) const
void materialize_to_uninitialized(void *dst) const
void get(int64_t index, void *r_value) const
void materialize_compressed(const IndexMask &mask, void *dst) const
void get_internal_single(void *r_value) const
GVArrayImpl_For_GSpan(const CPPType &type, int64_t size)
GVArrayImpl_For_GSpan(const GMutableSpan span)
GVArrayImpl_For_SingleValueRef(const CPPType &type, const int64_t size, const void *value)
GVArrayImpl_For_SingleValueRef(const CPPType &type, const int64_t size)
void materialize(const IndexMask &mask, void *dst) const override
bool try_assign_VArray(void *varray) const override
void get(const int64_t index, void *r_value) const override
void get_to_uninitialized(const int64_t index, void *r_value) const override
CommonVArrayInfo common_info() const override
void materialize_compressed(const IndexMask &mask, void *dst) const override
void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const override
void materialize_to_uninitialized(const IndexMask &mask, void *dst) const override
virtual void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const
virtual void materialize(const IndexMask &mask, void *dst) const
virtual void get_to_uninitialized(int64_t index, void *r_value) const =0
virtual void materialize_compressed(const IndexMask &mask, void *dst) const
virtual void get(int64_t index, void *r_value) const
virtual bool try_assign_VArray(void *varray) const
GVArrayImpl(const CPPType &type, int64_t size)
virtual CommonVArrayInfo common_info() const
const CPPType & type() const
virtual ~GVArrayImpl()=default
virtual void materialize_to_uninitialized(const IndexMask &mask, void *dst) const
GVArray slice(IndexRange slice) const
static GVArray ForEmpty(const CPPType &type)
static GVArray ForGArray(GArray<> array)
GVArray()=default
static GVArray ForSingleDefault(const CPPType &type, int64_t size)
GVArray & operator=(const GVArray &other)
static GVArray For(Args &&...args)
GVArray(const GVArray &other)
const GVArrayImpl * get_implementation() const
GVArray(GVArray &&other) noexcept
static GVArray ForSingleRef(const CPPType &type, int64_t size, const void *value)
static GVArray ForSpan(GSpan span)
static GVArray ForSingle(const CPPType &type, int64_t size, const void *value)
void set_by_copy(const int64_t index, const void *value) override
void materialize(const IndexMask &mask, void *dst) const override
bool try_assign_VMutableArray(void *varray) const override
void get(const int64_t index, void *r_value) const override
void materialize_to_uninitialized(const IndexMask &mask, void *dst) const override
void get_to_uninitialized(const int64_t index, void *r_value) const override
void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const override
void set_by_relocate(const int64_t index, void *value) override
void materialize_compressed(const IndexMask &mask, void *dst) const override
void set_by_move(const int64_t index, void *value) override
virtual bool try_assign_VMutableArray(void *varray) const
virtual void set_all(const void *src)
virtual void set_by_copy(int64_t index, const void *value)
GVMutableArrayImpl(const CPPType &type, int64_t size)
virtual void set_by_relocate(int64_t index, void *value)
virtual void set_by_move(int64_t index, void *value)=0
GVMutableArray(GVMutableArray &&other) noexcept
void set_by_move(int64_t index, void *value)
void set_all(const void *src)
void set_by_copy(int64_t index, const void *value)
GVMutableArray(const GVMutableArray &other)
GVMutableArrayImpl * get_implementation() const
GMutableSpan get_internal_span() const
bool try_assign_VMutableArray(VMutableArray< T > &varray) const
GVMutableArray & operator=(const GVMutableArray &other)
VMutableArray< T > typed() const
static GVMutableArray ForSpan(GMutableSpan span)
static GVMutableArray For(Args &&...args)
void set_by_relocate(int64_t index, void *value)
void materialize(MutableSpan< T > r_span) const
void materialize_compressed_to_uninitialized(const IndexMask &mask, MutableSpan< T > r_span) const
void materialize_to_uninitialized(MutableSpan< T > r_span) const
void materialize_compressed(const IndexMask &mask, MutableSpan< T > r_span) const
CommonVArrayInfo common_info() const
void materialize_compressed_to_uninitialized(const IndexMask &mask, T *dst) const override
void materialize_to_uninitialized(const IndexMask &mask, T *dst) const override
void materialize_compressed(const IndexMask &mask, T *dst) const override
void materialize(const IndexMask &mask, T *dst) const override
bool try_assign_GVArray(GVArray &varray) const override
CommonVArrayInfo common_info() const override
T get(const int64_t index) const override
static VArray ForSingle(T value, const int64_t size)
static VArray ForSpan(Span< T > values)
void set(const int64_t index, T value)
static VMutableArray ForSpan(MutableSpan< T > values)
bool try_assign_GVMutableArray(GVMutableArray &varray) const
void set_all(Span< T > src)
node_ attributes set("label", ss.str())
#define T
constexpr bool is_same_any_v
constexpr bool is_trivial_extended_v< GVArrayImpl_For_GSpan_final >
constexpr bool is_trivial_extended_v< GVArrayImpl_For_SingleValueRef_final >
static IOCIOImpl * impl
Definition ocio_capi.cc:9
__int64 int64_t
Definition stdint.h:89
static constexpr GVArrayAnyExtraInfo get()
PointerRNA * ptr
Definition wm_files.cc:4126