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