From 3797f1992609679b39711720fac69079fadf85c1 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Wed, 4 Dec 2019 14:54:33 +0100 Subject: [PATCH] C#: Add Duplicate method to the Array and Dictionary bindings --- modules/mono/glue/Managed/Files/Array.cs | 13 +++++++++++++ modules/mono/glue/Managed/Files/Dictionary.cs | 13 +++++++++++++ modules/mono/glue/collections_glue.cpp | 10 ++++++++++ modules/mono/glue/collections_glue.h | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/modules/mono/glue/Managed/Files/Array.cs b/modules/mono/glue/Managed/Files/Array.cs index 0e7b0362e00..aba10654986 100644 --- a/modules/mono/glue/Managed/Files/Array.cs +++ b/modules/mono/glue/Managed/Files/Array.cs @@ -64,6 +64,11 @@ namespace Godot.Collections return safeHandle.DangerousGetHandle(); } + public Array Duplicate(bool deep = false) + { + return new Array(godot_icall_Array_Duplicate(GetPtr(), deep)); + } + public Error Resize(int newSize) { return godot_icall_Array_Resize(GetPtr(), newSize); @@ -178,6 +183,9 @@ namespace Godot.Collections [MethodImpl(MethodImplOptions.InternalCall)] internal extern static void godot_icall_Array_CopyTo(IntPtr ptr, System.Array array, int arrayIndex); + [MethodImpl(MethodImplOptions.InternalCall)] + internal extern static IntPtr godot_icall_Array_Duplicate(IntPtr ptr, bool deep); + [MethodImpl(MethodImplOptions.InternalCall)] internal extern static int godot_icall_Array_IndexOf(IntPtr ptr, object item); @@ -250,6 +258,11 @@ namespace Godot.Collections return from.objectArray; } + public Array Duplicate(bool deep = false) + { + return new Array(objectArray.Duplicate(deep)); + } + public Error Resize(int newSize) { return objectArray.Resize(newSize); diff --git a/modules/mono/glue/Managed/Files/Dictionary.cs b/modules/mono/glue/Managed/Files/Dictionary.cs index 6ab8549a01a..d72109de927 100644 --- a/modules/mono/glue/Managed/Files/Dictionary.cs +++ b/modules/mono/glue/Managed/Files/Dictionary.cs @@ -80,6 +80,11 @@ namespace Godot.Collections disposed = true; } + public Dictionary Duplicate(bool deep = false) + { + return new Dictionary(godot_icall_Dictionary_Duplicate(GetPtr(), deep)); + } + // IDictionary public ICollection Keys @@ -234,6 +239,9 @@ namespace Godot.Collections [MethodImpl(MethodImplOptions.InternalCall)] internal extern static bool godot_icall_Dictionary_ContainsKey(IntPtr ptr, object key); + [MethodImpl(MethodImplOptions.InternalCall)] + internal extern static IntPtr godot_icall_Dictionary_Duplicate(IntPtr ptr, bool deep); + [MethodImpl(MethodImplOptions.InternalCall)] internal extern static bool godot_icall_Dictionary_RemoveKey(IntPtr ptr, object key); @@ -313,6 +321,11 @@ namespace Godot.Collections return objectDict.GetPtr(); } + public Dictionary Duplicate(bool deep = false) + { + return new Dictionary(objectDict.Duplicate(deep)); + } + // IDictionary public TValue this[TKey key] diff --git a/modules/mono/glue/collections_glue.cpp b/modules/mono/glue/collections_glue.cpp index bfb7b0f7756..e84a5becd67 100644 --- a/modules/mono/glue/collections_glue.cpp +++ b/modules/mono/glue/collections_glue.cpp @@ -103,6 +103,10 @@ void godot_icall_Array_CopyTo(Array *ptr, MonoArray *array, int array_index) { } } +Array *godot_icall_Array_Duplicate(Array *ptr, MonoBoolean deep) { + return memnew(Array(ptr->duplicate(deep))); +} + int godot_icall_Array_IndexOf(Array *ptr, MonoObject *item) { return ptr->find(GDMonoMarshal::mono_object_to_variant(item)); } @@ -224,6 +228,10 @@ MonoBoolean godot_icall_Dictionary_ContainsKey(Dictionary *ptr, MonoObject *key) return ptr->has(GDMonoMarshal::mono_object_to_variant(key)); } +Dictionary *godot_icall_Dictionary_Duplicate(Dictionary *ptr, MonoBoolean deep) { + return memnew(Dictionary(ptr->duplicate(deep))); +} + MonoBoolean godot_icall_Dictionary_RemoveKey(Dictionary *ptr, MonoObject *key) { return ptr->erase(GDMonoMarshal::mono_object_to_variant(key)); } @@ -284,6 +292,7 @@ void godot_register_collections_icalls() { mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Clear", (void *)godot_icall_Array_Clear); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Contains", (void *)godot_icall_Array_Contains); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_CopyTo", (void *)godot_icall_Array_CopyTo); + mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Duplicate", (void *)godot_icall_Array_Duplicate); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_IndexOf", (void *)godot_icall_Array_IndexOf); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Insert", (void *)godot_icall_Array_Insert); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Remove", (void *)godot_icall_Array_Remove); @@ -304,6 +313,7 @@ void godot_register_collections_icalls() { mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Clear", (void *)godot_icall_Dictionary_Clear); mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Contains", (void *)godot_icall_Dictionary_Contains); mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_ContainsKey", (void *)godot_icall_Dictionary_ContainsKey); + mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Duplicate", (void *)godot_icall_Dictionary_Duplicate); mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_RemoveKey", (void *)godot_icall_Dictionary_RemoveKey); mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Remove", (void *)godot_icall_Dictionary_Remove); mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_TryGetValue", (void *)godot_icall_Dictionary_TryGetValue); diff --git a/modules/mono/glue/collections_glue.h b/modules/mono/glue/collections_glue.h index 54ed42c3b6e..a79a651fcdc 100644 --- a/modules/mono/glue/collections_glue.h +++ b/modules/mono/glue/collections_glue.h @@ -59,6 +59,8 @@ MonoBoolean godot_icall_Array_Contains(Array *ptr, MonoObject *item); void godot_icall_Array_CopyTo(Array *ptr, MonoArray *array, int array_index); +Array *godot_icall_Array_Duplicate(Array *ptr, MonoBoolean deep); + int godot_icall_Array_IndexOf(Array *ptr, MonoObject *item); void godot_icall_Array_Insert(Array *ptr, int index, MonoObject *item); @@ -99,6 +101,8 @@ MonoBoolean godot_icall_Dictionary_Contains(Dictionary *ptr, MonoObject *key, Mo MonoBoolean godot_icall_Dictionary_ContainsKey(Dictionary *ptr, MonoObject *key); +Dictionary *godot_icall_Dictionary_Duplicate(Dictionary *ptr, MonoBoolean deep); + MonoBoolean godot_icall_Dictionary_RemoveKey(Dictionary *ptr, MonoObject *key); MonoBoolean godot_icall_Dictionary_Remove(Dictionary *ptr, MonoObject *key, MonoObject *value);