Blender  V2.93
BLI_virtual_vector_array.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
28 #include "BLI_virtual_array.hh"
29 
30 namespace blender {
31 
32 /* A readonly virtual array of vectors. */
33 template<typename T> class VVectorArray {
34  protected:
36 
37  public:
39  {
40  BLI_assert(size >= 0);
41  }
42 
43  virtual ~VVectorArray() = default;
44 
45  /* Returns the number of vectors in the vector array. */
46  int64_t size() const
47  {
48  return size_;
49  }
50 
51  /* Returns true when there is no vector in the vector array. */
52  bool is_empty() const
53  {
54  return size_ == 0;
55  }
56 
57  /* Returns the size of the vector at the given index. */
58  int64_t get_vector_size(const int64_t index) const
59  {
60  BLI_assert(index >= 0);
61  BLI_assert(index < size_);
62  return this->get_vector_size_impl(index);
63  }
64 
65  /* Returns an element from one of the vectors. */
66  T get_vector_element(const int64_t index, const int64_t index_in_vector) const
67  {
68  BLI_assert(index >= 0);
69  BLI_assert(index < size_);
70  BLI_assert(index_in_vector >= 0);
71  BLI_assert(index_in_vector < this->get_vector_size(index));
72  return this->get_vector_element_impl(index, index_in_vector);
73  }
74 
75  /* Returns true when the same vector is used at every index. */
76  bool is_single_vector() const
77  {
78  if (size_ == 1) {
79  return true;
80  }
81  return this->is_single_vector_impl();
82  }
83 
84  protected:
85  virtual int64_t get_vector_size_impl(const int64_t index) const = 0;
86 
87  virtual T get_vector_element_impl(const int64_t index, const int64_t index_in_vetor) const = 0;
88 
89  virtual bool is_single_vector_impl() const
90  {
91  return false;
92  }
93 };
94 
95 } // namespace blender
#define BLI_assert(a)
Definition: BLI_assert.h:58
virtual T get_vector_element_impl(const int64_t index, const int64_t index_in_vetor) const =0
virtual bool is_single_vector_impl() const
int64_t get_vector_size(const int64_t index) const
T get_vector_element(const int64_t index, const int64_t index_in_vector) const
virtual ~VVectorArray()=default
VVectorArray(const int64_t size)
virtual int64_t get_vector_size_impl(const int64_t index) const =0
#define T
__int64 int64_t
Definition: stdint.h:92