packed_arrays.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /**************************************************************************/
  2. /* packed_arrays.cpp */
  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. // extra functions for packed arrays
  31. #include <godot_cpp/godot.hpp>
  32. #include <godot_cpp/variant/array.hpp>
  33. #include <godot_cpp/variant/dictionary.hpp>
  34. #include <godot_cpp/variant/packed_byte_array.hpp>
  35. #include <godot_cpp/variant/packed_color_array.hpp>
  36. #include <godot_cpp/variant/packed_float32_array.hpp>
  37. #include <godot_cpp/variant/packed_float64_array.hpp>
  38. #include <godot_cpp/variant/packed_int32_array.hpp>
  39. #include <godot_cpp/variant/packed_int64_array.hpp>
  40. #include <godot_cpp/variant/packed_string_array.hpp>
  41. #include <godot_cpp/variant/packed_vector2_array.hpp>
  42. #include <godot_cpp/variant/packed_vector3_array.hpp>
  43. #include <godot_cpp/variant/packed_vector4_array.hpp>
  44. namespace godot {
  45. const uint8_t &PackedByteArray::operator[](int64_t p_index) const {
  46. return *::godot::gdextension_interface::packed_byte_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  47. }
  48. uint8_t &PackedByteArray::operator[](int64_t p_index) {
  49. return *::godot::gdextension_interface::packed_byte_array_operator_index((GDExtensionTypePtr *)this, p_index);
  50. }
  51. const uint8_t *PackedByteArray::ptr() const {
  52. return ::godot::gdextension_interface::packed_byte_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  53. }
  54. uint8_t *PackedByteArray::ptrw() {
  55. return ::godot::gdextension_interface::packed_byte_array_operator_index((GDExtensionTypePtr *)this, 0);
  56. }
  57. const Color &PackedColorArray::operator[](int64_t p_index) const {
  58. const Color *color = (const Color *)::godot::gdextension_interface::packed_color_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  59. return *color;
  60. }
  61. Color &PackedColorArray::operator[](int64_t p_index) {
  62. Color *color = (Color *)::godot::gdextension_interface::packed_color_array_operator_index((GDExtensionTypePtr *)this, p_index);
  63. return *color;
  64. }
  65. const Color *PackedColorArray::ptr() const {
  66. return (const Color *)::godot::gdextension_interface::packed_color_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  67. }
  68. Color *PackedColorArray::ptrw() {
  69. return (Color *)::godot::gdextension_interface::packed_color_array_operator_index((GDExtensionTypePtr *)this, 0);
  70. }
  71. const float &PackedFloat32Array::operator[](int64_t p_index) const {
  72. return *::godot::gdextension_interface::packed_float32_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  73. }
  74. float &PackedFloat32Array::operator[](int64_t p_index) {
  75. return *::godot::gdextension_interface::packed_float32_array_operator_index((GDExtensionTypePtr *)this, p_index);
  76. }
  77. const float *PackedFloat32Array::ptr() const {
  78. return ::godot::gdextension_interface::packed_float32_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  79. }
  80. float *PackedFloat32Array::ptrw() {
  81. return ::godot::gdextension_interface::packed_float32_array_operator_index((GDExtensionTypePtr *)this, 0);
  82. }
  83. const double &PackedFloat64Array::operator[](int64_t p_index) const {
  84. return *::godot::gdextension_interface::packed_float64_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  85. }
  86. double &PackedFloat64Array::operator[](int64_t p_index) {
  87. return *::godot::gdextension_interface::packed_float64_array_operator_index((GDExtensionTypePtr *)this, p_index);
  88. }
  89. const double *PackedFloat64Array::ptr() const {
  90. return ::godot::gdextension_interface::packed_float64_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  91. }
  92. double *PackedFloat64Array::ptrw() {
  93. return ::godot::gdextension_interface::packed_float64_array_operator_index((GDExtensionTypePtr *)this, 0);
  94. }
  95. const int32_t &PackedInt32Array::operator[](int64_t p_index) const {
  96. return *::godot::gdextension_interface::packed_int32_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  97. }
  98. int32_t &PackedInt32Array::operator[](int64_t p_index) {
  99. return *::godot::gdextension_interface::packed_int32_array_operator_index((GDExtensionTypePtr *)this, p_index);
  100. }
  101. const int32_t *PackedInt32Array::ptr() const {
  102. return ::godot::gdextension_interface::packed_int32_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  103. }
  104. int32_t *PackedInt32Array::ptrw() {
  105. return ::godot::gdextension_interface::packed_int32_array_operator_index((GDExtensionTypePtr *)this, 0);
  106. }
  107. const int64_t &PackedInt64Array::operator[](int64_t p_index) const {
  108. return *::godot::gdextension_interface::packed_int64_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  109. }
  110. int64_t &PackedInt64Array::operator[](int64_t p_index) {
  111. return *::godot::gdextension_interface::packed_int64_array_operator_index((GDExtensionTypePtr *)this, p_index);
  112. }
  113. const int64_t *PackedInt64Array::ptr() const {
  114. return ::godot::gdextension_interface::packed_int64_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  115. }
  116. int64_t *PackedInt64Array::ptrw() {
  117. return ::godot::gdextension_interface::packed_int64_array_operator_index((GDExtensionTypePtr *)this, 0);
  118. }
  119. const String &PackedStringArray::operator[](int64_t p_index) const {
  120. const String *string = (const String *)::godot::gdextension_interface::packed_string_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  121. return *string;
  122. }
  123. String &PackedStringArray::operator[](int64_t p_index) {
  124. String *string = (String *)::godot::gdextension_interface::packed_string_array_operator_index((GDExtensionTypePtr *)this, p_index);
  125. return *string;
  126. }
  127. const String *PackedStringArray::ptr() const {
  128. return (const String *)::godot::gdextension_interface::packed_string_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  129. }
  130. String *PackedStringArray::ptrw() {
  131. return (String *)::godot::gdextension_interface::packed_string_array_operator_index((GDExtensionTypePtr *)this, 0);
  132. }
  133. const Vector2 &PackedVector2Array::operator[](int64_t p_index) const {
  134. const Vector2 *vec = (const Vector2 *)::godot::gdextension_interface::packed_vector2_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  135. return *vec;
  136. }
  137. Vector2 &PackedVector2Array::operator[](int64_t p_index) {
  138. Vector2 *vec = (Vector2 *)::godot::gdextension_interface::packed_vector2_array_operator_index((GDExtensionTypePtr *)this, p_index);
  139. return *vec;
  140. }
  141. const Vector2 *PackedVector2Array::ptr() const {
  142. return (const Vector2 *)::godot::gdextension_interface::packed_vector2_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  143. }
  144. Vector2 *PackedVector2Array::ptrw() {
  145. return (Vector2 *)::godot::gdextension_interface::packed_vector2_array_operator_index((GDExtensionTypePtr *)this, 0);
  146. }
  147. const Vector3 &PackedVector3Array::operator[](int64_t p_index) const {
  148. const Vector3 *vec = (const Vector3 *)::godot::gdextension_interface::packed_vector3_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  149. return *vec;
  150. }
  151. Vector3 &PackedVector3Array::operator[](int64_t p_index) {
  152. Vector3 *vec = (Vector3 *)::godot::gdextension_interface::packed_vector3_array_operator_index((GDExtensionTypePtr *)this, p_index);
  153. return *vec;
  154. }
  155. const Vector3 *PackedVector3Array::ptr() const {
  156. return (const Vector3 *)::godot::gdextension_interface::packed_vector3_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  157. }
  158. Vector3 *PackedVector3Array::ptrw() {
  159. return (Vector3 *)::godot::gdextension_interface::packed_vector3_array_operator_index((GDExtensionTypePtr *)this, 0);
  160. }
  161. const Vector4 &PackedVector4Array::operator[](int64_t p_index) const {
  162. const Vector4 *vec = (const Vector4 *)::godot::gdextension_interface::packed_vector4_array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  163. return *vec;
  164. }
  165. Vector4 &PackedVector4Array::operator[](int64_t p_index) {
  166. Vector4 *vec = (Vector4 *)::godot::gdextension_interface::packed_vector4_array_operator_index((GDExtensionTypePtr *)this, p_index);
  167. return *vec;
  168. }
  169. const Vector4 *PackedVector4Array::ptr() const {
  170. return (const Vector4 *)::godot::gdextension_interface::packed_vector4_array_operator_index_const((GDExtensionTypePtr *)this, 0);
  171. }
  172. Vector4 *PackedVector4Array::ptrw() {
  173. return (Vector4 *)::godot::gdextension_interface::packed_vector4_array_operator_index((GDExtensionTypePtr *)this, 0);
  174. }
  175. const Variant &Array::operator[](int64_t p_index) const {
  176. const Variant *var = (const Variant *)::godot::gdextension_interface::array_operator_index_const((GDExtensionTypePtr *)this, p_index);
  177. return *var;
  178. }
  179. Variant &Array::operator[](int64_t p_index) {
  180. Variant *var = (Variant *)::godot::gdextension_interface::array_operator_index((GDExtensionTypePtr *)this, p_index);
  181. return *var;
  182. }
  183. void Array::set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script) {
  184. // p_type is not Variant::Type so that header doesn't depend on <variant.hpp>.
  185. ::godot::gdextension_interface::array_set_typed((GDExtensionTypePtr *)this, (GDExtensionVariantType)p_type, (GDExtensionConstStringNamePtr)&p_class_name, (GDExtensionConstVariantPtr)&p_script);
  186. }
  187. const Variant *Array::ptr() const {
  188. return (const Variant *)::godot::gdextension_interface::array_operator_index_const((GDExtensionTypePtr *)this, 0);
  189. }
  190. Variant *Array::ptrw() {
  191. return (Variant *)::godot::gdextension_interface::array_operator_index((GDExtensionTypePtr *)this, 0);
  192. }
  193. const Variant &Dictionary::operator[](const Variant &p_key) const {
  194. const Variant *var = (const Variant *)::godot::gdextension_interface::dictionary_operator_index_const((GDExtensionTypePtr *)this, (GDExtensionVariantPtr)&p_key);
  195. return *var;
  196. }
  197. Variant &Dictionary::operator[](const Variant &p_key) {
  198. Variant *var = (Variant *)::godot::gdextension_interface::dictionary_operator_index((GDExtensionTypePtr *)this, (GDExtensionVariantPtr)&p_key);
  199. return *var;
  200. }
  201. void Dictionary::set_typed(uint32_t p_key_type, const StringName &p_key_class_name, const Variant &p_key_script, uint32_t p_value_type, const StringName &p_value_class_name, const Variant &p_value_script) {
  202. // p_key_type/p_value_type are not Variant::Type so that header doesn't depend on <variant.hpp>.
  203. ::godot::gdextension_interface::dictionary_set_typed((GDExtensionTypePtr *)this, (GDExtensionVariantType)p_key_type, (GDExtensionConstStringNamePtr)&p_key_class_name, (GDExtensionConstVariantPtr)&p_key_script,
  204. (GDExtensionVariantType)p_value_type, (GDExtensionConstStringNamePtr)&p_value_class_name, (GDExtensionConstVariantPtr)&p_value_script);
  205. }
  206. } // namespace godot