Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gltf/gltf_template_convert.h
10277 views
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
#pragma once
32
33
#include "core/templates/hash_set.h"
34
#include "core/variant/array.h"
35
#include "core/variant/dictionary.h"
36
#include "core/variant/typed_array.h"
37
38
namespace GLTFTemplateConvert {
39
template <typename 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 <typename 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 <typename 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 <typename 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 <typename K, typename V>
76
static Dictionary to_dictionary(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 <typename K, typename V>
85
static void set_from_dictionary(HashMap<K, V> &r_out, const Dictionary &p_inp) {
86
r_out.clear();
87
for (const KeyValue<Variant, Variant> &kv : p_inp) {
88
r_out[kv.key] = kv.value;
89
}
90
}
91
} //namespace GLTFTemplateConvert
92
93