From c48a3056e4572f6bab08a1fe65cf322a599d8c21 Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 31 May 2024 21:15:16 +0200 Subject: [PATCH] feat: added util_functions --- util_functions.cpp | 1 + util_functions.hpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 util_functions.cpp create mode 100644 util_functions.hpp diff --git a/util_functions.cpp b/util_functions.cpp new file mode 100644 index 0000000..bdcca96 --- /dev/null +++ b/util_functions.cpp @@ -0,0 +1 @@ +#include "util_functions.hpp" diff --git a/util_functions.hpp b/util_functions.hpp new file mode 100644 index 0000000..1b74883 --- /dev/null +++ b/util_functions.hpp @@ -0,0 +1,24 @@ +#ifndef UTILS_FUNCTIONS_HPP +#define UTILS_FUNCTIONS_HPP + +#include +#include + +template +gd::Dictionary hashmap_to_dictionary(gd::HashMap const &map) { + gd::Dictionary dict{}; + for(gd::KeyValue const &kvp : map) + dict[kvp.key] = kvp.value; + return dict; +} + +template +gd::HashMap dictionary_to_hashmap(gd::Dictionary const &dict) { + gd::HashMap map{}; + gd::Array keys{dict.keys()}; + for(size_t i = 0; i < keys.size(); ++i) + map.insert(keys[i], dict[keys[i]]); + return map; +} + +#endif // !UTILS_FUNCTIONS_HPP