Skip to content

Commit

Permalink
Add sort and has methods to PackedArrays
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Jul 7, 2020
1 parent 141ce4d commit af80bcd
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 11 deletions.
36 changes: 36 additions & 0 deletions core/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedByteArray, uint8_t, remove);
VCALL_PARRMEM1(PackedByteArray, uint8_t, append);
VCALL_PARRMEM1(PackedByteArray, uint8_t, append_array);
VCALL_PARRMEM1R(PackedByteArray, uint8_t, has);
VCALL_PARRMEM0(PackedByteArray, uint8_t, sort);
VCALL_PARRMEM0(PackedByteArray, uint8_t, invert);
VCALL_PARRMEM2R(PackedByteArray, uint8_t, subarray);

Expand All @@ -714,6 +716,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedInt32Array, int32_t, remove);
VCALL_PARRMEM1(PackedInt32Array, int32_t, append);
VCALL_PARRMEM1(PackedInt32Array, int32_t, append_array);
VCALL_PARRMEM1R(PackedInt32Array, int32_t, has);
VCALL_PARRMEM0(PackedInt32Array, int32_t, sort);
VCALL_PARRMEM0(PackedInt32Array, int32_t, invert);

VCALL_PARRMEM0R(PackedInt64Array, int64_t, size);
Expand All @@ -726,6 +730,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedInt64Array, int64_t, remove);
VCALL_PARRMEM1(PackedInt64Array, int64_t, append);
VCALL_PARRMEM1(PackedInt64Array, int64_t, append_array);
VCALL_PARRMEM1R(PackedInt64Array, int64_t, has);
VCALL_PARRMEM0(PackedInt64Array, int64_t, sort);
VCALL_PARRMEM0(PackedInt64Array, int64_t, invert);

VCALL_PARRMEM0R(PackedFloat32Array, float, size);
Expand All @@ -738,6 +744,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedFloat32Array, float, remove);
VCALL_PARRMEM1(PackedFloat32Array, float, append);
VCALL_PARRMEM1(PackedFloat32Array, float, append_array);
VCALL_PARRMEM1R(PackedFloat32Array, float, has);
VCALL_PARRMEM0(PackedFloat32Array, float, sort);
VCALL_PARRMEM0(PackedFloat32Array, float, invert);

VCALL_PARRMEM0R(PackedFloat64Array, double, size);
Expand All @@ -750,6 +758,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedFloat64Array, double, remove);
VCALL_PARRMEM1(PackedFloat64Array, double, append);
VCALL_PARRMEM1(PackedFloat64Array, double, append_array);
VCALL_PARRMEM1R(PackedFloat64Array, double, has);
VCALL_PARRMEM0(PackedFloat64Array, double, sort);
VCALL_PARRMEM0(PackedFloat64Array, double, invert);

VCALL_PARRMEM0R(PackedStringArray, String, size);
Expand All @@ -762,6 +772,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedStringArray, String, remove);
VCALL_PARRMEM1(PackedStringArray, String, append);
VCALL_PARRMEM1(PackedStringArray, String, append_array);
VCALL_PARRMEM1R(PackedStringArray, String, has);
VCALL_PARRMEM0(PackedStringArray, String, sort);
VCALL_PARRMEM0(PackedStringArray, String, invert);

VCALL_PARRMEM0R(PackedVector2Array, Vector2, size);
Expand All @@ -774,6 +786,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedVector2Array, Vector2, remove);
VCALL_PARRMEM1(PackedVector2Array, Vector2, append);
VCALL_PARRMEM1(PackedVector2Array, Vector2, append_array);
VCALL_PARRMEM1R(PackedVector2Array, Vector2, has);
VCALL_PARRMEM0(PackedVector2Array, Vector2, sort);
VCALL_PARRMEM0(PackedVector2Array, Vector2, invert);

VCALL_PARRMEM0R(PackedVector3Array, Vector3, size);
Expand All @@ -786,6 +800,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedVector3Array, Vector3, remove);
VCALL_PARRMEM1(PackedVector3Array, Vector3, append);
VCALL_PARRMEM1(PackedVector3Array, Vector3, append_array);
VCALL_PARRMEM1R(PackedVector3Array, Vector3, has);
VCALL_PARRMEM0(PackedVector3Array, Vector3, sort);
VCALL_PARRMEM0(PackedVector3Array, Vector3, invert);

