Blender  V3.3
BLI_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 #include "BLI_virtual_array.hh"
15 
16 namespace blender {
17 
19 template<typename T> class VVectorArray {
20  protected:
22 
23  public:
25  {
26  BLI_assert(size >= 0);
27  }
28 
29  virtual ~VVectorArray() = default;
30 
31  /* Returns the number of vectors in the vector array. */
32  int64_t size() const
33  {
34  return size_;
35  }
36 
37  /* Returns true when there is no vector in the vector array. */
38  bool is_empty() const
39  {
40  return size_ == 0;
41  }
42 
43  /* Returns the size of the vector at the given index. */
44  int64_t get_vector_size(const int64_t index) const
45  {
46  BLI_assert(index >= 0);
47  BLI_assert(index < size_);
48  return this->get_vector_size_impl(index);
49  }
50 
51  /* Returns an element from one of the vectors. */
52  T get_vector_element(const int64_t index, const int64_t index_in_vector) const
53  {
54  BLI_assert(index >= 0);
55  BLI_assert(index < size_);
56  BLI_assert(index_in_vector >= 0);
57  BLI_assert(index_in_vector < this->get_vector_size(index));
58  return this->get_vector_element_impl(index, index_in_vector);
59  }
60 
61  /* Returns true when the same vector is used at every index. */
62  bool is_single_vector() const
63  {
64  if (size_ == 1) {
65  return true;
66  }
67  return this->is_single_vector_impl();
68  }
69 
70  protected:
71  virtual int64_t get_vector_size_impl(int64_t index) const = 0;
72 
73  virtual T get_vector_element_impl(int64_t index, int64_t index_in_vetor) const = 0;
74 
75  virtual bool is_single_vector_impl() const
76  {
77  return false;
78  }
79 };
80 
81 } // namespace blender
#define BLI_assert(a)
Definition: BLI_assert.h:46
virtual bool is_single_vector_impl() const
int64_t get_vector_size(const int64_t index) const
virtual int64_t get_vector_size_impl(int64_t index) const =0
T get_vector_element(const int64_t index, const int64_t index_in_vector) const
virtual ~VVectorArray()=default
VVectorArray(const int64_t size)
virtual T get_vector_element_impl(int64_t index, int64_t index_in_vetor) const =0
#define T
__int64 int64_t
Definition: stdint.h:89