- exposed Append() method to ZScript dynamic array

https://forum.zdoom.org/viewtopic.php?t=65570
This commit is contained in:
alexey.lysiuk 2019-08-10 16:30:25 +03:00
parent 34c2c65bb6
commit 07a2331ca3
2 changed files with 83 additions and 6 deletions

View file

@ -54,12 +54,6 @@ typedef TArray<void*> FDynArray_Ptr;
typedef TArray<DObject*> FDynArray_Obj; typedef TArray<DObject*> FDynArray_Obj;
typedef TArray<FString> FDynArray_String; typedef TArray<FString> FDynArray_String;
//-----------------------------------------------------
//
// Int8 array
//
//-----------------------------------------------------
template<class T> void ArrayCopy(T *self, T *other) template<class T> void ArrayCopy(T *self, T *other)
{ {
*self = *other; *self = *other;
@ -70,6 +64,11 @@ template<class T> void ArrayMove(T *self, T* other)
*self = std::move(*other); *self = std::move(*other);
} }
template<class T> void ArrayAppend(T *self, const T *other)
{
self->Append(*other);
}
template<class T, class U> int ArrayFind(T *self, U val) template<class T, class U> int ArrayFind(T *self, U val)
{ {
return self->Find(static_cast<typename T::value_type>(val)); return self->Find(static_cast<typename T::value_type>(val));
@ -139,6 +138,12 @@ template<class T> void ArrayClear(T *self)
// without this the two-argument templates cannot be used in macros. // without this the two-argument templates cannot be used in macros.
#define COMMA , #define COMMA ,
//-----------------------------------------------------
//
// Int8 array
//
//-----------------------------------------------------
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Copy, ArrayCopy<FDynArray_I8>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Copy, ArrayCopy<FDynArray_I8>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I8); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I8);
@ -155,6 +160,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Move, ArrayMove<FDynArray_I8>)
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Append, ArrayAppend<FDynArray_I8>)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I8);
PARAM_POINTER(other, FDynArray_I8);
self->Append(*other);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Find, ArrayFind<FDynArray_I8 COMMA int>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Find, ArrayFind<FDynArray_I8 COMMA int>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I8); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I8);
@ -258,6 +271,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I16, Move, ArrayMove<FDynArray_I16>)
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I16, Append, ArrayAppend<FDynArray_I16>)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I16);
PARAM_POINTER(other, FDynArray_I16);
self->Append(*other);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I16, Find, ArrayFind<FDynArray_I16 COMMA int>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I16, Find, ArrayFind<FDynArray_I16 COMMA int>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I16); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I16);
@ -361,6 +382,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I32, Move, ArrayMove<FDynArray_I32>)
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I32, Append, ArrayAppend<FDynArray_I32>)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I32);
PARAM_POINTER(other, FDynArray_I32);
self->Append(*other);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I32, Find, ArrayFind<FDynArray_I32 COMMA int>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I32, Find, ArrayFind<FDynArray_I32 COMMA int>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I32); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I32);
@ -464,6 +493,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F32, Move, ArrayMove<FDynArray_F32>)
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F32, Append, ArrayAppend<FDynArray_F32>)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F32);
PARAM_POINTER(other, FDynArray_F32);
self->Append(*other);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F32, Find, ArrayFind<FDynArray_F32 COMMA double>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F32, Find, ArrayFind<FDynArray_F32 COMMA double>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F32); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F32);
@ -567,6 +604,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F64, Move, ArrayMove<FDynArray_F64>)
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F64, Append, ArrayAppend<FDynArray_F64>)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F64);
PARAM_POINTER(other, FDynArray_F64);
self->Append(*other);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F64, Find, ArrayFind<FDynArray_F64 COMMA double>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F64, Find, ArrayFind<FDynArray_F64 COMMA double>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F64); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F64);
@ -670,6 +715,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Ptr, Move, ArrayMove<FDynArray_Ptr>)
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Ptr, Append, ArrayAppend<FDynArray_Ptr>)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Ptr);
PARAM_POINTER(other, FDynArray_Ptr);
self->Append(*other);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Ptr, Find, ArrayFind<FDynArray_Ptr COMMA void*>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Ptr, Find, ArrayFind<FDynArray_Ptr COMMA void*>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Ptr); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Ptr);
@ -774,6 +827,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Move, ArrayMove<FDynArray_Obj>)
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Append, ArrayAppend<FDynArray_Obj>)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_POINTER(other, FDynArray_Obj);
self->Append(*other);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Find, ArrayFind<FDynArray_Obj COMMA DObject*>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Find, ArrayFind<FDynArray_Obj COMMA DObject*>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
@ -890,6 +951,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_String, Move, ArrayMove<FDynArray_String
return 0; return 0;
} }
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_String, Append, ArrayAppend<FDynArray_String>)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_String);
PARAM_POINTER(other, FDynArray_String);
self->Append(*other);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_String, Find, ArrayFind<FDynArray_String COMMA const FString &>) DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_String, Find, ArrayFind<FDynArray_String COMMA const FString &>)
{ {
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_String); PARAM_SELF_STRUCT_PROLOGUE(FDynArray_String);

View file

@ -7,6 +7,7 @@ struct DynArray_I8 native
native void Copy(DynArray_I8 other); native void Copy(DynArray_I8 other);
native void Move(DynArray_I8 other); native void Move(DynArray_I8 other);
native void Append (DynArray_I8 other);
native uint Find(int item) const; native uint Find(int item) const;
native uint Push (int item); native uint Push (int item);
native bool Pop (); native bool Pop ();
@ -26,6 +27,7 @@ struct DynArray_I16 native
native void Copy(DynArray_I16 other); native void Copy(DynArray_I16 other);
native void Move(DynArray_I16 other); native void Move(DynArray_I16 other);
native void Append (DynArray_I16 other);
native uint Find(int item) const; native uint Find(int item) const;
native uint Push (int item); native uint Push (int item);
native bool Pop (); native bool Pop ();
@ -45,6 +47,7 @@ struct DynArray_I32 native
native void Copy(DynArray_I32 other); native void Copy(DynArray_I32 other);
native void Move(DynArray_I32 other); native void Move(DynArray_I32 other);
native void Append (DynArray_I32 other);
native uint Find(int item) const; native uint Find(int item) const;
native uint Push (int item); native uint Push (int item);
native bool Pop (); native bool Pop ();
@ -64,6 +67,7 @@ struct DynArray_F32 native
native void Copy(DynArray_F32 other); native void Copy(DynArray_F32 other);
native void Move(DynArray_F32 other); native void Move(DynArray_F32 other);
native void Append (DynArray_F32 other);
native uint Find(double item) const; native uint Find(double item) const;
native uint Push (double item); native uint Push (double item);
native bool Pop (); native bool Pop ();
@ -83,6 +87,7 @@ struct DynArray_F64 native
native void Copy(DynArray_F64 other); native void Copy(DynArray_F64 other);
native void Move(DynArray_F64 other); native void Move(DynArray_F64 other);
native void Append (DynArray_F64 other);
native uint Find(double item) const; native uint Find(double item) const;
native uint Push (double item); native uint Push (double item);
native bool Pop (); native bool Pop ();
@ -102,6 +107,7 @@ struct DynArray_Ptr native
native void Copy(DynArray_Ptr other); native void Copy(DynArray_Ptr other);
native void Move(DynArray_Ptr other); native void Move(DynArray_Ptr other);
native void Append (DynArray_Ptr other);
native uint Find(voidptr item) const; native uint Find(voidptr item) const;
native uint Push (voidptr item); native uint Push (voidptr item);
native bool Pop (); native bool Pop ();
@ -121,6 +127,7 @@ struct DynArray_Obj native
native void Copy(DynArray_Obj other); native void Copy(DynArray_Obj other);
native void Move(DynArray_Obj other); native void Move(DynArray_Obj other);
native void Append (DynArray_Obj other);
native uint Find(Object item) const; native uint Find(Object item) const;
native uint Push (Object item); native uint Push (Object item);
native bool Pop (); native bool Pop ();
@ -140,6 +147,7 @@ struct DynArray_String native
native void Copy(DynArray_String other); native void Copy(DynArray_String other);
native void Move(DynArray_String other); native void Move(DynArray_String other);
native void Append (DynArray_String other);
native uint Find(String item) const; native uint Find(String item) const;
native uint Push (String item); native uint Push (String item);
native bool Pop (); native bool Pop ();