gltf_template_convert.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #ifndef GLTF_TEMPLATE_CONVERT_H
  31. #define GLTF_TEMPLATE_CONVERT_H
  32. #include "core/array.h"
  33. #include "core/dictionary.h"
  34. #include "core/set.h"
  35. namespace GLTFTemplateConvert {
  36. template <class T>
  37. static Array to_array(const Vector<T> &p_inp) {
  38. Array ret;
  39. for (int i = 0; i < p_inp.size(); i++) {
  40. ret.push_back(p_inp[i]);
  41. }
  42. return ret;
  43. }
  44. template <class T>
  45. static Array to_array(const Set<T> &p_inp) {
  46. Array ret;
  47. typename Set<T>::Element *elem = p_inp.front();
  48. while (elem) {
  49. ret.push_back(elem->get());
  50. elem = elem->next();
  51. }
  52. return ret;
  53. }
  54. template <class T>
  55. static void set_from_array(Vector<T> &r_out, const Array &p_inp) {
  56. r_out.clear();
  57. for (int i = 0; i < p_inp.size(); i++) {
  58. r_out.push_back(p_inp[i]);
  59. }
  60. }
  61. template <class T>
  62. static void set_from_array(Set<T> &r_out, const Array &p_inp) {
  63. r_out.clear();
  64. for (int i = 0; i < p_inp.size(); i++) {
  65. r_out.insert(p_inp[i]);
  66. }
  67. }
  68. template <class K, class V>
  69. static Dictionary to_dict(const Map<K, V> &p_inp) {
  70. Dictionary ret;
  71. for (typename Map<K, V>::Element *E = p_inp.front(); E; E = E->next()) {
  72. ret[E->key()] = E->value();
  73. }
  74. return ret;
  75. }
  76. template <class K, class V>
  77. static void set_from_dict(Map<K, V> &r_out, const Dictionary &p_inp) {
  78. r_out.clear();
  79. Array keys = p_inp.keys();
  80. for (int i = 0; i < keys.size(); i++) {
  81. r_out[keys[i]] = p_inp[keys[i]];
  82. }
  83. }
  84. } //namespace GLTFTemplateConvert
  85. #endif // GLTF_TEMPLATE_CONVERT_H