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