Blender  V3.3
BLI_generic_virtual_vector_array.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
14 
15 namespace blender {
16 
17 /* A generically typed version of `VVectorArray`. */
19  protected:
20  const CPPType *type_;
22 
23  public:
25  {
26  }
27 
28  virtual ~GVVectorArray() = default;
29 
30  /* Returns the number of vectors in the vector array. */
31  int64_t size() const
32  {
33  return size_;
34  }
35 
36  /* Returns true when there is no vector in the vector array. */
37  bool is_empty() const
38  {
39  return size_ == 0;
40  }
41 
42  const CPPType &type() const
43  {
44  return *type_;
45  }
46 
47  /* Returns the size of the vector at the given index. */
48  int64_t get_vector_size(const int64_t index) const
49  {
50  BLI_assert(index >= 0);
51  BLI_assert(index < size_);
52  return this->get_vector_size_impl(index);
53  }
54 
55  /* Copies an element from one of the vectors into `r_value`, which is expected to point to
56  * initialized memory. */
57  void get_vector_element(const int64_t index, const int64_t index_in_vector, void *r_value) const
58  {
59  BLI_assert(index >= 0);
60  BLI_assert(index < size_);
61  BLI_assert(index_in_vector >= 0);
62  BLI_assert(index_in_vector < this->get_vector_size(index));
63  this->get_vector_element_impl(index, index_in_vector, r_value);
64  }
65 
66  /* Returns true when the same vector is used at every index. */
67  bool is_single_vector() const
68  {
69  if (size_ == 1) {
70  return true;
71  }
72  return this->is_single_vector_impl();
73  }
74 
75  protected:
76  virtual int64_t get_vector_size_impl(int64_t index) const = 0;
77 
78  virtual void get_vector_element_impl(int64_t index,
79  int64_t index_in_vector,
80  void *r_value) const = 0;
81 
82  virtual bool is_single_vector_impl() const
83  {
84  return false;
85  }
86 };
87 
89  private:
90  const GVVectorArray &vector_array_;
91  const int64_t index_;
92 
93  public:
94  GVArray_For_GVVectorArrayIndex(const GVVectorArray &vector_array, const int64_t index)
95  : GVArrayImpl(vector_array.type(), vector_array.get_vector_size(index)),
96  vector_array_(vector_array),
97  index_(index)
98  {
99  }
100 
101  protected:
102  void get(int64_t index_in_vector, void *r_value) const override;
103  void get_to_uninitialized(int64_t index_in_vector, void *r_value) const override;
104 };
105 
107  private:
108  GVArray varray_;
109 
110  public:
112  : GVVectorArray(varray.type(), size), varray_(std::move(varray))
113  {
114  }
115 
116  protected:
117  int64_t get_vector_size_impl(int64_t index) const override;
118  void get_vector_element_impl(int64_t index,
119  int64_t index_in_vector,
120  void *r_value) const override;
121 
122  bool is_single_vector_impl() const override;
123 };
124 
126  private:
127  const GSpan span_;
128 
129  public:
131  : GVVectorArray(span.type(), size), span_(span)
132  {
133  }
134 
135  protected:
136  int64_t get_vector_size_impl(int64_t UNUSED(index)) const override;
138  int64_t index_in_vector,
139  void *r_value) const override;
140 
141  bool is_single_vector_impl() const override;
142 };
143 
144 template<typename T> class VVectorArray_For_GVVectorArray : public VVectorArray<T> {
145  private:
146  const GVVectorArray &vector_array_;
147 
148  public:
150  : VVectorArray<T>(vector_array.size()), vector_array_(vector_array)
151  {
152  }
153 
154  protected:
155  int64_t get_vector_size_impl(const int64_t index) const override
156  {
157  return vector_array_.get_vector_size(index);
158  }
159 
160  T get_vector_element_impl(const int64_t index, const int64_t index_in_vector) const override
161  {
162  T value;
163  vector_array_.get_vector_element(index, index_in_vector, &value);
164  return value;
165  }
166 
167  bool is_single_vector_impl() const override
168  {
169  return vector_array_.is_single_vector();
170  }
171 };
172 
173 } // namespace blender
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define UNUSED(x)
const CPPType & type() const
void get(int64_t index_in_vector, void *r_value) const override
GVArray_For_GVVectorArrayIndex(const GVVectorArray &vector_array, const int64_t index)
void get_to_uninitialized(int64_t index_in_vector, void *r_value) const override
int64_t get_vector_size_impl(int64_t UNUSED(index)) const override
void get_vector_element_impl(int64_t UNUSED(index), int64_t index_in_vector, void *r_value) const override
GVVectorArray_For_SingleGSpan(const GSpan span, const int64_t size)
int64_t get_vector_size_impl(int64_t index) const override
GVVectorArray_For_SingleGVArray(GVArray varray, const int64_t size)
void get_vector_element_impl(int64_t index, int64_t index_in_vector, void *r_value) const override
virtual int64_t get_vector_size_impl(int64_t index) const =0
void get_vector_element(const int64_t index, const int64_t index_in_vector, void *r_value) const
GVVectorArray(const CPPType &type, const int64_t size)
virtual void get_vector_element_impl(int64_t index, int64_t index_in_vector, void *r_value) const =0
virtual ~GVVectorArray()=default
int64_t get_vector_size(const int64_t index) const
VVectorArray_For_GVVectorArray(const GVVectorArray &vector_array)
T get_vector_element_impl(const int64_t index, const int64_t index_in_vector) const override
int64_t get_vector_size_impl(const int64_t index) const override
#define T
__int64 int64_t
Definition: stdint.h:89