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