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