1/**************************************************************************/
2/* array.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef ARRAY_H
32#define ARRAY_H
33
34#include "core/typedefs.h"
35
36#include <climits>
37
38class Variant;
39class ArrayPrivate;
40class Object;
41class StringName;
42class Callable;
43
44class Array {
45 mutable ArrayPrivate *_p;
46 void _unref() const;
47
48public:
49 void _ref(const Array &p_from) const;
50
51 Variant &operator[](int p_idx);
52 const Variant &operator[](int p_idx) const;
53
54 void set(int p_idx, const Variant &p_value);
55 const Variant &get(int p_idx) const;
56
57 int size() const;
58 bool is_empty() const;
59 void clear();
60
61 bool operator==(const Array &p_array) const;
62 bool operator!=(const Array &p_array) const;
63 bool recursive_equal(const Array &p_array, int recursion_count) const;
64
65 uint32_t hash() const;
66 uint32_t recursive_hash(int recursion_count) const;
67 void operator=(const Array &p_array);
68
69 void assign(const Array &p_array);
70 void push_back(const Variant &p_value);
71 _FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility
72 void append_array(const Array &p_array);
73 Error resize(int p_new_size);
74
75 Error insert(int p_pos, const Variant &p_value);
76 void remove_at(int p_pos);
77 void fill(const Variant &p_value);
78
79 Variant front() const;
80 Variant back() const;
81 Variant pick_random() const;
82
83 void sort();
84 void sort_custom(const Callable &p_callable);
85 void shuffle();
86 int bsearch(const Variant &p_value, bool p_before = true) const;
87 int bsearch_custom(const Variant &p_value, const Callable &p_callable, bool p_before = true) const;
88 void reverse();
89
90 int find(const Variant &p_value, int p_from = 0) const;
91 int rfind(const Variant &p_value, int p_from = -1) const;
92 int count(const Variant &p_value) const;
93 bool has(const Variant &p_value) const;
94
95 void erase(const Variant &p_value);
96
97 void push_front(const Variant &p_value);
98 Variant pop_back();
99 Variant pop_front();
100 Variant pop_at(int p_pos);
101
102 Array duplicate(bool p_deep = false) const;
103 Array recursive_duplicate(bool p_deep, int recursion_count) const;
104
105 Array slice(int p_begin, int p_end = INT_MAX, int p_step = 1, bool p_deep = false) const;
106 Array filter(const Callable &p_callable) const;
107 Array map(const Callable &p_callable) const;
108 Variant reduce(const Callable &p_callable, const Variant &p_accum) const;
109 bool any(const Callable &p_callable) const;
110 bool all(const Callable &p_callable) const;
111
112 bool operator<(const Array &p_array) const;
113 bool operator<=(const Array &p_array) const;
114 bool operator>(const Array &p_array) const;
115 bool operator>=(const Array &p_array) const;
116
117 Variant min() const;
118 Variant max() const;
119
120 const void *id() const;
121
122 void set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
123 bool is_typed() const;
124 bool is_same_typed(const Array &p_other) const;
125 uint32_t get_typed_builtin() const;
126 StringName get_typed_class_name() const;
127 Variant get_typed_script() const;
128
129 void make_read_only();
130 bool is_read_only() const;
131
132 Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
133 Array(const Array &p_from);
134 Array();
135 ~Array();
136};
137
138#endif // ARRAY_H
139