VCALL_PARRMEM0R(PackedColorArray, Color, size);
Expand All @@ -798,6 +814,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedColorArray, Color, remove);
VCALL_PARRMEM1(PackedColorArray, Color, append);
VCALL_PARRMEM1(PackedColorArray, Color, append_array);
VCALL_PARRMEM1R(PackedColorArray, Color, has);
VCALL_PARRMEM0(PackedColorArray, Color, sort);
VCALL_PARRMEM0(PackedColorArray, Color, invert);

#define VCALL_PTR0(m_type, m_method) \
Expand Down Expand Up @@ -2085,6 +2103,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_BYTE_ARRAY, INT, PackedByteArray, insert, INT, "idx", INT, "byte", varray());
ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_BYTE_ARRAY, BOOL, PackedByteArray, has, INT, "value", varray());
ADDFUNC0(PACKED_BYTE_ARRAY, NIL, PackedByteArray, sort, varray());
ADDFUNC0(PACKED_BYTE_ARRAY, NIL, PackedByteArray, invert, varray());
ADDFUNC2R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, subarray, INT, "from", INT, "to", varray());

Expand All @@ -2103,6 +2123,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_INT32_ARRAY, INT, PackedInt32Array, insert, INT, "idx", INT, "integer", varray());
ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_INT32_ARRAY, BOOL, PackedInt32Array, has, INT, "value", varray());
ADDFUNC0(PACKED_INT32_ARRAY, NIL, PackedInt32Array, sort, varray());
ADDFUNC0(PACKED_INT32_ARRAY, NIL, PackedInt32Array, invert, varray());

ADDFUNC0R(PACKED_INT64_ARRAY, INT, PackedInt64Array, size, varray());
Expand All @@ -2114,6 +2136,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_INT64_ARRAY, INT, PackedInt64Array, insert, INT, "idx", INT, "integer", varray());
ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_INT64_ARRAY, BOOL, PackedInt64Array, has, INT, "value", varray());
ADDFUNC0(PACKED_INT64_ARRAY, NIL, PackedInt64Array, sort, varray());
ADDFUNC0(PACKED_INT64_ARRAY, NIL, PackedInt64Array, invert, varray());

ADDFUNC0R(PACKED_FLOAT32_ARRAY, INT, PackedFloat32Array, size, varray());
Expand All @@ -2125,6 +2149,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_FLOAT32_ARRAY, INT, PackedFloat32Array, insert, INT, "idx", FLOAT, "value", varray());
ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_FLOAT32_ARRAY, BOOL, PackedFloat32Array, has, FLOAT, "value", varray());
ADDFUNC0(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, sort, varray());
ADDFUNC0(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, invert, varray());

ADDFUNC0R(PACKED_FLOAT64_ARRAY, INT, PackedFloat64Array, size, varray());
Expand All @@ -2136,6 +2162,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_FLOAT64_ARRAY, INT, PackedFloat64Array, insert, INT, "idx", FLOAT, "value", varray());
ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_FLOAT64_ARRAY, BOOL, PackedFloat64Array, has, FLOAT, "value", varray());
ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, sort, varray());
ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, invert, varray());

ADDFUNC0R(PACKED_STRING_ARRAY, INT, PackedStringArray, size, varray());
Expand All @@ -2147,6 +2175,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_STRING_ARRAY, INT, PackedStringArray, insert, INT, "idx", STRING, "string", varray());
ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_STRING_ARRAY, BOOL, PackedStringArray, has, STRING, "value", varray());
ADDFUNC0(PACKED_STRING_ARRAY, NIL, PackedStringArray, sort, varray());
ADDFUNC0(PACKED_STRING_ARRAY, NIL, PackedStringArray, invert, varray());

ADDFUNC0R(PACKED_VECTOR2_ARRAY, INT, PackedVector2Array, size, varray());
Expand All @@ -2158,6 +2188,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_VECTOR2_ARRAY, INT, PackedVector2Array, insert, INT, "idx", VECTOR2, "vector2", varray());
ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_VECTOR2_ARRAY, BOOL, PackedVector2Array, has, VECTOR2, "value", varray());
ADDFUNC0(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, sort, varray());
ADDFUNC0(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, invert, varray());

ADDFUNC0R(PACKED_VECTOR3_ARRAY, INT, PackedVector3Array, size, varray());
Expand All @@ -2169,6 +2201,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_VECTOR3_ARRAY, INT, PackedVector3Array, insert, INT, "idx", VECTOR3, "vector3", varray());
ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_VECTOR3_ARRAY, BOOL, PackedVector3Array, has, VECTOR3, "value", varray());
ADDFUNC0(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, sort, varray());
ADDFUNC0(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, invert, varray());

