| 1 | /**************************************************************************/ | 
| 2 | /*  gltf_template_convert.h                                               */ | 
| 3 | /**************************************************************************/ | 
| 4 | /*                         This file is part of:                          */ | 
| 5 | /*                             GODOT ENGINE                               */ | 
| 6 | /*                        https://godotengine.org                         */ | 
| 7 | /**************************************************************************/ | 
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
| 10 | /*                                                                        */ | 
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
| 12 | /* a copy of this software and associated documentation files (the        */ | 
| 13 | /* "Software"), to deal in the Software without restriction, including    */ | 
| 14 | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
| 16 | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
| 17 | /* the following conditions:                                              */ | 
| 18 | /*                                                                        */ | 
| 19 | /* The above copyright notice and this permission notice shall be         */ | 
| 20 | /* included in all copies or substantial portions of the Software.        */ | 
| 21 | /*                                                                        */ | 
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
| 29 | /**************************************************************************/ | 
| 30 |  | 
| 31 | #ifndef GLTF_TEMPLATE_CONVERT_H | 
| 32 | #define GLTF_TEMPLATE_CONVERT_H | 
| 33 |  | 
| 34 | #include "core/templates/hash_set.h" | 
| 35 | #include "core/variant/array.h" | 
| 36 | #include "core/variant/dictionary.h" | 
| 37 |  | 
| 38 | namespace GLTFTemplateConvert { | 
| 39 | template <class T> | 
| 40 | static Array to_array(const Vector<T> &p_inp) { | 
| 41 | 	Array ret; | 
| 42 | 	for (int i = 0; i < p_inp.size(); i++) { | 
| 43 | 		ret.push_back(p_inp[i]); | 
| 44 | 	} | 
| 45 | 	return ret; | 
| 46 | } | 
| 47 |  | 
| 48 | template <class T> | 
| 49 | static TypedArray<T> to_array(const HashSet<T> &p_inp) { | 
| 50 | 	TypedArray<T> ret; | 
| 51 | 	typename HashSet<T>::Iterator elem = p_inp.begin(); | 
| 52 | 	while (elem) { | 
| 53 | 		ret.push_back(*elem); | 
| 54 | 		++elem; | 
| 55 | 	} | 
| 56 | 	return ret; | 
| 57 | } | 
| 58 |  | 
| 59 | template <class T> | 
| 60 | static void set_from_array(Vector<T> &r_out, const Array &p_inp) { | 
| 61 | 	r_out.clear(); | 
| 62 | 	for (int i = 0; i < p_inp.size(); i++) { | 
| 63 | 		r_out.push_back(p_inp[i]); | 
| 64 | 	} | 
| 65 | } | 
| 66 |  | 
| 67 | template <class T> | 
| 68 | static void set_from_array(HashSet<T> &r_out, const TypedArray<T> &p_inp) { | 
| 69 | 	r_out.clear(); | 
| 70 | 	for (int i = 0; i < p_inp.size(); i++) { | 
| 71 | 		r_out.insert(p_inp[i]); | 
| 72 | 	} | 
| 73 | } | 
| 74 |  | 
| 75 | template <class K, class V> | 
| 76 | static Dictionary to_dict(const HashMap<K, V> &p_inp) { | 
| 77 | 	Dictionary ret; | 
| 78 | 	for (const KeyValue<K, V> &E : p_inp) { | 
| 79 | 		ret[E.key] = E.value; | 
| 80 | 	} | 
| 81 | 	return ret; | 
| 82 | } | 
| 83 |  | 
| 84 | template <class K, class V> | 
| 85 | static void set_from_dict(HashMap<K, V> &r_out, const Dictionary &p_inp) { | 
| 86 | 	r_out.clear(); | 
| 87 | 	Array keys = p_inp.keys(); | 
| 88 | 	for (int i = 0; i < keys.size(); i++) { | 
| 89 | 		r_out[keys[i]] = p_inp[keys[i]]; | 
| 90 | 	} | 
| 91 | } | 
| 92 | } //namespace GLTFTemplateConvert | 
| 93 |  | 
| 94 | #endif // GLTF_TEMPLATE_CONVERT_H | 
| 95 |  |