variant_internal.h 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  1. /**************************************************************************/
  2. /* variant_internal.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 VARIANT_INTERNAL_H
  31. #define VARIANT_INTERNAL_H
  32. #include "variant.h"
  33. // For use when you want to access the internal pointer of a Variant directly.
  34. // Use with caution. You need to be sure that the type is correct.
  35. class RefCounted;
  36. class VariantInternal {
  37. friend class Variant;
  38. public:
  39. // Set type.
  40. _FORCE_INLINE_ static void initialize(Variant *v, Variant::Type p_type) {
  41. v->clear();
  42. v->type = p_type;
  43. switch (p_type) {
  44. case Variant::STRING:
  45. init_string(v);
  46. break;
  47. case Variant::TRANSFORM2D:
  48. init_transform2d(v);
  49. break;
  50. case Variant::AABB:
  51. init_aabb(v);
  52. break;
  53. case Variant::BASIS:
  54. init_basis(v);
  55. break;
  56. case Variant::TRANSFORM3D:
  57. init_transform3d(v);
  58. break;
  59. case Variant::PROJECTION:
  60. init_projection(v);
  61. break;
  62. case Variant::COLOR:
  63. init_color(v);
  64. break;
  65. case Variant::STRING_NAME:
  66. init_string_name(v);
  67. break;
  68. case Variant::NODE_PATH:
  69. init_node_path(v);
  70. break;
  71. case Variant::CALLABLE:
  72. init_callable(v);
  73. break;
  74. case Variant::SIGNAL:
  75. init_signal(v);
  76. break;
  77. case Variant::DICTIONARY:
  78. init_dictionary(v);
  79. break;
  80. case Variant::ARRAY:
  81. init_array(v);
  82. break;
  83. case Variant::PACKED_BYTE_ARRAY:
  84. init_byte_array(v);
  85. break;
  86. case Variant::PACKED_INT32_ARRAY:
  87. init_int32_array(v);
  88. break;
  89. case Variant::PACKED_INT64_ARRAY:
  90. init_int64_array(v);
  91. break;
  92. case Variant::PACKED_FLOAT32_ARRAY:
  93. init_float32_array(v);
  94. break;
  95. case Variant::PACKED_FLOAT64_ARRAY:
  96. init_float64_array(v);
  97. break;
  98. case Variant::PACKED_STRING_ARRAY:
  99. init_string_array(v);
  100. break;
  101. case Variant::PACKED_VECTOR2_ARRAY:
  102. init_vector2_array(v);
  103. break;
  104. case Variant::PACKED_VECTOR3_ARRAY:
  105. init_vector3_array(v);
  106. break;
  107. case Variant::PACKED_COLOR_ARRAY:
  108. init_color_array(v);
  109. break;
  110. case Variant::PACKED_VECTOR4_ARRAY:
  111. init_vector4_array(v);
  112. break;
  113. case Variant::OBJECT:
  114. init_object(v);
  115. break;
  116. default:
  117. break;
  118. }
  119. }
  120. // Atomic types.
  121. _FORCE_INLINE_ static bool *get_bool(Variant *v) { return &v->_data._bool; }
  122. _FORCE_INLINE_ static const bool *get_bool(const Variant *v) { return &v->_data._bool; }
  123. _FORCE_INLINE_ static int64_t *get_int(Variant *v) { return &v->_data._int; }
  124. _FORCE_INLINE_ static const int64_t *get_int(const Variant *v) { return &v->_data._int; }
  125. _FORCE_INLINE_ static double *get_float(Variant *v) { return &v->_data._float; }
  126. _FORCE_INLINE_ static const double *get_float(const Variant *v) { return &v->_data._float; }
  127. _FORCE_INLINE_ static String *get_string(Variant *v) { return reinterpret_cast<String *>(v->_data._mem); }
  128. _FORCE_INLINE_ static const String *get_string(const Variant *v) { return reinterpret_cast<const String *>(v->_data._mem); }
  129. // Math types.
  130. _FORCE_INLINE_ static Vector2 *get_vector2(Variant *v) { return reinterpret_cast<Vector2 *>(v->_data._mem); }
  131. _FORCE_INLINE_ static const Vector2 *get_vector2(const Variant *v) { return reinterpret_cast<const Vector2 *>(v->_data._mem); }
  132. _FORCE_INLINE_ static Vector2i *get_vector2i(Variant *v) { return reinterpret_cast<Vector2i *>(v->_data._mem); }
  133. _FORCE_INLINE_ static const Vector2i *get_vector2i(const Variant *v) { return reinterpret_cast<const Vector2i *>(v->_data._mem); }
  134. _FORCE_INLINE_ static Rect2 *get_rect2(Variant *v) { return reinterpret_cast<Rect2 *>(v->_data._mem); }
  135. _FORCE_INLINE_ static const Rect2 *get_rect2(const Variant *v) { return reinterpret_cast<const Rect2 *>(v->_data._mem); }
  136. _FORCE_INLINE_ static Rect2i *get_rect2i(Variant *v) { return reinterpret_cast<Rect2i *>(v->_data._mem); }
  137. _FORCE_INLINE_ static const Rect2i *get_rect2i(const Variant *v) { return reinterpret_cast<const Rect2i *>(v->_data._mem); }
  138. _FORCE_INLINE_ static Vector3 *get_vector3(Variant *v) { return reinterpret_cast<Vector3 *>(v->_data._mem); }
  139. _FORCE_INLINE_ static const Vector3 *get_vector3(const Variant *v) { return reinterpret_cast<const Vector3 *>(v->_data._mem); }
  140. _FORCE_INLINE_ static Vector3i *get_vector3i(Variant *v) { return reinterpret_cast<Vector3i *>(v->_data._mem); }
  141. _FORCE_INLINE_ static const Vector3i *get_vector3i(const Variant *v) { return reinterpret_cast<const Vector3i *>(v->_data._mem); }
  142. _FORCE_INLINE_ static Vector4 *get_vector4(Variant *v) { return reinterpret_cast<Vector4 *>(v->_data._mem); }
  143. _FORCE_INLINE_ static const Vector4 *get_vector4(const Variant *v) { return reinterpret_cast<const Vector4 *>(v->_data._mem); }
  144. _FORCE_INLINE_ static Vector4i *get_vector4i(Variant *v) { return reinterpret_cast<Vector4i *>(v->_data._mem); }
  145. _FORCE_INLINE_ static const Vector4i *get_vector4i(const Variant *v) { return reinterpret_cast<const Vector4i *>(v->_data._mem); }
  146. _FORCE_INLINE_ static Transform2D *get_transform2d(Variant *v) { return v->_data._transform2d; }
  147. _FORCE_INLINE_ static const Transform2D *get_transform2d(const Variant *v) { return v->_data._transform2d; }
  148. _FORCE_INLINE_ static Plane *get_plane(Variant *v) { return reinterpret_cast<Plane *>(v->_data._mem); }
  149. _FORCE_INLINE_ static const Plane *get_plane(const Variant *v) { return reinterpret_cast<const Plane *>(v->_data._mem); }
  150. _FORCE_INLINE_ static Quaternion *get_quaternion(Variant *v) { return reinterpret_cast<Quaternion *>(v->_data._mem); }
  151. _FORCE_INLINE_ static const Quaternion *get_quaternion(const Variant *v) { return reinterpret_cast<const Quaternion *>(v->_data._mem); }
  152. _FORCE_INLINE_ static ::AABB *get_aabb(Variant *v) { return v->_data._aabb; }
  153. _FORCE_INLINE_ static const ::AABB *get_aabb(const Variant *v) { return v->_data._aabb; }
  154. _FORCE_INLINE_ static Basis *get_basis(Variant *v) { return v->_data._basis; }
  155. _FORCE_INLINE_ static const Basis *get_basis(const Variant *v) { return v->_data._basis; }
  156. _FORCE_INLINE_ static Transform3D *get_transform(Variant *v) { return v->_data._transform3d; }
  157. _FORCE_INLINE_ static const Transform3D *get_transform(const Variant *v) { return v->_data._transform3d; }
  158. _FORCE_INLINE_ static Projection *get_projection(Variant *v) { return v->_data._projection; }
  159. _FORCE_INLINE_ static const Projection *get_projection(const Variant *v) { return v->_data._projection; }
  160. // Misc types.
  161. _FORCE_INLINE_ static Color *get_color(Variant *v) { return reinterpret_cast<Color *>(v->_data._mem); }
  162. _FORCE_INLINE_ static const Color *get_color(const Variant *v) { return reinterpret_cast<const Color *>(v->_data._mem); }
  163. _FORCE_INLINE_ static StringName *get_string_name(Variant *v) { return reinterpret_cast<StringName *>(v->_data._mem); }
  164. _FORCE_INLINE_ static const StringName *get_string_name(const Variant *v) { return reinterpret_cast<const StringName *>(v->_data._mem); }
  165. _FORCE_INLINE_ static NodePath *get_node_path(Variant *v) { return reinterpret_cast<NodePath *>(v->_data._mem); }
  166. _FORCE_INLINE_ static const NodePath *get_node_path(const Variant *v) { return reinterpret_cast<const NodePath *>(v->_data._mem); }
  167. _FORCE_INLINE_ static ::RID *get_rid(Variant *v) { return reinterpret_cast<::RID *>(v->_data._mem); }
  168. _FORCE_INLINE_ static const ::RID *get_rid(const Variant *v) { return reinterpret_cast<const ::RID *>(v->_data._mem); }
  169. _FORCE_INLINE_ static Callable *get_callable(Variant *v) { return reinterpret_cast<Callable *>(v->_data._mem); }
  170. _FORCE_INLINE_ static const Callable *get_callable(const Variant *v) { return reinterpret_cast<const Callable *>(v->_data._mem); }
  171. _FORCE_INLINE_ static Signal *get_signal(Variant *v) { return reinterpret_cast<Signal *>(v->_data._mem); }
  172. _FORCE_INLINE_ static const Signal *get_signal(const Variant *v) { return reinterpret_cast<const Signal *>(v->_data._mem); }
  173. _FORCE_INLINE_ static Dictionary *get_dictionary(Variant *v) { return reinterpret_cast<Dictionary *>(v->_data._mem); }
  174. _FORCE_INLINE_ static const Dictionary *get_dictionary(const Variant *v) { return reinterpret_cast<const Dictionary *>(v->_data._mem); }
  175. _FORCE_INLINE_ static Array *get_array(Variant *v) { return reinterpret_cast<Array *>(v->_data._mem); }
  176. _FORCE_INLINE_ static const Array *get_array(const Variant *v) { return reinterpret_cast<const Array *>(v->_data._mem); }
  177. // Typed arrays.
  178. _FORCE_INLINE_ static PackedByteArray *get_byte_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<uint8_t> *>(v->_data.packed_array)->array; }
  179. _FORCE_INLINE_ static const PackedByteArray *get_byte_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<uint8_t> *>(v->_data.packed_array)->array; }
  180. _FORCE_INLINE_ static PackedInt32Array *get_int32_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<int32_t> *>(v->_data.packed_array)->array; }
  181. _FORCE_INLINE_ static const PackedInt32Array *get_int32_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<int32_t> *>(v->_data.packed_array)->array; }
  182. _FORCE_INLINE_ static PackedInt64Array *get_int64_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<int64_t> *>(v->_data.packed_array)->array; }
  183. _FORCE_INLINE_ static const PackedInt64Array *get_int64_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<int64_t> *>(v->_data.packed_array)->array; }
  184. _FORCE_INLINE_ static PackedFloat32Array *get_float32_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<float> *>(v->_data.packed_array)->array; }
  185. _FORCE_INLINE_ static const PackedFloat32Array *get_float32_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<float> *>(v->_data.packed_array)->array; }
  186. _FORCE_INLINE_ static PackedFloat64Array *get_float64_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<double> *>(v->_data.packed_array)->array; }
  187. _FORCE_INLINE_ static const PackedFloat64Array *get_float64_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<double> *>(v->_data.packed_array)->array; }
  188. _FORCE_INLINE_ static PackedStringArray *get_string_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<String> *>(v->_data.packed_array)->array; }
  189. _FORCE_INLINE_ static const PackedStringArray *get_string_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<String> *>(v->_data.packed_array)->array; }
  190. _FORCE_INLINE_ static PackedVector2Array *get_vector2_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<Vector2> *>(v->_data.packed_array)->array; }
  191. _FORCE_INLINE_ static const PackedVector2Array *get_vector2_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Vector2> *>(v->_data.packed_array)->array; }
  192. _FORCE_INLINE_ static PackedVector3Array *get_vector3_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<Vector3> *>(v->_data.packed_array)->array; }
  193. _FORCE_INLINE_ static const PackedVector3Array *get_vector3_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Vector3> *>(v->_data.packed_array)->array; }
  194. _FORCE_INLINE_ static PackedColorArray *get_color_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<Color> *>(v->_data.packed_array)->array; }
  195. _FORCE_INLINE_ static const PackedColorArray *get_color_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Color> *>(v->_data.packed_array)->array; }
  196. _FORCE_INLINE_ static PackedVector4Array *get_vector4_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<Vector4> *>(v->_data.packed_array)->array; }
  197. _FORCE_INLINE_ static const PackedVector4Array *get_vector4_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Vector4> *>(v->_data.packed_array)->array; }
  198. _FORCE_INLINE_ static Object **get_object(Variant *v) { return (Object **)&v->_get_obj().obj; }
  199. _FORCE_INLINE_ static const Object **get_object(const Variant *v) { return (const Object **)&v->_get_obj().obj; }
  200. _FORCE_INLINE_ static const ObjectID get_object_id(const Variant *v) { return v->_get_obj().id; }
  201. template <typename T>
  202. _FORCE_INLINE_ static void init_generic(Variant *v) {
  203. v->type = GetTypeInfo<T>::VARIANT_TYPE;
  204. }
  205. // Should be in the same order as Variant::Type for consistency.
  206. // Those primitive and vector types don't need an `init_` method:
  207. // Nil, bool, float, Vector2/i, Rect2/i, Vector3/i, Plane, Quat, RID.
  208. // Object is a special case, handled via `object_reset_data`.
  209. _FORCE_INLINE_ static void init_string(Variant *v) {
  210. memnew_placement(v->_data._mem, String);
  211. v->type = Variant::STRING;
  212. }
  213. _FORCE_INLINE_ static void init_transform2d(Variant *v) {
  214. v->_data._transform2d = (Transform2D *)Variant::Pools::_bucket_small.alloc();
  215. memnew_placement(v->_data._transform2d, Transform2D);
  216. v->type = Variant::TRANSFORM2D;
  217. }
  218. _FORCE_INLINE_ static void init_aabb(Variant *v) {
  219. v->_data._aabb = (AABB *)Variant::Pools::_bucket_small.alloc();
  220. memnew_placement(v->_data._aabb, AABB);
  221. v->type = Variant::AABB;
  222. }
  223. _FORCE_INLINE_ static void init_basis(Variant *v) {
  224. v->_data._basis = (Basis *)Variant::Pools::_bucket_medium.alloc();
  225. memnew_placement(v->_data._basis, Basis);
  226. v->type = Variant::BASIS;
  227. }
  228. _FORCE_INLINE_ static void init_transform3d(Variant *v) {
  229. v->_data._transform3d = (Transform3D *)Variant::Pools::_bucket_medium.alloc();
  230. memnew_placement(v->_data._transform3d, Transform3D);
  231. v->type = Variant::TRANSFORM3D;
  232. }
  233. _FORCE_INLINE_ static void init_projection(Variant *v) {
  234. v->_data._projection = (Projection *)Variant::Pools::_bucket_large.alloc();
  235. memnew_placement(v->_data._projection, Projection);
  236. v->type = Variant::PROJECTION;
  237. }
  238. _FORCE_INLINE_ static void init_color(Variant *v) {
  239. memnew_placement(v->_data._mem, Color);
  240. v->type = Variant::COLOR;
  241. }
  242. _FORCE_INLINE_ static void init_string_name(Variant *v) {
  243. memnew_placement(v->_data._mem, StringName);
  244. v->type = Variant::STRING_NAME;
  245. }
  246. _FORCE_INLINE_ static void init_node_path(Variant *v) {
  247. memnew_placement(v->_data._mem, NodePath);
  248. v->type = Variant::NODE_PATH;
  249. }
  250. _FORCE_INLINE_ static void init_callable(Variant *v) {
  251. memnew_placement(v->_data._mem, Callable);
  252. v->type = Variant::CALLABLE;
  253. }
  254. _FORCE_INLINE_ static void init_signal(Variant *v) {
  255. memnew_placement(v->_data._mem, Signal);
  256. v->type = Variant::SIGNAL;
  257. }
  258. _FORCE_INLINE_ static void init_dictionary(Variant *v) {
  259. memnew_placement(v->_data._mem, Dictionary);
  260. v->type = Variant::DICTIONARY;
  261. }
  262. _FORCE_INLINE_ static void init_array(Variant *v) {
  263. memnew_placement(v->_data._mem, Array);
  264. v->type = Variant::ARRAY;
  265. }
  266. _FORCE_INLINE_ static void init_byte_array(Variant *v) {
  267. v->_data.packed_array = Variant::PackedArrayRef<uint8_t>::create(Vector<uint8_t>());
  268. v->type = Variant::PACKED_BYTE_ARRAY;
  269. }
  270. _FORCE_INLINE_ static void init_int32_array(Variant *v) {
  271. v->_data.packed_array = Variant::PackedArrayRef<int32_t>::create(Vector<int32_t>());
  272. v->type = Variant::PACKED_INT32_ARRAY;
  273. }
  274. _FORCE_INLINE_ static void init_int64_array(Variant *v) {
  275. v->_data.packed_array = Variant::PackedArrayRef<int64_t>::create(Vector<int64_t>());
  276. v->type = Variant::PACKED_INT64_ARRAY;
  277. }
  278. _FORCE_INLINE_ static void init_float32_array(Variant *v) {
  279. v->_data.packed_array = Variant::PackedArrayRef<float>::create(Vector<float>());
  280. v->type = Variant::PACKED_FLOAT32_ARRAY;
  281. }
  282. _FORCE_INLINE_ static void init_float64_array(Variant *v) {
  283. v->_data.packed_array = Variant::PackedArrayRef<double>::create(Vector<double>());
  284. v->type = Variant::PACKED_FLOAT64_ARRAY;
  285. }
  286. _FORCE_INLINE_ static void init_string_array(Variant *v) {
  287. v->_data.packed_array = Variant::PackedArrayRef<String>::create(Vector<String>());
  288. v->type = Variant::PACKED_STRING_ARRAY;
  289. }
  290. _FORCE_INLINE_ static void init_vector2_array(Variant *v) {
  291. v->_data.packed_array = Variant::PackedArrayRef<Vector2>::create(Vector<Vector2>());
  292. v->type = Variant::PACKED_VECTOR2_ARRAY;
  293. }
  294. _FORCE_INLINE_ static void init_vector3_array(Variant *v) {
  295. v->_data.packed_array = Variant::PackedArrayRef<Vector3>::create(Vector<Vector3>());
  296. v->type = Variant::PACKED_VECTOR3_ARRAY;
  297. }
  298. _FORCE_INLINE_ static void init_color_array(Variant *v) {
  299. v->_data.packed_array = Variant::PackedArrayRef<Color>::create(Vector<Color>());
  300. v->type = Variant::PACKED_COLOR_ARRAY;
  301. }
  302. _FORCE_INLINE_ static void init_vector4_array(Variant *v) {
  303. v->_data.packed_array = Variant::PackedArrayRef<Vector4>::create(Vector<Vector4>());
  304. v->type = Variant::PACKED_VECTOR4_ARRAY;
  305. }
  306. _FORCE_INLINE_ static void init_object(Variant *v) {
  307. object_reset_data(v);
  308. v->type = Variant::OBJECT;
  309. }
  310. _FORCE_INLINE_ static void clear(Variant *v) {
  311. v->clear();
  312. }
  313. _FORCE_INLINE_ static void object_assign(Variant *v, const Variant *vo) {
  314. v->_get_obj().ref(vo->_get_obj());
  315. }
  316. _FORCE_INLINE_ static void object_assign(Variant *v, Object *o) {
  317. v->_get_obj().ref_pointer(o);
  318. }
  319. _FORCE_INLINE_ static void object_assign(Variant *v, const Object *o) {
  320. v->_get_obj().ref_pointer(const_cast<Object *>(o));
  321. }
  322. template <typename T>
  323. _FORCE_INLINE_ static void object_assign(Variant *v, const Ref<T> &r) {
  324. v->_get_obj().ref(r);
  325. }
  326. _FORCE_INLINE_ static void object_reset_data(Variant *v) {
  327. v->_get_obj() = Variant::ObjData();
  328. }
  329. _FORCE_INLINE_ static void update_object_id(Variant *v) {
  330. const Object *o = v->_get_obj().obj;
  331. if (o) {
  332. v->_get_obj().id = o->get_instance_id();
  333. }
  334. }
  335. _FORCE_INLINE_ static void *get_opaque_pointer(Variant *v) {
  336. switch (v->type) {
  337. case Variant::NIL:
  338. return nullptr;
  339. case Variant::BOOL:
  340. return get_bool(v);
  341. case Variant::INT:
  342. return get_int(v);
  343. case Variant::FLOAT:
  344. return get_float(v);
  345. case Variant::STRING:
  346. return get_string(v);
  347. case Variant::VECTOR2:
  348. return get_vector2(v);
  349. case Variant::VECTOR2I:
  350. return get_vector2i(v);
  351. case Variant::VECTOR3:
  352. return get_vector3(v);
  353. case Variant::VECTOR3I:
  354. return get_vector3i(v);
  355. case Variant::VECTOR4:
  356. return get_vector4(v);
  357. case Variant::VECTOR4I:
  358. return get_vector4i(v);
  359. case Variant::RECT2:
  360. return get_rect2(v);
  361. case Variant::RECT2I:
  362. return get_rect2i(v);
  363. case Variant::TRANSFORM3D:
  364. return get_transform(v);
  365. case Variant::PROJECTION:
  366. return get_projection(v);
  367. case Variant::TRANSFORM2D:
  368. return get_transform2d(v);
  369. case Variant::QUATERNION:
  370. return get_quaternion(v);
  371. case Variant::PLANE:
  372. return get_plane(v);
  373. case Variant::BASIS:
  374. return get_basis(v);
  375. case Variant::AABB:
  376. return get_aabb(v);
  377. case Variant::COLOR:
  378. return get_color(v);
  379. case Variant::STRING_NAME:
  380. return get_string_name(v);
  381. case Variant::NODE_PATH:
  382. return get_node_path(v);
  383. case Variant::RID:
  384. return get_rid(v);
  385. case Variant::CALLABLE:
  386. return get_callable(v);
  387. case Variant::SIGNAL:
  388. return get_signal(v);
  389. case Variant::DICTIONARY:
  390. return get_dictionary(v);
  391. case Variant::ARRAY:
  392. return get_array(v);
  393. case Variant::PACKED_BYTE_ARRAY:
  394. return get_byte_array(v);
  395. case Variant::PACKED_INT32_ARRAY:
  396. return get_int32_array(v);
  397. case Variant::PACKED_INT64_ARRAY:
  398. return get_int64_array(v);
  399. case Variant::PACKED_FLOAT32_ARRAY:
  400. return get_float32_array(v);
  401. case Variant::PACKED_FLOAT64_ARRAY:
  402. return get_float64_array(v);
  403. case Variant::PACKED_STRING_ARRAY:
  404. return get_string_array(v);
  405. case Variant::PACKED_VECTOR2_ARRAY:
  406. return get_vector2_array(v);
  407. case Variant::PACKED_VECTOR3_ARRAY:
  408. return get_vector3_array(v);
  409. case Variant::PACKED_COLOR_ARRAY:
  410. return get_color_array(v);
  411. case Variant::PACKED_VECTOR4_ARRAY:
  412. return get_vector4_array(v);
  413. case Variant::OBJECT:
  414. return get_object(v);
  415. case Variant::VARIANT_MAX:
  416. ERR_FAIL_V(nullptr);
  417. }
  418. ERR_FAIL_V(nullptr);
  419. }
  420. _FORCE_INLINE_ static const void *get_opaque_pointer(const Variant *v) {
  421. switch (v->type) {
  422. case Variant::NIL:
  423. return nullptr;
  424. case Variant::BOOL:
  425. return get_bool(v);
  426. case Variant::INT:
  427. return get_int(v);
  428. case Variant::FLOAT:
  429. return get_float(v);
  430. case Variant::STRING:
  431. return get_string(v);
  432. case Variant::VECTOR2:
  433. return get_vector2(v);
  434. case Variant::VECTOR2I:
  435. return get_vector2i(v);
  436. case Variant::VECTOR3:
  437. return get_vector3(v);
  438. case Variant::VECTOR3I:
  439. return get_vector3i(v);
  440. case Variant::VECTOR4:
  441. return get_vector4(v);
  442. case Variant::VECTOR4I:
  443. return get_vector4i(v);
  444. case Variant::RECT2:
  445. return get_rect2(v);
  446. case Variant::RECT2I:
  447. return get_rect2i(v);
  448. case Variant::TRANSFORM3D:
  449. return get_transform(v);
  450. case Variant::PROJECTION:
  451. return get_projection(v);
  452. case Variant::TRANSFORM2D:
  453. return get_transform2d(v);
  454. case Variant::QUATERNION:
  455. return get_quaternion(v);
  456. case Variant::PLANE:
  457. return get_plane(v);
  458. case Variant::BASIS:
  459. return get_basis(v);
  460. case Variant::AABB:
  461. return get_aabb(v);
  462. case Variant::COLOR:
  463. return get_color(v);
  464. case Variant::STRING_NAME:
  465. return get_string_name(v);
  466. case Variant::NODE_PATH:
  467. return get_node_path(v);
  468. case Variant::RID:
  469. return get_rid(v);
  470. case Variant::CALLABLE:
  471. return get_callable(v);
  472. case Variant::SIGNAL:
  473. return get_signal(v);
  474. case Variant::DICTIONARY:
  475. return get_dictionary(v);
  476. case Variant::ARRAY:
  477. return get_array(v);
  478. case Variant::PACKED_BYTE_ARRAY:
  479. return get_byte_array(v);
  480. case Variant::PACKED_INT32_ARRAY:
  481. return get_int32_array(v);
  482. case Variant::PACKED_INT64_ARRAY:
  483. return get_int64_array(v);
  484. case Variant::PACKED_FLOAT32_ARRAY:
  485. return get_float32_array(v);
  486. case Variant::PACKED_FLOAT64_ARRAY:
  487. return get_float64_array(v);
  488. case Variant::PACKED_STRING_ARRAY:
  489. return get_string_array(v);
  490. case Variant::PACKED_VECTOR2_ARRAY:
  491. return get_vector2_array(v);
  492. case Variant::PACKED_VECTOR3_ARRAY:
  493. return get_vector3_array(v);
  494. case Variant::PACKED_COLOR_ARRAY:
  495. return get_color_array(v);
  496. case Variant::PACKED_VECTOR4_ARRAY:
  497. return get_vector4_array(v);
  498. case Variant::OBJECT:
  499. return get_object(v);
  500. case Variant::VARIANT_MAX:
  501. ERR_FAIL_V(nullptr);
  502. }
  503. ERR_FAIL_V(nullptr);
  504. }
  505. };
  506. template <typename T>
  507. struct VariantGetInternalPtr {
  508. };
  509. template <>
  510. struct VariantGetInternalPtr<bool> {
  511. static bool *get_ptr(Variant *v) { return VariantInternal::get_bool(v); }
  512. static const bool *get_ptr(const Variant *v) { return VariantInternal::get_bool(v); }
  513. };
  514. template <>
  515. struct VariantGetInternalPtr<int8_t> {
  516. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  517. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  518. };
  519. template <>
  520. struct VariantGetInternalPtr<uint8_t> {
  521. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  522. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  523. };
  524. template <>
  525. struct VariantGetInternalPtr<int16_t> {
  526. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  527. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  528. };
  529. template <>
  530. struct VariantGetInternalPtr<uint16_t> {
  531. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  532. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  533. };
  534. template <>
  535. struct VariantGetInternalPtr<int32_t> {
  536. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  537. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  538. };
  539. template <>
  540. struct VariantGetInternalPtr<uint32_t> {
  541. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  542. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  543. };
  544. template <>
  545. struct VariantGetInternalPtr<int64_t> {
  546. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  547. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  548. };
  549. template <>
  550. struct VariantGetInternalPtr<uint64_t> {
  551. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  552. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  553. };
  554. template <>
  555. struct VariantGetInternalPtr<char32_t> {
  556. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  557. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  558. };
  559. template <>
  560. struct VariantGetInternalPtr<ObjectID> {
  561. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  562. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  563. };
  564. template <>
  565. struct VariantGetInternalPtr<Error> {
  566. static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
  567. static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
  568. };
  569. template <>
  570. struct VariantGetInternalPtr<float> {
  571. static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); }
  572. static const double *get_ptr(const Variant *v) { return VariantInternal::get_float(v); }
  573. };
  574. template <>
  575. struct VariantGetInternalPtr<double> {
  576. static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); }
  577. static const double *get_ptr(const Variant *v) { return VariantInternal::get_float(v); }
  578. };
  579. template <>
  580. struct VariantGetInternalPtr<String> {
  581. static String *get_ptr(Variant *v) { return VariantInternal::get_string(v); }
  582. static const String *get_ptr(const Variant *v) { return VariantInternal::get_string(v); }
  583. };
  584. template <>
  585. struct VariantGetInternalPtr<Vector2> {
  586. static Vector2 *get_ptr(Variant *v) { return VariantInternal::get_vector2(v); }
  587. static const Vector2 *get_ptr(const Variant *v) { return VariantInternal::get_vector2(v); }
  588. };
  589. template <>
  590. struct VariantGetInternalPtr<Vector2i> {
  591. static Vector2i *get_ptr(Variant *v) { return VariantInternal::get_vector2i(v); }
  592. static const Vector2i *get_ptr(const Variant *v) { return VariantInternal::get_vector2i(v); }
  593. };
  594. template <>
  595. struct VariantGetInternalPtr<Rect2> {
  596. static Rect2 *get_ptr(Variant *v) { return VariantInternal::get_rect2(v); }
  597. static const Rect2 *get_ptr(const Variant *v) { return VariantInternal::get_rect2(v); }
  598. };
  599. template <>
  600. struct VariantGetInternalPtr<Rect2i> {
  601. static Rect2i *get_ptr(Variant *v) { return VariantInternal::get_rect2i(v); }
  602. static const Rect2i *get_ptr(const Variant *v) { return VariantInternal::get_rect2i(v); }
  603. };
  604. template <>
  605. struct VariantGetInternalPtr<Vector3> {
  606. static Vector3 *get_ptr(Variant *v) { return VariantInternal::get_vector3(v); }
  607. static const Vector3 *get_ptr(const Variant *v) { return VariantInternal::get_vector3(v); }
  608. };
  609. template <>
  610. struct VariantGetInternalPtr<Vector3i> {
  611. static Vector3i *get_ptr(Variant *v) { return VariantInternal::get_vector3i(v); }
  612. static const Vector3i *get_ptr(const Variant *v) { return VariantInternal::get_vector3i(v); }
  613. };
  614. template <>
  615. struct VariantGetInternalPtr<Vector4> {
  616. static Vector4 *get_ptr(Variant *v) { return VariantInternal::get_vector4(v); }
  617. static const Vector4 *get_ptr(const Variant *v) { return VariantInternal::get_vector4(v); }
  618. };
  619. template <>
  620. struct VariantGetInternalPtr<Vector4i> {
  621. static Vector4i *get_ptr(Variant *v) { return VariantInternal::get_vector4i(v); }
  622. static const Vector4i *get_ptr(const Variant *v) { return VariantInternal::get_vector4i(v); }
  623. };
  624. template <>
  625. struct VariantGetInternalPtr<Transform2D> {
  626. static Transform2D *get_ptr(Variant *v) { return VariantInternal::get_transform2d(v); }
  627. static const Transform2D *get_ptr(const Variant *v) { return VariantInternal::get_transform2d(v); }
  628. };
  629. template <>
  630. struct VariantGetInternalPtr<Transform3D> {
  631. static Transform3D *get_ptr(Variant *v) { return VariantInternal::get_transform(v); }
  632. static const Transform3D *get_ptr(const Variant *v) { return VariantInternal::get_transform(v); }
  633. };
  634. template <>
  635. struct VariantGetInternalPtr<Projection> {
  636. static Projection *get_ptr(Variant *v) { return VariantInternal::get_projection(v); }
  637. static const Projection *get_ptr(const Variant *v) { return VariantInternal::get_projection(v); }
  638. };
  639. template <>
  640. struct VariantGetInternalPtr<Plane> {
  641. static Plane *get_ptr(Variant *v) { return VariantInternal::get_plane(v); }
  642. static const Plane *get_ptr(const Variant *v) { return VariantInternal::get_plane(v); }
  643. };
  644. template <>
  645. struct VariantGetInternalPtr<Quaternion> {
  646. static Quaternion *get_ptr(Variant *v) { return VariantInternal::get_quaternion(v); }
  647. static const Quaternion *get_ptr(const Variant *v) { return VariantInternal::get_quaternion(v); }
  648. };
  649. template <>
  650. struct VariantGetInternalPtr<::AABB> {
  651. static ::AABB *get_ptr(Variant *v) { return VariantInternal::get_aabb(v); }
  652. static const ::AABB *get_ptr(const Variant *v) { return VariantInternal::get_aabb(v); }
  653. };
  654. template <>
  655. struct VariantGetInternalPtr<Basis> {
  656. static Basis *get_ptr(Variant *v) { return VariantInternal::get_basis(v); }
  657. static const Basis *get_ptr(const Variant *v) { return VariantInternal::get_basis(v); }
  658. };
  659. //
  660. template <>
  661. struct VariantGetInternalPtr<Color> {
  662. static Color *get_ptr(Variant *v) { return VariantInternal::get_color(v); }
  663. static const Color *get_ptr(const Variant *v) { return VariantInternal::get_color(v); }
  664. };
  665. template <>
  666. struct VariantGetInternalPtr<StringName> {
  667. static StringName *get_ptr(Variant *v) { return VariantInternal::get_string_name(v); }
  668. static const StringName *get_ptr(const Variant *v) { return VariantInternal::get_string_name(v); }
  669. };
  670. template <>
  671. struct VariantGetInternalPtr<NodePath> {
  672. static NodePath *get_ptr(Variant *v) { return VariantInternal::get_node_path(v); }
  673. static const NodePath *get_ptr(const Variant *v) { return VariantInternal::get_node_path(v); }
  674. };
  675. template <>
  676. struct VariantGetInternalPtr<::RID> {
  677. static ::RID *get_ptr(Variant *v) { return VariantInternal::get_rid(v); }
  678. static const ::RID *get_ptr(const Variant *v) { return VariantInternal::get_rid(v); }
  679. };
  680. template <>
  681. struct VariantGetInternalPtr<Callable> {
  682. static Callable *get_ptr(Variant *v) { return VariantInternal::get_callable(v); }
  683. static const Callable *get_ptr(const Variant *v) { return VariantInternal::get_callable(v); }
  684. };
  685. template <>
  686. struct VariantGetInternalPtr<Signal> {
  687. static Signal *get_ptr(Variant *v) { return VariantInternal::get_signal(v); }
  688. static const Signal *get_ptr(const Variant *v) { return VariantInternal::get_signal(v); }
  689. };
  690. template <>
  691. struct VariantGetInternalPtr<Dictionary> {
  692. static Dictionary *get_ptr(Variant *v) { return VariantInternal::get_dictionary(v); }
  693. static const Dictionary *get_ptr(const Variant *v) { return VariantInternal::get_dictionary(v); }
  694. };
  695. template <>
  696. struct VariantGetInternalPtr<Array> {
  697. static Array *get_ptr(Variant *v) { return VariantInternal::get_array(v); }
  698. static const Array *get_ptr(const Variant *v) { return VariantInternal::get_array(v); }
  699. };
  700. template <>
  701. struct VariantGetInternalPtr<PackedByteArray> {
  702. static PackedByteArray *get_ptr(Variant *v) { return VariantInternal::get_byte_array(v); }
  703. static const PackedByteArray *get_ptr(const Variant *v) { return VariantInternal::get_byte_array(v); }
  704. };
  705. template <>
  706. struct VariantGetInternalPtr<PackedInt32Array> {
  707. static PackedInt32Array *get_ptr(Variant *v) { return VariantInternal::get_int32_array(v); }
  708. static const PackedInt32Array *get_ptr(const Variant *v) { return VariantInternal::get_int32_array(v); }
  709. };
  710. template <>
  711. struct VariantGetInternalPtr<PackedInt64Array> {
  712. static PackedInt64Array *get_ptr(Variant *v) { return VariantInternal::get_int64_array(v); }
  713. static const PackedInt64Array *get_ptr(const Variant *v) { return VariantInternal::get_int64_array(v); }
  714. };
  715. template <>
  716. struct VariantGetInternalPtr<PackedFloat32Array> {
  717. static PackedFloat32Array *get_ptr(Variant *v) { return VariantInternal::get_float32_array(v); }
  718. static const PackedFloat32Array *get_ptr(const Variant *v) { return VariantInternal::get_float32_array(v); }
  719. };
  720. template <>
  721. struct VariantGetInternalPtr<PackedFloat64Array> {
  722. static PackedFloat64Array *get_ptr(Variant *v) { return VariantInternal::get_float64_array(v); }
  723. static const PackedFloat64Array *get_ptr(const Variant *v) { return VariantInternal::get_float64_array(v); }
  724. };
  725. template <>
  726. struct VariantGetInternalPtr<PackedStringArray> {
  727. static PackedStringArray *get_ptr(Variant *v) { return VariantInternal::get_string_array(v); }
  728. static const PackedStringArray *get_ptr(const Variant *v) { return VariantInternal::get_string_array(v); }
  729. };
  730. template <>
  731. struct VariantGetInternalPtr<PackedVector2Array> {
  732. static PackedVector2Array *get_ptr(Variant *v) { return VariantInternal::get_vector2_array(v); }
  733. static const PackedVector2Array *get_ptr(const Variant *v) { return VariantInternal::get_vector2_array(v); }
  734. };
  735. template <>
  736. struct VariantGetInternalPtr<PackedVector3Array> {
  737. static PackedVector3Array *get_ptr(Variant *v) { return VariantInternal::get_vector3_array(v); }
  738. static const PackedVector3Array *get_ptr(const Variant *v) { return VariantInternal::get_vector3_array(v); }
  739. };
  740. template <>
  741. struct VariantGetInternalPtr<PackedColorArray> {
  742. static PackedColorArray *get_ptr(Variant *v) { return VariantInternal::get_color_array(v); }
  743. static const PackedColorArray *get_ptr(const Variant *v) { return VariantInternal::get_color_array(v); }
  744. };
  745. template <>
  746. struct VariantGetInternalPtr<PackedVector4Array> {
  747. static PackedVector4Array *get_ptr(Variant *v) { return VariantInternal::get_vector4_array(v); }
  748. static const PackedVector4Array *get_ptr(const Variant *v) { return VariantInternal::get_vector4_array(v); }
  749. };
  750. template <typename T>
  751. struct VariantInternalAccessor {
  752. };
  753. template <>
  754. struct VariantInternalAccessor<bool> {
  755. static _FORCE_INLINE_ bool get(const Variant *v) { return *VariantInternal::get_bool(v); }
  756. static _FORCE_INLINE_ void set(Variant *v, bool p_value) { *VariantInternal::get_bool(v) = p_value; }
  757. };
  758. #define VARIANT_ACCESSOR_NUMBER(m_type) \
  759. template <> \
  760. struct VariantInternalAccessor<m_type> { \
  761. static _FORCE_INLINE_ m_type get(const Variant *v) { return (m_type) * VariantInternal::get_int(v); } \
  762. static _FORCE_INLINE_ void set(Variant *v, m_type p_value) { *VariantInternal::get_int(v) = p_value; } \
  763. };
  764. VARIANT_ACCESSOR_NUMBER(int8_t)
  765. VARIANT_ACCESSOR_NUMBER(uint8_t)
  766. VARIANT_ACCESSOR_NUMBER(int16_t)
  767. VARIANT_ACCESSOR_NUMBER(uint16_t)
  768. VARIANT_ACCESSOR_NUMBER(int32_t)
  769. VARIANT_ACCESSOR_NUMBER(uint32_t)
  770. VARIANT_ACCESSOR_NUMBER(int64_t)
  771. VARIANT_ACCESSOR_NUMBER(uint64_t)
  772. VARIANT_ACCESSOR_NUMBER(char32_t)
  773. template <>
  774. struct VariantInternalAccessor<ObjectID> {
  775. static _FORCE_INLINE_ ObjectID get(const Variant *v) { return ObjectID(*VariantInternal::get_int(v)); }
  776. static _FORCE_INLINE_ void set(Variant *v, ObjectID p_value) { *VariantInternal::get_int(v) = p_value; }
  777. };
  778. template <typename T>
  779. struct VariantInternalAccessor<T *> {
  780. static _FORCE_INLINE_ T *get(const Variant *v) { return const_cast<T *>(static_cast<const T *>(*VariantInternal::get_object(v))); }
  781. static _FORCE_INLINE_ void set(Variant *v, const T *p_value) { VariantInternal::object_assign(v, p_value); }
  782. };
  783. template <typename T>
  784. struct VariantInternalAccessor<const T *> {
  785. static _FORCE_INLINE_ const T *get(const Variant *v) { return static_cast<const T *>(*VariantInternal::get_object(v)); }
  786. static _FORCE_INLINE_ void set(Variant *v, const T *p_value) { VariantInternal::object_assign(v, p_value); }
  787. };
  788. template <>
  789. struct VariantInternalAccessor<IPAddress> {
  790. static _FORCE_INLINE_ IPAddress get(const Variant *v) { return IPAddress(*VariantInternal::get_string(v)); }
  791. static _FORCE_INLINE_ void set(Variant *v, IPAddress p_value) { *VariantInternal::get_string(v) = p_value; }
  792. };
  793. template <>
  794. struct VariantInternalAccessor<float> {
  795. static _FORCE_INLINE_ float get(const Variant *v) { return *VariantInternal::get_float(v); }
  796. static _FORCE_INLINE_ void set(Variant *v, float p_value) { *VariantInternal::get_float(v) = p_value; }
  797. };
  798. template <>
  799. struct VariantInternalAccessor<double> {
  800. static _FORCE_INLINE_ double get(const Variant *v) { return *VariantInternal::get_float(v); }
  801. static _FORCE_INLINE_ void set(Variant *v, double p_value) { *VariantInternal::get_float(v) = p_value; }
  802. };
  803. template <>
  804. struct VariantInternalAccessor<String> {
  805. static _FORCE_INLINE_ const String &get(const Variant *v) { return *VariantInternal::get_string(v); }
  806. static _FORCE_INLINE_ void set(Variant *v, const String &p_value) { *VariantInternal::get_string(v) = p_value; }
  807. };
  808. template <>
  809. struct VariantInternalAccessor<Vector2> {
  810. static _FORCE_INLINE_ const Vector2 &get(const Variant *v) { return *VariantInternal::get_vector2(v); }
  811. static _FORCE_INLINE_ void set(Variant *v, const Vector2 &p_value) { *VariantInternal::get_vector2(v) = p_value; }
  812. };
  813. template <>
  814. struct VariantInternalAccessor<Vector2i> {
  815. static _FORCE_INLINE_ const Vector2i &get(const Variant *v) { return *VariantInternal::get_vector2i(v); }
  816. static _FORCE_INLINE_ void set(Variant *v, const Vector2i &p_value) { *VariantInternal::get_vector2i(v) = p_value; }
  817. };
  818. template <>
  819. struct VariantInternalAccessor<Rect2> {
  820. static _FORCE_INLINE_ const Rect2 &get(const Variant *v) { return *VariantInternal::get_rect2(v); }
  821. static _FORCE_INLINE_ void set(Variant *v, const Rect2 &p_value) { *VariantInternal::get_rect2(v) = p_value; }
  822. };
  823. template <>
  824. struct VariantInternalAccessor<Rect2i> {
  825. static _FORCE_INLINE_ const Rect2i &get(const Variant *v) { return *VariantInternal::get_rect2i(v); }
  826. static _FORCE_INLINE_ void set(Variant *v, const Rect2i &p_value) { *VariantInternal::get_rect2i(v) = p_value; }
  827. };
  828. template <>
  829. struct VariantInternalAccessor<Vector3> {
  830. static _FORCE_INLINE_ const Vector3 &get(const Variant *v) { return *VariantInternal::get_vector3(v); }
  831. static _FORCE_INLINE_ void set(Variant *v, const Vector3 &p_value) { *VariantInternal::get_vector3(v) = p_value; }
  832. };
  833. template <>
  834. struct VariantInternalAccessor<Vector3i> {
  835. static _FORCE_INLINE_ const Vector3i &get(const Variant *v) { return *VariantInternal::get_vector3i(v); }
  836. static _FORCE_INLINE_ void set(Variant *v, const Vector3i &p_value) { *VariantInternal::get_vector3i(v) = p_value; }
  837. };
  838. template <>
  839. struct VariantInternalAccessor<Vector4> {
  840. static _FORCE_INLINE_ const Vector4 &get(const Variant *v) { return *VariantInternal::get_vector4(v); }
  841. static _FORCE_INLINE_ void set(Variant *v, const Vector4 &p_value) { *VariantInternal::get_vector4(v) = p_value; }
  842. };
  843. template <>
  844. struct VariantInternalAccessor<Vector4i> {
  845. static _FORCE_INLINE_ const Vector4i &get(const Variant *v) { return *VariantInternal::get_vector4i(v); }
  846. static _FORCE_INLINE_ void set(Variant *v, const Vector4i &p_value) { *VariantInternal::get_vector4i(v) = p_value; }
  847. };
  848. template <>
  849. struct VariantInternalAccessor<Transform2D> {
  850. static _FORCE_INLINE_ const Transform2D &get(const Variant *v) { return *VariantInternal::get_transform2d(v); }
  851. static _FORCE_INLINE_ void set(Variant *v, const Transform2D &p_value) { *VariantInternal::get_transform2d(v) = p_value; }
  852. };
  853. template <>
  854. struct VariantInternalAccessor<Transform3D> {
  855. static _FORCE_INLINE_ const Transform3D &get(const Variant *v) { return *VariantInternal::get_transform(v); }
  856. static _FORCE_INLINE_ void set(Variant *v, const Transform3D &p_value) { *VariantInternal::get_transform(v) = p_value; }
  857. };
  858. template <>
  859. struct VariantInternalAccessor<Projection> {
  860. static _FORCE_INLINE_ const Projection &get(const Variant *v) { return *VariantInternal::get_projection(v); }
  861. static _FORCE_INLINE_ void set(Variant *v, const Projection &p_value) { *VariantInternal::get_projection(v) = p_value; }
  862. };
  863. template <>
  864. struct VariantInternalAccessor<Plane> {
  865. static _FORCE_INLINE_ const Plane &get(const Variant *v) { return *VariantInternal::get_plane(v); }
  866. static _FORCE_INLINE_ void set(Variant *v, const Plane &p_value) { *VariantInternal::get_plane(v) = p_value; }
  867. };
  868. template <>
  869. struct VariantInternalAccessor<Quaternion> {
  870. static _FORCE_INLINE_ const Quaternion &get(const Variant *v) { return *VariantInternal::get_quaternion(v); }
  871. static _FORCE_INLINE_ void set(Variant *v, const Quaternion &p_value) { *VariantInternal::get_quaternion(v) = p_value; }
  872. };
  873. template <>
  874. struct VariantInternalAccessor<AABB> {
  875. static _FORCE_INLINE_ const AABB &get(const Variant *v) { return *VariantInternal::get_aabb(v); }
  876. static _FORCE_INLINE_ void set(Variant *v, const AABB &p_value) { *VariantInternal::get_aabb(v) = p_value; }
  877. };
  878. template <>
  879. struct VariantInternalAccessor<Basis> {
  880. static _FORCE_INLINE_ const Basis &get(const Variant *v) { return *VariantInternal::get_basis(v); }
  881. static _FORCE_INLINE_ void set(Variant *v, const Basis &p_value) { *VariantInternal::get_basis(v) = p_value; }
  882. };
  883. template <>
  884. struct VariantInternalAccessor<Color> {
  885. static _FORCE_INLINE_ const Color &get(const Variant *v) { return *VariantInternal::get_color(v); }
  886. static _FORCE_INLINE_ void set(Variant *v, const Color &p_value) { *VariantInternal::get_color(v) = p_value; }
  887. };
  888. template <>
  889. struct VariantInternalAccessor<StringName> {
  890. static _FORCE_INLINE_ const StringName &get(const Variant *v) { return *VariantInternal::get_string_name(v); }
  891. static _FORCE_INLINE_ void set(Variant *v, const StringName &p_value) { *VariantInternal::get_string_name(v) = p_value; }
  892. };
  893. template <>
  894. struct VariantInternalAccessor<NodePath> {
  895. static _FORCE_INLINE_ const NodePath &get(const Variant *v) { return *VariantInternal::get_node_path(v); }
  896. static _FORCE_INLINE_ void set(Variant *v, const NodePath &p_value) { *VariantInternal::get_node_path(v) = p_value; }
  897. };
  898. template <>
  899. struct VariantInternalAccessor<::RID> {
  900. static _FORCE_INLINE_ const ::RID &get(const Variant *v) { return *VariantInternal::get_rid(v); }
  901. static _FORCE_INLINE_ void set(Variant *v, const ::RID &p_value) { *VariantInternal::get_rid(v) = p_value; }
  902. };
  903. template <>
  904. struct VariantInternalAccessor<Callable> {
  905. static _FORCE_INLINE_ const Callable &get(const Variant *v) { return *VariantInternal::get_callable(v); }
  906. static _FORCE_INLINE_ void set(Variant *v, const Callable &p_value) { *VariantInternal::get_callable(v) = p_value; }
  907. };
  908. template <>
  909. struct VariantInternalAccessor<Signal> {
  910. static _FORCE_INLINE_ const Signal &get(const Variant *v) { return *VariantInternal::get_signal(v); }
  911. static _FORCE_INLINE_ void set(Variant *v, const Signal &p_value) { *VariantInternal::get_signal(v) = p_value; }
  912. };
  913. template <>
  914. struct VariantInternalAccessor<Dictionary> {
  915. static _FORCE_INLINE_ const Dictionary &get(const Variant *v) { return *VariantInternal::get_dictionary(v); }
  916. static _FORCE_INLINE_ void set(Variant *v, const Dictionary &p_value) { *VariantInternal::get_dictionary(v) = p_value; }
  917. };
  918. template <>
  919. struct VariantInternalAccessor<Array> {
  920. static _FORCE_INLINE_ const Array &get(const Variant *v) { return *VariantInternal::get_array(v); }
  921. static _FORCE_INLINE_ void set(Variant *v, const Array &p_value) { *VariantInternal::get_array(v) = p_value; }
  922. };
  923. template <>
  924. struct VariantInternalAccessor<PackedByteArray> {
  925. static _FORCE_INLINE_ const PackedByteArray &get(const Variant *v) { return *VariantInternal::get_byte_array(v); }
  926. static _FORCE_INLINE_ void set(Variant *v, const PackedByteArray &p_value) { *VariantInternal::get_byte_array(v) = p_value; }
  927. };
  928. template <>
  929. struct VariantInternalAccessor<PackedInt32Array> {
  930. static _FORCE_INLINE_ const PackedInt32Array &get(const Variant *v) { return *VariantInternal::get_int32_array(v); }
  931. static _FORCE_INLINE_ void set(Variant *v, const PackedInt32Array &p_value) { *VariantInternal::get_int32_array(v) = p_value; }
  932. };
  933. template <>
  934. struct VariantInternalAccessor<PackedInt64Array> {
  935. static _FORCE_INLINE_ const PackedInt64Array &get(const Variant *v) { return *VariantInternal::get_int64_array(v); }
  936. static _FORCE_INLINE_ void set(Variant *v, const PackedInt64Array &p_value) { *VariantInternal::get_int64_array(v) = p_value; }
  937. };
  938. template <>
  939. struct VariantInternalAccessor<PackedFloat32Array> {
  940. static _FORCE_INLINE_ const PackedFloat32Array &get(const Variant *v) { return *VariantInternal::get_float32_array(v); }
  941. static _FORCE_INLINE_ void set(Variant *v, const PackedFloat32Array &p_value) { *VariantInternal::get_float32_array(v) = p_value; }
  942. };
  943. template <>
  944. struct VariantInternalAccessor<PackedFloat64Array> {
  945. static _FORCE_INLINE_ const PackedFloat64Array &get(const Variant *v) { return *VariantInternal::get_float64_array(v); }
  946. static _FORCE_INLINE_ void set(Variant *v, const PackedFloat64Array &p_value) { *VariantInternal::get_float64_array(v) = p_value; }
  947. };
  948. template <>
  949. struct VariantInternalAccessor<PackedStringArray> {
  950. static _FORCE_INLINE_ const PackedStringArray &get(const Variant *v) { return *VariantInternal::get_string_array(v); }
  951. static _FORCE_INLINE_ void set(Variant *v, const PackedStringArray &p_value) { *VariantInternal::get_string_array(v) = p_value; }
  952. };
  953. template <>
  954. struct VariantInternalAccessor<PackedVector2Array> {
  955. static _FORCE_INLINE_ const PackedVector2Array &get(const Variant *v) { return *VariantInternal::get_vector2_array(v); }
  956. static _FORCE_INLINE_ void set(Variant *v, const PackedVector2Array &p_value) { *VariantInternal::get_vector2_array(v) = p_value; }
  957. };
  958. template <>
  959. struct VariantInternalAccessor<PackedVector3Array> {
  960. static _FORCE_INLINE_ const PackedVector3Array &get(const Variant *v) { return *VariantInternal::get_vector3_array(v); }
  961. static _FORCE_INLINE_ void set(Variant *v, const PackedVector3Array &p_value) { *VariantInternal::get_vector3_array(v) = p_value; }
  962. };
  963. template <>
  964. struct VariantInternalAccessor<PackedColorArray> {
  965. static _FORCE_INLINE_ const PackedColorArray &get(const Variant *v) { return *VariantInternal::get_color_array(v); }
  966. static _FORCE_INLINE_ void set(Variant *v, const PackedColorArray &p_value) { *VariantInternal::get_color_array(v) = p_value; }
  967. };
  968. template <>
  969. struct VariantInternalAccessor<PackedVector4Array> {
  970. static _FORCE_INLINE_ const PackedVector4Array &get(const Variant *v) { return *VariantInternal::get_vector4_array(v); }
  971. static _FORCE_INLINE_ void set(Variant *v, const PackedVector4Array &p_value) { *VariantInternal::get_vector4_array(v) = p_value; }
  972. };
  973. template <>
  974. struct VariantInternalAccessor<Object *> {
  975. static _FORCE_INLINE_ Object *get(const Variant *v) { return const_cast<Object *>(*VariantInternal::get_object(v)); }
  976. static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { VariantInternal::object_assign(v, p_value); }
  977. };
  978. template <>
  979. struct VariantInternalAccessor<Variant> {
  980. static _FORCE_INLINE_ Variant &get(Variant *v) { return *v; }
  981. static _FORCE_INLINE_ const Variant &get(const Variant *v) { return *v; }
  982. static _FORCE_INLINE_ void set(Variant *v, const Variant &p_value) { *v = p_value; }
  983. };
  984. template <>
  985. struct VariantInternalAccessor<Vector<Variant>> {
  986. static _FORCE_INLINE_ Vector<Variant> get(const Variant *v) {
  987. Vector<Variant> ret;
  988. int s = VariantInternal::get_array(v)->size();
  989. ret.resize(s);
  990. for (int i = 0; i < s; i++) {
  991. ret.write[i] = VariantInternal::get_array(v)->get(i);
  992. }
  993. return ret;
  994. }
  995. static _FORCE_INLINE_ void set(Variant *v, const Vector<Variant> &p_value) {
  996. int s = p_value.size();
  997. VariantInternal::get_array(v)->resize(s);
  998. for (int i = 0; i < s; i++) {
  999. VariantInternal::get_array(v)->set(i, p_value[i]);
  1000. }
  1001. }
  1002. };
  1003. template <typename T>
  1004. struct VariantInitializer {
  1005. };
  1006. template <>
  1007. struct VariantInitializer<bool> {
  1008. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<bool>(v); }
  1009. };
  1010. #define INITIALIZER_INT(m_type) \
  1011. template <> \
  1012. struct VariantInitializer<m_type> { \
  1013. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<int64_t>(v); } \
  1014. };
  1015. INITIALIZER_INT(uint8_t)
  1016. INITIALIZER_INT(int8_t)
  1017. INITIALIZER_INT(uint16_t)
  1018. INITIALIZER_INT(int16_t)
  1019. INITIALIZER_INT(uint32_t)
  1020. INITIALIZER_INT(int32_t)
  1021. INITIALIZER_INT(uint64_t)
  1022. INITIALIZER_INT(int64_t)
  1023. INITIALIZER_INT(char32_t)
  1024. INITIALIZER_INT(Error)
  1025. INITIALIZER_INT(ObjectID)
  1026. INITIALIZER_INT(Vector2::Axis)
  1027. INITIALIZER_INT(Vector2i::Axis)
  1028. INITIALIZER_INT(Vector3::Axis)
  1029. INITIALIZER_INT(Vector3i::Axis)
  1030. INITIALIZER_INT(Vector4::Axis)
  1031. INITIALIZER_INT(Vector4i::Axis)
  1032. template <>
  1033. struct VariantInitializer<double> {
  1034. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<double>(v); }
  1035. };
  1036. template <>
  1037. struct VariantInitializer<float> {
  1038. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<double>(v); }
  1039. };
  1040. template <>
  1041. struct VariantInitializer<String> {
  1042. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string(v); }
  1043. };
  1044. template <>
  1045. struct VariantInitializer<Vector2> {
  1046. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector2>(v); }
  1047. };
  1048. template <>
  1049. struct VariantInitializer<Vector2i> {
  1050. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector2i>(v); }
  1051. };
  1052. template <>
  1053. struct VariantInitializer<Rect2> {
  1054. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Rect2>(v); }
  1055. };
  1056. template <>
  1057. struct VariantInitializer<Rect2i> {
  1058. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Rect2i>(v); }
  1059. };
  1060. template <>
  1061. struct VariantInitializer<Vector3> {
  1062. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector3>(v); }
  1063. };
  1064. template <>
  1065. struct VariantInitializer<Vector3i> {
  1066. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector3i>(v); }
  1067. };
  1068. template <>
  1069. struct VariantInitializer<Vector4> {
  1070. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector4>(v); }
  1071. };
  1072. template <>
  1073. struct VariantInitializer<Vector4i> {
  1074. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector4i>(v); }
  1075. };
  1076. template <>
  1077. struct VariantInitializer<Transform2D> {
  1078. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform2d(v); }
  1079. };
  1080. template <>
  1081. struct VariantInitializer<Plane> {
  1082. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Plane>(v); }
  1083. };
  1084. template <>
  1085. struct VariantInitializer<Quaternion> {
  1086. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Quaternion>(v); }
  1087. };
  1088. template <>
  1089. struct VariantInitializer<AABB> {
  1090. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_aabb(v); }
  1091. };
  1092. template <>
  1093. struct VariantInitializer<Basis> {
  1094. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_basis(v); }
  1095. };
  1096. template <>
  1097. struct VariantInitializer<Transform3D> {
  1098. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform3d(v); }
  1099. };
  1100. template <>
  1101. struct VariantInitializer<Projection> {
  1102. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_projection(v); }
  1103. };
  1104. template <>
  1105. struct VariantInitializer<Color> {
  1106. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Color>(v); }
  1107. };
  1108. template <>
  1109. struct VariantInitializer<StringName> {
  1110. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string_name(v); }
  1111. };
  1112. template <>
  1113. struct VariantInitializer<NodePath> {
  1114. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_node_path(v); }
  1115. };
  1116. template <>
  1117. struct VariantInitializer<::RID> {
  1118. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<::RID>(v); }
  1119. };
  1120. template <>
  1121. struct VariantInitializer<Callable> {
  1122. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_callable(v); }
  1123. };
  1124. template <>
  1125. struct VariantInitializer<Signal> {
  1126. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_signal(v); }
  1127. };
  1128. template <>
  1129. struct VariantInitializer<Dictionary> {
  1130. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_dictionary(v); }
  1131. };
  1132. template <>
  1133. struct VariantInitializer<Array> {
  1134. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_array(v); }
  1135. };
  1136. template <>
  1137. struct VariantInitializer<PackedByteArray> {
  1138. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_byte_array(v); }
  1139. };
  1140. template <>
  1141. struct VariantInitializer<PackedInt32Array> {
  1142. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_int32_array(v); }
  1143. };
  1144. template <>
  1145. struct VariantInitializer<PackedInt64Array> {
  1146. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_int64_array(v); }
  1147. };
  1148. template <>
  1149. struct VariantInitializer<PackedFloat32Array> {
  1150. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_float32_array(v); }
  1151. };
  1152. template <>
  1153. struct VariantInitializer<PackedFloat64Array> {
  1154. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_float64_array(v); }
  1155. };
  1156. template <>
  1157. struct VariantInitializer<PackedStringArray> {
  1158. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string_array(v); }
  1159. };
  1160. template <>
  1161. struct VariantInitializer<PackedVector2Array> {
  1162. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector2_array(v); }
  1163. };
  1164. template <>
  1165. struct VariantInitializer<PackedVector3Array> {
  1166. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector3_array(v); }
  1167. };
  1168. template <>
  1169. struct VariantInitializer<PackedColorArray> {
  1170. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_color_array(v); }
  1171. };
  1172. template <>
  1173. struct VariantInitializer<PackedVector4Array> {
  1174. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector4_array(v); }
  1175. };
  1176. template <>
  1177. struct VariantInitializer<Object *> {
  1178. static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_object(v); }
  1179. };
  1180. template <typename T>
  1181. struct VariantDefaultInitializer {
  1182. };
  1183. template <>
  1184. struct VariantDefaultInitializer<bool> {
  1185. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_bool(v) = false; }
  1186. };
  1187. template <>
  1188. struct VariantDefaultInitializer<int64_t> {
  1189. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_int(v) = 0; }
  1190. };
  1191. template <>
  1192. struct VariantDefaultInitializer<double> {
  1193. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_float(v) = 0.0; }
  1194. };
  1195. template <>
  1196. struct VariantDefaultInitializer<float> {
  1197. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_float(v) = 0.0; }
  1198. };
  1199. template <>
  1200. struct VariantDefaultInitializer<String> {
  1201. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_string(v) = String(); }
  1202. };
  1203. template <>
  1204. struct VariantDefaultInitializer<Vector2> {
  1205. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector2(v) = Vector2(); }
  1206. };
  1207. template <>
  1208. struct VariantDefaultInitializer<Vector2i> {
  1209. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector2i(v) = Vector2i(); }
  1210. };
  1211. template <>
  1212. struct VariantDefaultInitializer<Rect2> {
  1213. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_rect2(v) = Rect2(); }
  1214. };
  1215. template <>
  1216. struct VariantDefaultInitializer<Rect2i> {
  1217. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_rect2i(v) = Rect2i(); }
  1218. };
  1219. template <>
  1220. struct VariantDefaultInitializer<Vector3> {
  1221. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector3(v) = Vector3(); }
  1222. };
  1223. template <>
  1224. struct VariantDefaultInitializer<Vector3i> {
  1225. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector3i(v) = Vector3i(); }
  1226. };
  1227. template <>
  1228. struct VariantDefaultInitializer<Vector4> {
  1229. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector4(v) = Vector4(); }
  1230. };
  1231. template <>
  1232. struct VariantDefaultInitializer<Vector4i> {
  1233. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector4i(v) = Vector4i(); }
  1234. };
  1235. template <>
  1236. struct VariantDefaultInitializer<Transform2D> {
  1237. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_transform2d(v) = Transform2D(); }
  1238. };
  1239. template <>
  1240. struct VariantDefaultInitializer<Plane> {
  1241. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_plane(v) = Plane(); }
  1242. };
  1243. template <>
  1244. struct VariantDefaultInitializer<Quaternion> {
  1245. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_quaternion(v) = Quaternion(); }
  1246. };
  1247. template <>
  1248. struct VariantDefaultInitializer<AABB> {
  1249. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_aabb(v) = AABB(); }
  1250. };
  1251. template <>
  1252. struct VariantDefaultInitializer<Basis> {
  1253. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_basis(v) = Basis(); }
  1254. };
  1255. template <>
  1256. struct VariantDefaultInitializer<Transform3D> {
  1257. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_transform(v) = Transform3D(); }
  1258. };
  1259. template <>
  1260. struct VariantDefaultInitializer<Projection> {
  1261. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_projection(v) = Projection(); }
  1262. };
  1263. template <>
  1264. struct VariantDefaultInitializer<Color> {
  1265. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_color(v) = Color(); }
  1266. };
  1267. template <>
  1268. struct VariantDefaultInitializer<StringName> {
  1269. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_string_name(v) = StringName(); }
  1270. };
  1271. template <>
  1272. struct VariantDefaultInitializer<NodePath> {
  1273. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_node_path(v) = NodePath(); }
  1274. };
  1275. template <>
  1276. struct VariantDefaultInitializer<::RID> {
  1277. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_rid(v) = RID(); }
  1278. };
  1279. template <>
  1280. struct VariantDefaultInitializer<Callable> {
  1281. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_callable(v) = Callable(); }
  1282. };
  1283. template <>
  1284. struct VariantDefaultInitializer<Signal> {
  1285. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_signal(v) = Signal(); }
  1286. };
  1287. template <>
  1288. struct VariantDefaultInitializer<Dictionary> {
  1289. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_dictionary(v) = Dictionary(); }
  1290. };
  1291. template <>
  1292. struct VariantDefaultInitializer<Array> {
  1293. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_array(v) = Array(); }
  1294. };
  1295. template <>
  1296. struct VariantDefaultInitializer<PackedByteArray> {
  1297. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_byte_array(v) = PackedByteArray(); }
  1298. };
  1299. template <>
  1300. struct VariantDefaultInitializer<PackedInt32Array> {
  1301. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_int32_array(v) = PackedInt32Array(); }
  1302. };
  1303. template <>
  1304. struct VariantDefaultInitializer<PackedInt64Array> {
  1305. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_int64_array(v) = PackedInt64Array(); }
  1306. };
  1307. template <>
  1308. struct VariantDefaultInitializer<PackedFloat32Array> {
  1309. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_float32_array(v) = PackedFloat32Array(); }
  1310. };
  1311. template <>
  1312. struct VariantDefaultInitializer<PackedFloat64Array> {
  1313. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_float64_array(v) = PackedFloat64Array(); }
  1314. };
  1315. template <>
  1316. struct VariantDefaultInitializer<PackedStringArray> {
  1317. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_string_array(v) = PackedStringArray(); }
  1318. };
  1319. template <>
  1320. struct VariantDefaultInitializer<PackedVector2Array> {
  1321. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector2_array(v) = PackedVector2Array(); }
  1322. };
  1323. template <>
  1324. struct VariantDefaultInitializer<PackedVector3Array> {
  1325. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector3_array(v) = PackedVector3Array(); }
  1326. };
  1327. template <>
  1328. struct VariantDefaultInitializer<PackedColorArray> {
  1329. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_color_array(v) = PackedColorArray(); }
  1330. };
  1331. template <>
  1332. struct VariantDefaultInitializer<PackedVector4Array> {
  1333. static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector4_array(v) = PackedVector4Array(); }
  1334. };
  1335. template <typename T>
  1336. struct VariantTypeChanger {
  1337. static _FORCE_INLINE_ void change(Variant *v) {
  1338. if (v->get_type() != GetTypeInfo<T>::VARIANT_TYPE || GetTypeInfo<T>::VARIANT_TYPE >= Variant::PACKED_BYTE_ARRAY) { //second condition removed by optimizer
  1339. VariantInternal::clear(v);
  1340. VariantInitializer<T>::init(v);
  1341. }
  1342. }
  1343. static _FORCE_INLINE_ void change_and_reset(Variant *v) {
  1344. if (v->get_type() != GetTypeInfo<T>::VARIANT_TYPE || GetTypeInfo<T>::VARIANT_TYPE >= Variant::PACKED_BYTE_ARRAY) { //second condition removed by optimizer
  1345. VariantInternal::clear(v);
  1346. VariantInitializer<T>::init(v);
  1347. }
  1348. VariantDefaultInitializer<T>::init(v);
  1349. }
  1350. };
  1351. template <typename T>
  1352. struct VariantTypeAdjust {
  1353. _FORCE_INLINE_ static void adjust(Variant *r_ret) {
  1354. VariantTypeChanger<GetSimpleTypeT<T>>::change(r_ret);
  1355. }
  1356. };
  1357. template <>
  1358. struct VariantTypeAdjust<Variant> {
  1359. _FORCE_INLINE_ static void adjust(Variant *r_ret) {
  1360. // Do nothing for variant.
  1361. }
  1362. };
  1363. template <>
  1364. struct VariantTypeAdjust<Object *> {
  1365. _FORCE_INLINE_ static void adjust(Variant *r_ret) {
  1366. VariantInternal::clear(r_ret);
  1367. *r_ret = (Object *)nullptr;
  1368. }
  1369. };
  1370. // GDExtension helpers.
  1371. template <typename T>
  1372. struct VariantTypeConstructor {
  1373. _FORCE_INLINE_ static void variant_from_type(void *r_variant, void *p_value) {
  1374. // r_variant is provided by caller as uninitialized memory
  1375. memnew_placement(r_variant, Variant(*((T *)p_value)));
  1376. }
  1377. _FORCE_INLINE_ static void type_from_variant(void *r_value, void *p_variant) {
  1378. // r_value is provided by caller as uninitialized memory
  1379. memnew_placement(r_value, T(*reinterpret_cast<Variant *>(p_variant)));
  1380. }
  1381. };
  1382. #endif // VARIANT_INTERNAL_H