ADDFUNC0R(PACKED_COLOR_ARRAY, INT, PackedColorArray, size, varray());
Expand All @@ -2180,6 +2214,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_COLOR_ARRAY, INT, PackedColorArray, insert, INT, "idx", COLOR, "color", varray());
ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, resize, INT, "idx", varray());
ADDFUNC1R(PACKED_COLOR_ARRAY, BOOL, PackedColorArray, has, COLOR, "value", varray());
ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, sort, varray());
ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, invert, varray());

//pointerbased
Expand Down
4 changes: 4 additions & 0 deletions core/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class Vector {

void append_array(Vector<T> p_other);

bool has(const T &p_val) {
return find(p_val, 0) != -1;
}

template <class C>
void sort_custom() {
int len = _cowdata.size();
Expand Down
16 changes: 16 additions & 0 deletions doc/classes/PackedByteArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
Returns a copy of the array's contents as [String]. Slower than [method get_string_from_ascii] but supports UTF-8 encoded data. Use this function if you are unsure about the source of the data. For user input this function should always be preferred.
</description>
</method>
<method name="has">
<return type="bool">
</return>
<argument index="0" name="value" type="int">
</argument>
<description>
Returns [code]true[/code] if the array contains [code]value[/code].
</description>
</method>
<method name="hex_encode">
<return type="String">
</return>
Expand Down Expand Up @@ -152,6 +161,13 @@
Returns the size of the array.
</description>
</method>
<method name="sort">
<return type="void">
</return>
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
<method name="subarray">
<return type="PackedByteArray">
</return>
Expand Down
16 changes: 16 additions & 0 deletions doc/classes/PackedColorArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="has">
<return type="bool">
</return>
<argument index="0" name="value" type="Color">
</argument>
<description>
Returns [code]true[/code] if the array contains [code]value[/code].
</description>
</method>
<method name="insert">
<return type="int">
</return>
Expand Down Expand Up @@ -107,6 +116,13 @@
Returns the size of the array.
</description>
</method>
<method name="sort">
<return type="void">
</return>
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>
Expand Down
16 changes: 16 additions & 0 deletions doc/classes/PackedFloat32Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="has">
<return type="bool">
</return>
<argument index="0" name="value" type="float">
</argument>
<description>
Returns [code]true[/code] if the array contains [code]value[/code].
</description>
</method>
<method name="insert">
<return type="int">
</return>
Expand Down Expand Up @@ -108,6 +117,13 @@
Returns the size of the array.
</description>
</method>
<method name="sort">
<return type="void">
</return>
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>
Expand Down
16 changes: 16 additions & 0 deletions doc/classes/PackedFloat64Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="has">
<return type="bool">
</return>
<argument index="0" name="value" type="float">
</argument>
<description>
Returns [code]true[/code] if the array contains [code]value[/code].
</description>
</method>
<method name="insert">
<return type="int">
</return>
Expand Down Expand Up @@ -108,6 +117,13 @@
Returns the size of the array.
</description>
</method>
<method name="sort">
<return type="void">
</return>
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>
Expand Down
16 changes: 16 additions & 0 deletions doc/classes/PackedInt32Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="has">
<return type="bool">
</return>
<argument index="0" name="value" type="int">
</argument>
<description>
Returns [code]true[/code] if the array contains [code]value[/code].
</description>
</method>
<method name="insert">
<return type="int">
</return>
Expand Down Expand Up @@ -108,6 +117,13 @@
Returns the array size.
</description>
</method>
<method name="sort">
<return type="void">
</return>
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>
Expand Down
16 changes: 16 additions & 0 deletions doc/classes/PackedInt64Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="has">
<return type="bool">
</return>
<argument index="0" name="value" type="int">
</argument>
<description>
Returns [code]true[/code] if the array contains [code]value[/code].
</description>
</method>
<method name="insert">
<return type="int">
</return>
Expand Down Expand Up @@ -108,6 +117,13 @@
Returns the array size.
</description>
</method>
<method name="sort">
<return type="void">
</return>
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>
Expand Down
16 changes: 16 additions & 0 deletions doc/classes/PackedStringArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="has">
<return type="bool">
</return>
<argument index="0" name="value" type="String">
</argument>
<description>
Returns [code]true[/code] if the array contains [code]value[/code].
</description>
</method>
<method name="insert">
<return type="int">
</return>
Expand Down Expand Up @@ -107,6 +116,13 @@
Returns the size of the array.
</description>
</method>
<method name="sort">
<return type="void">
</return>
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>
Expand Down
Loading

0 comments on commit af80bcd

Please sign in to comment.