Blender V5.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
13
14#include "BLI_generic_array.hh"
15#include "BLI_generic_span.hh"
16#include "BLI_virtual_array.hh"
17
18namespace blender {
19
20/* -------------------------------------------------------------------- */
23
24class GVArray;
25class GVArrayImpl;
26class GVMutableArray;
28
29/* A generically typed version of #VArrayImpl. */
31 protected:
32 const CPPType *type_;
34
35 public:
37 virtual ~GVArrayImpl() = default;
38
39 const CPPType &type() const;
40
41 int64_t size() const;
42
43 virtual void get(int64_t index, void *r_value) const;
44 virtual void get_to_uninitialized(int64_t index, void *r_value) const = 0;
45
46 virtual CommonVArrayInfo common_info() const;
47
48 virtual void materialize(const IndexMask &mask, void *dst, bool dst_is_uninitialized) const;
49 virtual void materialize_compressed(const IndexMask &mask,
50 void *dst,
51 bool dst_is_uninitialized) const;
52
53 virtual bool try_assign_VArray(void *varray) const;
54};
55
56/* A generic version of #VMutableArrayImpl. */
58 public:
60
61 virtual void set_by_copy(int64_t index, const void *value);
62 virtual void set_by_relocate(int64_t index, void *value);
63 virtual void set_by_move(int64_t index, void *value) = 0;
64
65 virtual void set_all(const void *src);
66
67 virtual bool try_assign_VMutableArray(void *varray) const;
68};
69
71
72/* -------------------------------------------------------------------- */
75
76namespace blenlib_detail {
78 const GVArrayImpl *(*get_varray)(const void *buffer) =
79 [](const void * /*buffer*/) -> const GVArrayImpl * { return nullptr; };
80
81 template<typename StorageT> static constexpr GVArrayAnyExtraInfo get();
82};
83} // namespace blenlib_detail
84
85class GVMutableArray;
86
92 protected:
94
95 GVArrayCommon() = default;
96 GVArrayCommon(const GVArrayImpl *impl);
97 GVArrayCommon(std::shared_ptr<const GVArrayImpl> impl);
98
99 template<typename ImplT, typename... Args> void emplace(Args &&...args);
100
101 public:
102 const CPPType &type() const;
103 operator bool() const;
104
105 int64_t size() const;
106 bool is_empty() const;
107 IndexRange index_range() const;
108
109 template<typename T> bool try_assign_VArray(VArray<T> &varray) const;
110 bool may_have_ownership() const;
111
112 void materialize(void *dst) const;
113 void materialize(const IndexMask &mask, void *dst) const;
114
115 void materialize_to_uninitialized(void *dst) const;
116 void materialize_to_uninitialized(const IndexMask &mask, void *dst) const;
117
118 void materialize_compressed(const IndexMask &mask, void *dst) const;
119 void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const;
120
122
126 bool is_span() const;
131 GSpan get_internal_span() const;
132
136 bool is_single() const;
142 void get_internal_single(void *r_value) const;
146 void get_internal_single_to_uninitialized(void *r_value) const;
147
148 void get(int64_t index, void *r_value) const;
153 template<typename T> T get(int64_t index) const;
154 void get_to_uninitialized(int64_t index, void *r_value) const;
155};
156
158class GVArray : public GVArrayCommon {
159 private:
160 friend GVMutableArray;
161
162 public:
163 GVArray() = default;
164
165 GVArray(const GVArrayImpl *impl);
166 GVArray(std::shared_ptr<const GVArrayImpl> impl);
167
168 GVArray(varray_tag::span /*tag*/, GSpan span);
169 GVArray(varray_tag::single_ref /*tag*/, const CPPType &type, int64_t size, const void *value);
170 GVArray(varray_tag::single /*tag*/, const CPPType &type, int64_t size, const void *value);
171
172 template<typename T> GVArray(const VArray<T> &varray);
173 template<typename T> GVArray(VArray<T> &&varray);
174 template<typename T> VArray<T> typed() const;
175
176 template<typename ImplT, typename... Args> static GVArray from(Args &&...args);
177
178 static GVArray from_single(const CPPType &type, int64_t size, const void *value);
179 static GVArray from_single_ref(const CPPType &type, int64_t size, const void *value);
181 static GVArray from_span(GSpan span);
183 static GVArray from_empty(const CPPType &type);
184 template<typename GetToUninitFn>
185 static GVArray from_func(const CPPType &type, int64_t size, GetToUninitFn &&get_to_uninit);
186 static GVArray from_std_func(const CPPType &type,
188 std::function<void(int64_t index, void *r_value)> get_to_uninit);
189
191
193 {
194 return impl_.get();
195 }
196};
197
200 public:
201 GVMutableArray() = default;
203 GVMutableArray(std::shared_ptr<GVMutableArrayImpl> impl);
204
205 template<typename T> GVMutableArray(const VMutableArray<T> &varray);
206 template<typename T> VMutableArray<T> typed() const;
207
208 template<typename ImplT, typename... Args> static GVMutableArray from(Args &&...args);
209
211
212 operator GVArray() const &;
213 operator GVArray() && noexcept;
214
216
217 template<typename T> bool try_assign_VMutableArray(VMutableArray<T> &varray) const;
218
219 void set_by_copy(int64_t index, const void *value);
220 void set_by_move(int64_t index, void *value);
221 void set_by_relocate(int64_t index, void *value);
222
223 void fill(const void *value);
227 void set_all(const void *src);
228
230
231 private:
232 GVMutableArrayImpl *get_impl() const;
233};
234
236
237/* -------------------------------------------------------------------- */
240
241/* A generic version of VArraySpan. */
242class GVArraySpan : public GSpan {
243 private:
244 GVArray varray_;
245 void *owned_data_ = nullptr;
246
247 public:
249 GVArraySpan(GVArray varray);
250 template<typename T> GVArraySpan(VArray<T> varray) : GVArraySpan(GVArray(varray)) {}
251 GVArraySpan(GVArraySpan &&other);
252 ~GVArraySpan();
254};
255
256/* A generic version of MutableVArraySpan. */
258 private:
259 GVMutableArray varray_;
260 void *owned_data_ = nullptr;
261 bool save_has_been_called_ = false;
262 bool show_not_saved_warning_ = true;
263
264 public:
266 GMutableVArraySpan(GVMutableArray varray, bool copy_values_to_span = true);
270
271 const GVMutableArray &varray() const;
272
273 void save();
275};
276
278
279/* -------------------------------------------------------------------- */
282
283/* Used to convert a typed virtual array into a generic one. */
284template<typename T> class GVArrayImpl_For_VArray : public GVArrayImpl {
285 protected:
287
288 public:
290 : GVArrayImpl(CPPType::get<T>(), varray.size()), varray_(std::move(varray))
291 {
292 }
293
294 protected:
295 void get(const int64_t index, void *r_value) const override
296 {
297 *static_cast<T *>(r_value) = varray_[index];
298 }
299
300 void get_to_uninitialized(const int64_t index, void *r_value) const override
301 {
302 new (r_value) T(varray_[index]);
303 }
304
306 void *dst,
307 const bool dst_is_uninitialized) const override
308 {
309 varray_.get_implementation()->materialize(mask, static_cast<T *>(dst), dst_is_uninitialized);
310 }
311
313 void *dst,
314 const bool dst_is_uninitialized) const override
315 {
316 varray_.get_implementation()->materialize_compressed(
317 mask, static_cast<T *>(dst), dst_is_uninitialized);
318 }
319
320 bool try_assign_VArray(void *varray) const override
321 {
322 *static_cast<VArray<T> *>(varray) = varray_;
323 return true;
324 }
325
327 {
328 return varray_.common_info();
329 }
330};
331
332/* Used to convert any generic virtual array into a typed one. */
333template<typename T> class VArrayImpl_For_GVArray : public VArrayImpl<T> {
334 protected:
336
337 public:
338 VArrayImpl_For_GVArray(GVArray varray) : VArrayImpl<T>(varray.size()), varray_(std::move(varray))
339 {
341 BLI_assert(varray_.type().template is<T>());
342 }
343
344 protected:
345 T get(const int64_t index) const override
346 {
347 T value;
348 varray_.get(index, &value);
349 return value;
350 }
351
353 {
354 return varray_.common_info();
355 }
356
357 bool try_assign_GVArray(GVArray &varray) const override
358 {
359 varray = varray_;
360 return true;
361 }
362
363 void materialize(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const override
364 {
365 varray_.get_implementation()->materialize(mask, dst, dst_is_uninitialized);
366 }
367
369 T *dst,
370 const bool dst_is_uninitialized) const override
371 {
372 varray_.get_implementation()->materialize_compressed(mask, dst, dst_is_uninitialized);
373 }
374};
375
376/* Used to convert any typed virtual mutable array into a generic one. */
377template<typename T> class GVMutableArrayImpl_For_VMutableArray : public GVMutableArrayImpl {
378 protected:
380
381 public:
383 : GVMutableArrayImpl(CPPType::get<T>(), varray.size()), varray_(std::move(varray))
384 {
385 }
386
387 protected:
388 void get(const int64_t index, void *r_value) const override
389 {
390/* Quiet false-positive warning in GCC. */
391#if defined(__GNUC__) && !defined(__clang__)
392# pragma GCC diagnostic push
393# pragma GCC diagnostic ignored "-Warray-bounds"
394#endif
395 *static_cast<T *>(r_value) = varray_[index];
396#if defined(__GNUC__) && !defined(__clang__)
397# pragma GCC diagnostic pop
398#endif
399 }
400
401 void get_to_uninitialized(const int64_t index, void *r_value) const override
402 {
403 new (r_value) T(varray_[index]);
404 }
405
407 {
408 return varray_.common_info();
409 }
410
411 void set_by_copy(const int64_t index, const void *value) override
412 {
413 const T &value_ = *static_cast<const T *>(value);
414 varray_.set(index, value_);
415 }
416
417 void set_by_relocate(const int64_t index, void *value) override
418 {
419/* Quiet false-positive warning in GCC. */
420#if defined(__GNUC__) && !defined(__clang__)
421# pragma GCC diagnostic push
422# pragma GCC diagnostic ignored "-Warray-bounds"
423#endif
424 T &value_ = *static_cast<T *>(value);
425 varray_.set(index, std::move(value_));
426 value_.~T();
427#if defined(__GNUC__) && !defined(__clang__)
428# pragma GCC diagnostic pop
429#endif
430 }
431
432 void set_by_move(const int64_t index, void *value) override
433 {
434 T &value_ = *static_cast<T *>(value);
435 varray_.set(index, std::move(value_));
436 }
437
438 void set_all(const void *src) override
439 {
440 varray_.set_all(Span(static_cast<const T *>(src), size_));
441 }
442
444 void *dst,
445 const bool dst_is_uninitialized) const override
446 {
447 varray_.get_implementation()->materialize(mask, static_cast<T *>(dst), dst_is_uninitialized);
448 }
449
451 void *dst,
452 const bool dst_is_uninitialized) const override
453 {
454 varray_.get_implementation()->materialize_compressed(
455 mask, static_cast<T *>(dst), dst_is_uninitialized);
456 }
457
458 bool try_assign_VArray(void *varray) const override
459 {
460 *static_cast<VArray<T> *>(varray) = varray_;
461 return true;
462 }
463
464 bool try_assign_VMutableArray(void *varray) const override
465 {
466 *static_cast<VMutableArray<T> *>(varray) = varray_;
467 return true;
468 }
469};
470
471/* Used to convert an generic mutable virtual array into a typed one. */
472template<typename T> class VMutableArrayImpl_For_GVMutableArray : public VMutableArrayImpl<T> {
473 protected:
475
476 public:
478 : VMutableArrayImpl<T>(varray.size()), varray_(varray)
479 {
481 BLI_assert(varray_.type().template is<T>());
482 }
483
484 private:
485 T get(const int64_t index) const override
486 {
487 T value;
488 varray_.get(index, &value);
489 return value;
490 }
491
492 void set(const int64_t index, T value) override
493 {
494 varray_.set_by_relocate(index, &value);
495 }
496
497 CommonVArrayInfo common_info() const override
498 {
499 return varray_.common_info();
500 }
501
502 bool try_assign_GVArray(GVArray &varray) const override
503 {
504 varray = varray_;
505 return true;
506 }
507
508 bool try_assign_GVMutableArray(GVMutableArray &varray) const override
509 {
510 varray = varray_;
511 return true;
512 }
513
514 void materialize(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const override
515 {
516 varray_.get_implementation()->materialize(mask, dst, dst_is_uninitialized);
517 }
518
519 void materialize_compressed(const IndexMask &mask,
520 T *dst,
521 const bool dst_is_uninitialized) const override
522 {
523 varray_.get_implementation()->materialize_compressed(mask, dst, dst_is_uninitialized);
524 }
525};
526
528
529/* -------------------------------------------------------------------- */
532
534 protected:
535 void *data_ = nullptr;
537
538 public:
540 : GVMutableArrayImpl(span.type(), span.size()),
541 data_(span.data()),
542 element_size_(span.type().size)
543 {
544 }
545
546 protected:
551
552 public:
553 void get(int64_t index, void *r_value) const override;
554 void get_to_uninitialized(int64_t index, void *r_value) const override;
555
556 void set_by_copy(int64_t index, const void *value) override;
557 void set_by_move(int64_t index, void *value) override;
558 void set_by_relocate(int64_t index, void *value) override;
559
560 CommonVArrayInfo common_info() const override;
561
562 void materialize(const IndexMask &mask, void *dst, bool dst_is_uninitialized) const override;
563
564 void materialize_compressed(const IndexMask &mask,
565 void *dst,
566 bool dst_is_uninitialized) const override;
567};
568
570 public:
572
573 private:
574 CommonVArrayInfo common_info() const override;
575};
576
577template<> inline constexpr bool is_trivial_extended_v<GVArrayImpl_For_GSpan_final> = true;
578
580
581/* -------------------------------------------------------------------- */
584
586 protected:
587 const void *value_ = nullptr;
588
589 public:
590 GVArrayImpl_For_SingleValueRef(const CPPType &type, const int64_t size, const void *value)
591 : GVArrayImpl(type, size), value_(value)
592 {
593 }
594
595 protected:
599
600 void get(const int64_t index, void *r_value) const override;
601 void get_to_uninitialized(const int64_t index, void *r_value) const override;
602 CommonVArrayInfo common_info() const override;
603 void materialize(const IndexMask &mask, void *dst, bool dst_is_uninitialized) const override;
604 void materialize_compressed(const IndexMask &mask,
605 void *dst,
606 bool dst_is_uninitialized) const override;
607};
608
610 public:
612
613 private:
614 CommonVArrayInfo common_info() const override;
615};
616
617template<>
619
621
622/* -------------------------------------------------------------------- */
625
626template<typename GetToUninitFn> class GVArrayImpl_For_Func final : public GVArrayImpl {
627 private:
628 GetToUninitFn get_to_uninit_;
629
630 public:
631 GVArrayImpl_For_Func(const CPPType &type, const int64_t size, GetToUninitFn get_to_uninit)
632 : GVArrayImpl(type, size), get_to_uninit_(std::move(get_to_uninit))
633 {
634 }
635
636 void get(const int64_t index, void *r_value) const override
637 {
638 if (!type_->is_trivially_destructible) {
639 type_->destruct(r_value);
640 }
641 return get_to_uninit_(index, r_value);
642 }
643
644 void get_to_uninitialized(const int64_t index, void *r_value) const override
645 {
646 return get_to_uninit_(index, r_value);
647 }
648};
649
651
652/* -------------------------------------------------------------------- */
655
657 : type_(&type), size_(size)
658{
659 BLI_assert(size_ >= 0);
660}
661
662inline const CPPType &GVArrayImpl::type() const
663{
664 return *type_;
665}
666
668{
669 return size_;
670}
671
673
674/* -------------------------------------------------------------------- */
677
678inline void GVMutableArray::set_by_copy(const int64_t index, const void *value)
679{
680 BLI_assert(index >= 0);
681 BLI_assert(index < this->size());
682 this->get_impl()->set_by_copy(index, value);
683}
684
685inline void GVMutableArray::set_by_move(const int64_t index, void *value)
686{
687 BLI_assert(index >= 0);
688 BLI_assert(index < this->size());
689 this->get_impl()->set_by_move(index, value);
690}
691
692inline void GVMutableArray::set_by_relocate(const int64_t index, void *value)
693{
694 BLI_assert(index >= 0);
695 BLI_assert(index < this->size());
696 this->get_impl()->set_by_relocate(index, value);
697}
698
699template<typename T>
701{
702 BLI_assert(impl_->type().is<T>());
703 return this->get_impl()->try_assign_VMutableArray(&varray);
704}
705
706inline GVMutableArrayImpl *GVMutableArray::get_impl() const
707{
708 return const_cast<GVMutableArrayImpl *>(static_cast<const GVMutableArrayImpl *>(impl_.get()));
709}
710
712{
713 return this->get_impl();
714}
715
717
718/* -------------------------------------------------------------------- */
721
722template<typename ImplT, typename... Args> inline void GVArrayCommon::emplace(Args &&...args)
723{
724 impl_.emplace<ImplT>(std::forward<Args>(args)...);
725}
726
727/* Copies the value at the given index into the provided storage. The `r_value` pointer is
728 * expected to point to initialized memory. */
729inline void GVArrayCommon::get(const int64_t index, void *r_value) const
730{
731 BLI_assert(index >= 0);
732 BLI_assert(index < this->size());
733 impl_->get(index, r_value);
734}
735
736template<typename T> inline T GVArrayCommon::get(const int64_t index) const
737{
738 BLI_assert(index >= 0);
739 BLI_assert(index < this->size());
740 BLI_assert(this->type().is<T>());
741 T value{};
742 impl_->get(index, &value);
743 return value;
744}
745
746/* Same as `get`, but `r_value` is expected to point to uninitialized memory. */
747inline void GVArrayCommon::get_to_uninitialized(const int64_t index, void *r_value) const
748{
749 BLI_assert(index >= 0);
750 BLI_assert(index < this->size());
751 impl_->get_to_uninitialized(index, r_value);
752}
753
754template<typename T> inline bool GVArrayCommon::try_assign_VArray(VArray<T> &varray) const
755{
756 BLI_assert(impl_->type().is<T>());
757 return impl_->try_assign_VArray(&varray);
758}
759
760inline const CPPType &GVArrayCommon::type() const
761{
762 return impl_->type();
763}
764
765inline GVArrayCommon::operator bool() const
766{
767 return impl_;
768}
769
771{
772 return impl_->common_info();
773}
774
776{
777 if (!impl_) {
778 return 0;
779 }
780 return impl_->size();
781}
782
783inline bool GVArrayCommon::is_empty() const
784{
785 return this->size() == 0;
786}
787
789
791template<typename T, bool UseSingle, bool UseSpan> struct GVArrayDevirtualizer {
793
794 template<typename Fn> bool devirtualize(const Fn &fn) const
795 {
796 const CommonVArrayInfo info = this->varray_impl.common_info();
797 const int64_t size = this->varray_impl.size();
798 if constexpr (UseSingle) {
800 return fn(SingleAsSpan<T>(*static_cast<const T *>(info.data), size));
801 }
802 }
803 if constexpr (UseSpan) {
805 return fn(Span<T>(static_cast<const T *>(info.data), size));
806 }
807 }
808 return false;
809 }
810};
811
812/* -------------------------------------------------------------------- */
815
816inline GVArray::GVArray(varray_tag::span /*tag*/, const GSpan span)
817{
818 /* Use const-cast because the underlying virtual array implementation is shared between const
819 * and non const data. */
820 GMutableSpan mutable_span{span.type(), const_cast<void *>(span.data()), span.size()};
821 this->emplace<GVArrayImpl_For_GSpan_final>(mutable_span);
822}
823
825 const CPPType &type,
826 const int64_t size,
827 const void *value)
828{
830}
831
832namespace blenlib_detail {
833template<typename StorageT> constexpr GVArrayAnyExtraInfo GVArrayAnyExtraInfo::get()
834{
835 static_assert(std::is_base_of_v<GVArrayImpl, StorageT> ||
837
838 if constexpr (std::is_base_of_v<GVArrayImpl, StorageT>) {
839 return {[](const void *buffer) {
840 return static_cast<const GVArrayImpl *>(static_cast<const StorageT *>(buffer));
841 }};
842 }
843 else if constexpr (std::is_same_v<StorageT, const GVArrayImpl *>) {
844 return {[](const void *buffer) { return *static_cast<const StorageT *>(buffer); }};
845 }
846 else if constexpr (std::is_same_v<StorageT, std::shared_ptr<const GVArrayImpl>>) {
847 return {[](const void *buffer) { return (static_cast<const StorageT *>(buffer))->get(); }};
848 }
849 else {
851 return {};
852 }
853}
854} // namespace blenlib_detail
855
856template<typename ImplT, typename... Args> inline GVArray GVArray::from(Args &&...args)
857{
858 static_assert(std::is_base_of_v<GVArrayImpl, ImplT>);
859 GVArray varray;
860 varray.template emplace<ImplT>(std::forward<Args>(args)...);
861 return varray;
862}
863
864template<typename T> inline GVArray::GVArray(const VArray<T> &varray) : GVArray(VArray<T>(varray))
865{
866}
867
868template<typename T> inline GVArray::GVArray(VArray<T> &&varray)
869{
870 if (!varray) {
871 return;
872 }
873 const CommonVArrayInfo info = varray.common_info();
875 *this = GVArray::from_single(CPPType::get<T>(), varray.size(), info.data);
876 return;
877 }
878 /* Need to check for ownership, because otherwise the referenced data can be destructed when
879 * #this is destructed. */
881 *this = GVArray::from_span(GSpan(CPPType::get<T>(), info.data, varray.size()));
882 return;
883 }
884 if (varray.try_assign_GVArray(*this)) {
885 return;
886 }
887 *this = GVArray::from<GVArrayImpl_For_VArray<T>>(std::move(varray));
888}
889
890inline GVArray::GVArray(const GVArrayImpl *impl) : GVArrayCommon(impl) {}
891
892inline GVArray::GVArray(std::shared_ptr<const GVArrayImpl> impl) : GVArrayCommon(std::move(impl))
893{
894}
895
896inline GVArray GVArray::from_single(const CPPType &type, const int64_t size, const void *value)
897{
898 return GVArray(varray_tag::single{}, type, size, value);
899}
900
901inline GVArray GVArray::from_single_ref(const CPPType &type, const int64_t size, const void *value)
902{
903 return GVArray(varray_tag::single_ref{}, type, size, value);
904}
905
910
912{
913 return GVArray(varray_tag::span{}, span);
914}
915
917{
919}
920
922 const CPPType &type,
924 std::function<void(int64_t index, void *r_value)> get_to_uninit)
925{
926 return GVArray::from_func(type, size, std::move(get_to_uninit));
927}
928
929template<typename T> inline VArray<T> GVArray::typed() const
930{
931 if (!*this) {
932 return {};
933 }
934 BLI_assert(impl_->type().is<T>());
935 const CommonVArrayInfo info = this->common_info();
937 return VArray<T>::from_single(*static_cast<const T *>(info.data), this->size());
938 }
939 /* Need to check for ownership, because otherwise the referenced data can be destructed when
940 * #this is destructed. */
942 return VArray<T>::from_span(Span<T>(static_cast<const T *>(info.data), this->size()));
943 }
944 VArray<T> varray;
945 if (this->try_assign_VArray(varray)) {
946 return varray;
947 }
949}
950
951template<typename GetToUninitFn>
952inline GVArray GVArray::from_func(const CPPType &type, int64_t size, GetToUninitFn &&get_to_uninit)
953{
955 type, size, std::forward<GetToUninitFn>(get_to_uninit));
956}
957
959
960/* -------------------------------------------------------------------- */
963
964template<typename ImplT, typename... Args>
966{
967 static_assert(std::is_base_of_v<GVMutableArrayImpl, ImplT>);
968 GVMutableArray varray;
969 varray.emplace<ImplT>(std::forward<Args>(args)...);
970 return varray;
971}
972
973template<typename T> inline GVMutableArray::GVMutableArray(const VMutableArray<T> &varray)
974{
975 if (!varray) {
976 return;
977 }
978 const CommonVArrayInfo info = varray.common_info();
981 GMutableSpan(CPPType::get<T>(), const_cast<void *>(info.data), varray.size()));
982 return;
983 }
984 if (varray.try_assign_GVMutableArray(*this)) {
985 return;
986 }
988}
989
990template<typename T> inline VMutableArray<T> GVMutableArray::typed() const
991{
992 if (!*this) {
993 return {};
994 }
995 BLI_assert(this->type().is<T>());
996 const CommonVArrayInfo info = this->common_info();
999 MutableSpan<T>(const_cast<T *>(static_cast<const T *>(info.data)), this->size()));
1000 }
1001 VMutableArray<T> varray;
1002 if (this->try_assign_VMutableArray(varray)) {
1003 return varray;
1004 }
1006}
1007
1009
1010} // namespace blender
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define BLI_assert_unreachable()
long long int int64_t
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
constexpr Span()=default
static const CPPType & get()
const void * default_value() const
const GVMutableArray & varray() const
GMutableVArraySpan & operator=(GMutableVArraySpan &&other)
const CPPType & type() const
GSpan()=default
const void * data() const
int64_t size() const
CommonVArrayInfo common_info() const
bool may_have_ownership() const
AnyDerived< const GVArrayImpl, 40 > impl_
void materialize_compressed_to_uninitialized(const IndexMask &mask, void *dst) const
bool try_assign_VArray(VArray< T > &varray) const
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
void get(const int64_t index, void *r_value) const override
void get_to_uninitialized(const int64_t index, void *r_value) const override
GVArrayImpl_For_Func(const CPPType &type, const int64_t size, GetToUninitFn get_to_uninit)
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, const void *value)
GVArrayImpl_For_SingleValueRef(const CPPType &type, const int64_t size)
bool try_assign_VArray(void *varray) const override
void materialize(const IndexMask &mask, void *dst, const bool dst_is_uninitialized) 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 bool dst_is_uninitialized) const override
virtual void materialize(const IndexMask &mask, void *dst, bool dst_is_uninitialized) const
virtual void get_to_uninitialized(int64_t index, void *r_value) const =0
virtual void get(int64_t index, void *r_value) const
virtual bool try_assign_VArray(void *varray) const
virtual void materialize_compressed(const IndexMask &mask, void *dst, bool dst_is_uninitialized) const
GVArrayImpl(const CPPType &type, int64_t size)
virtual CommonVArrayInfo common_info() const
const CPPType & type() const
virtual ~GVArrayImpl()=default
GVArray slice(IndexRange slice) const
GVArray()=default
static GVArray from_empty(const CPPType &type)
const GVArrayImpl * get_implementation() const
static GVArray from_std_func(const CPPType &type, int64_t size, std::function< void(int64_t index, void *r_value)> get_to_uninit)
static GVArray from(Args &&...args)
static GVArray from_single_default(const CPPType &type, int64_t size)
static GVArray from_garray(GArray<> array)
static GVArray from_func(const CPPType &type, int64_t size, GetToUninitFn &&get_to_uninit)
static GVArray from_single(const CPPType &type, int64_t size, const void *value)
static GVArray from_span(GSpan span)
static GVArray from_single_ref(const CPPType &type, int64_t size, const void *value)
void materialize(const IndexMask &mask, void *dst, const bool dst_is_uninitialized) const override
void set_by_copy(const int64_t index, const void *value) override
bool try_assign_VMutableArray(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
void set_by_relocate(const int64_t index, void *value) override
void materialize_compressed(const IndexMask &mask, void *dst, const bool dst_is_uninitialized) 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
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)
GVMutableArrayImpl * get_implementation() const
static GVMutableArray from_span(GMutableSpan span)
GMutableSpan get_internal_span() const
bool try_assign_VMutableArray(VMutableArray< T > &varray) const
void fill(const void *value)
static GVMutableArray from(Args &&...args)
VMutableArray< T > typed() const
void set_by_relocate(int64_t index, void *value)
const VArrayImpl< T > * get_implementation() const
CommonVArrayInfo common_info() const
void materialize(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const override
void materialize_compressed(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const override
bool try_assign_GVArray(GVArray &varray) const override
CommonVArrayInfo common_info() const override
T get(const int64_t index) const override
VArrayImpl(const int64_t size)
static VArray from_single(T value, const int64_t size)
static VArray from_span(Span< T > values)
void set(const int64_t index, T value)
bool try_assign_GVMutableArray(GVMutableArray &varray) const
static VMutableArray from_span(MutableSpan< T > values)
void set_all(Span< T > src)
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
#define index(i)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
#define T
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
constexpr bool is_same_any_v
BMesh const char void * data
constexpr bool is_trivial_extended_v