| 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 |
#pragma once |
| 32 |
|
| 33 |
#include "core/templates/span.h" |
| 34 |
#include "core/typedefs.h" |
| 35 |
#include "core/variant/variant_deep_duplicate.h" |
| 36 |
|
| 37 |
#include <climits> |
| 38 |
#include <initializer_list> |
| 39 |
|
| 40 |
class Callable; |
| 41 |
class StringName; |
| 42 |
class Variant; |
| 43 |
|
| 44 |
struct ArrayPrivate; |
| 45 |
struct ContainerType; |
| 46 |
|
| 47 |
class Array { |
| 48 |
mutable ArrayPrivate *_p; |
| 49 |
void _ref(const Array &p_from) const; |
| 50 |
void _unref() const; |
| 51 |
|
| 52 |
public: |
| 53 |
struct ConstIterator { |
| 54 |
_FORCE_INLINE_ const Variant &operator*() const { return *element_ptr; } |
| 55 |
_FORCE_INLINE_ const Variant *operator->() const { return element_ptr; } |
| 56 |
|
| 57 |
_FORCE_INLINE_ ConstIterator &operator++(); |
| 58 |
_FORCE_INLINE_ ConstIterator &operator--(); |
| 59 |
|
| 60 |
_FORCE_INLINE_ bool operator==(const ConstIterator &p_other) const { return element_ptr == p_other.element_ptr; } |
| 61 |
_FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return element_ptr != p_other.element_ptr; } |
| 62 |
|
| 63 |
ConstIterator() = default; |
| 64 |
|
| 65 |
_FORCE_INLINE_ ConstIterator(const Variant *p_element_ptr) : |
| 66 |
element_ptr(p_element_ptr) {} |
| 67 |
|
| 68 |
private: |
| 69 |
const Variant *element_ptr = nullptr; |
| 70 |
}; |
| 71 |
static_assert(std::is_trivially_copyable_v<ConstIterator>, "ConstIterator must be trivially copyable"); |
| 72 |
|
| 73 |
struct Iterator { |
| 74 |
_FORCE_INLINE_ Variant &operator*() const; |
| 75 |
_FORCE_INLINE_ Variant *operator->() const; |
| 76 |
|
| 77 |
_FORCE_INLINE_ Iterator &operator++(); |
| 78 |
_FORCE_INLINE_ Iterator &operator--(); |
| 79 |
|
| 80 |
_FORCE_INLINE_ bool operator==(const Iterator &p_other) const { return element_ptr == p_other.element_ptr; } |
| 81 |
_FORCE_INLINE_ bool operator!=(const Iterator &p_other) const { return element_ptr != p_other.element_ptr; } |
| 82 |
|
| 83 |
_FORCE_INLINE_ operator ConstIterator() const { return ConstIterator(element_ptr); } |
| 84 |
|
| 85 |
Iterator() = default; |
| 86 |
|
| 87 |
_FORCE_INLINE_ Iterator(Variant *p_element_ptr, Variant *p_read_only = nullptr) : |
| 88 |
element_ptr(p_element_ptr), read_only(p_read_only) {} |
| 89 |
|
| 90 |
private: |
| 91 |
Variant *element_ptr = nullptr; |
| 92 |
Variant *read_only = nullptr; |
| 93 |
}; |
| 94 |
static_assert(std::is_trivially_copyable_v<Iterator>, "Iterator must be trivially copyable"); |
| 95 |
|
| 96 |
Iterator begin(); |
| 97 |
Iterator end(); |
| 98 |
|
| 99 |
ConstIterator begin() const; |
| 100 |
ConstIterator end() const; |
| 101 |
|
| 102 |
Variant &operator[](int p_idx); |
| 103 |
const Variant &operator[](int p_idx) const; |
| 104 |
|
| 105 |
void set(int p_idx, const Variant &p_value); |
| 106 |
const Variant &get(int p_idx) const; |
| 107 |
|
| 108 |
int size() const; |
| 109 |
bool is_empty() const; |
| 110 |
void clear(); |
| 111 |
|
| 112 |
bool operator==(const Array &p_array) const; |
| 113 |
bool operator!=(const Array &p_array) const; |
| 114 |
bool recursive_equal(const Array &p_array, int recursion_count) const; |
| 115 |
|
| 116 |
uint32_t hash() const; |
| 117 |
uint32_t recursive_hash(int recursion_count) const; |
| 118 |
void operator=(const Array &p_array); |
| 119 |
|
| 120 |
void assign(const Array &p_array); |
| 121 |
void push_back(const Variant &p_value); |
| 122 |
_FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } |
| 123 |
void append_array(const Array &p_array); |
| 124 |
Error resize(int p_new_size); |
| 125 |
Error reserve(int p_new_size); |
| 126 |
|
| 127 |
Error insert(int p_pos, const Variant &p_value); |
| 128 |
void remove_at(int p_pos); |
| 129 |
void fill(const Variant &p_value); |
| 130 |
|
| 131 |
Variant front() const; |
| 132 |
Variant back() const; |
| 133 |
Variant pick_random() const; |
| 134 |
|
| 135 |
void sort(); |
| 136 |
void sort_custom(const Callable &p_callable); |
| 137 |
void shuffle(); |
| 138 |
int bsearch(const Variant &p_value, bool p_before = true) const; |
| 139 |
int bsearch_custom(const Variant &p_value, const Callable &p_callable, bool p_before = true) const; |
| 140 |
void reverse(); |
| 141 |
|
| 142 |
int find(const Variant &p_value, int p_from = 0) const; |
| 143 |
int find_custom(const Callable &p_callable, int p_from = 0) const; |
| 144 |
int rfind(const Variant &p_value, int p_from = -1) const; |
| 145 |
int rfind_custom(const Callable &p_callable, int p_from = -1) const; |
| 146 |
int count(const Variant &p_value) const; |
| 147 |
bool has(const Variant &p_value) const; |
| 148 |
|
| 149 |
void erase(const Variant &p_value); |
| 150 |
|
| 151 |
void push_front(const Variant &p_value); |
| 152 |
Variant pop_back(); |
| 153 |
Variant pop_front(); |
| 154 |
Variant pop_at(int p_pos); |
| 155 |
|
| 156 |
Array duplicate(bool p_deep = false) const; |
| 157 |
Array duplicate_deep(ResourceDeepDuplicateMode p_deep_subresources_mode = RESOURCE_DEEP_DUPLICATE_INTERNAL) const; |
| 158 |
Array recursive_duplicate(bool p_deep, ResourceDeepDuplicateMode p_deep_subresources_mode, int recursion_count) const; |
| 159 |
|
| 160 |
Array slice(int p_begin, int p_end = INT_MAX, int p_step = 1, bool p_deep = false) const; |
| 161 |
Array filter(const Callable &p_callable) const; |
| 162 |
Array map(const Callable &p_callable) const; |
| 163 |
Variant reduce(const Callable &p_callable, const Variant &p_accum) const; |
| 164 |
bool any(const Callable &p_callable) const; |
| 165 |
bool all(const Callable &p_callable) const; |
| 166 |
|
| 167 |
bool operator<(const Array &p_array) const; |
| 168 |
bool operator<=(const Array &p_array) const; |
| 169 |
bool operator>(const Array &p_array) const; |
| 170 |
bool operator>=(const Array &p_array) const; |
| 171 |
|
| 172 |
Variant min() const; |
| 173 |
Variant max() const; |
| 174 |
|
| 175 |
const void *id() const; |
| 176 |
|
| 177 |
void set_typed(const ContainerType &p_element_type); |
| 178 |
void set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script); |
| 179 |
|
| 180 |
bool is_typed() const; |
| 181 |
bool is_same_typed(const Array &p_other) const; |
| 182 |
bool is_same_instance(const Array &p_other) const; |
| 183 |
|
| 184 |
ContainerType get_element_type() const; |
| 185 |
uint32_t get_typed_builtin() const; |
| 186 |
StringName get_typed_class_name() const; |
| 187 |
Variant get_typed_script() const; |
| 188 |
|
| 189 |
void make_read_only(); |
| 190 |
bool is_read_only() const; |
| 191 |
static Array create_read_only(); |
| 192 |
|
| 193 |
Span<Variant> span() const; |
| 194 |
operator Span<Variant>() const { |
| 195 |
return this->span(); |
| 196 |
} |
| 197 |
|
| 198 |
Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script); |
| 199 |
Array(const Array &p_from); |
| 200 |
Array(std::initializer_list<Variant> p_init); |
| 201 |
Array(); |
| 202 |
~Array(); |
| 203 |
}; |