From 00f089d7edafa53a5018054f9662a36a695ad8b9 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Wed, 17 Jan 2018 01:57:01 +0100 Subject: [PATCH] Added copy constructors and assignment operators to Array and Dictionary --- include/core/Array.hpp | 2 ++ include/core/Dictionary.hpp | 2 ++ src/core/Array.cpp | 12 ++++++++++++ src/core/Dictionary.cpp | 12 ++++++++++++ 4 files changed, 28 insertions(+) diff --git a/include/core/Array.hpp b/include/core/Array.hpp index 20057402..23205686 100644 --- a/include/core/Array.hpp +++ b/include/core/Array.hpp @@ -22,6 +22,8 @@ class Array { godot_array _godot_array; public: Array(); + Array(const Array & other); + Array & operator=(const Array & other); Array(const PoolByteArray& a); diff --git a/include/core/Dictionary.hpp b/include/core/Dictionary.hpp index 238724de..ec496af6 100644 --- a/include/core/Dictionary.hpp +++ b/include/core/Dictionary.hpp @@ -13,6 +13,8 @@ class Dictionary { godot_dictionary _godot_dictionary; public: Dictionary(); + Dictionary(const Dictionary & other); + Dictionary & operator=(const Dictionary & other); void clear(); diff --git a/src/core/Array.cpp b/src/core/Array.cpp index c3de16c7..03505478 100644 --- a/src/core/Array.cpp +++ b/src/core/Array.cpp @@ -13,6 +13,18 @@ Array::Array() godot::api->godot_array_new(&_godot_array); } +Array::Array(const Array & other) +{ + godot::api->godot_array_new_copy(&_godot_array, &other._godot_array); +} + +Array & Array::operator=(const Array & other) +{ + godot::api->godot_array_destroy(&_godot_array); + godot::api->godot_array_new_copy(&_godot_array, &other._godot_array); + return *this; +} + Array::Array(const PoolByteArray& a) { godot::api->godot_array_new_pool_byte_array(&_godot_array, (godot_pool_byte_array *) &a); diff --git a/src/core/Dictionary.cpp b/src/core/Dictionary.cpp index aba226c9..bb400176 100644 --- a/src/core/Dictionary.cpp +++ b/src/core/Dictionary.cpp @@ -10,6 +10,18 @@ Dictionary::Dictionary() godot::api->godot_dictionary_new(&_godot_dictionary); } +Dictionary::Dictionary(const Dictionary & other) +{ + godot::api->godot_dictionary_new_copy(&_godot_dictionary, &other._godot_dictionary); +} + +Dictionary & Dictionary::operator=(const Dictionary & other) +{ + godot::api->godot_dictionary_destroy(&_godot_dictionary); + godot::api->godot_dictionary_new_copy(&_godot_dictionary, &other._godot_dictionary); + return *this; +} + void Dictionary::clear() { godot::api->godot_dictionary_clear(&_godot_dictionary);