-
-
Notifications
You must be signed in to change notification settings - Fork 582
/
variant.cpp
802 lines (667 loc) · 24.5 KB
/
variant.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
/**************************************************************************/
/* variant.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include <godot_cpp/variant/variant.hpp>
#include <godot_cpp/godot.hpp>
#include <godot_cpp/core/binder_common.hpp>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <utility>
namespace godot {
GDExtensionVariantFromTypeConstructorFunc Variant::from_type_constructor[Variant::VARIANT_MAX]{};
GDExtensionTypeFromVariantConstructorFunc Variant::to_type_constructor[Variant::VARIANT_MAX]{};
void Variant::init_bindings() {
// Start from 1 to skip NIL.
for (int i = 1; i < VARIANT_MAX; i++) {
from_type_constructor[i] = internal::gdextension_interface_get_variant_from_type_constructor((GDExtensionVariantType)i);
to_type_constructor[i] = internal::gdextension_interface_get_variant_to_type_constructor((GDExtensionVariantType)i);
}
StringName::init_bindings();
String::init_bindings();
NodePath::init_bindings();
RID::init_bindings();
Callable::init_bindings();
Signal::init_bindings();
Dictionary::init_bindings();
Array::init_bindings();
PackedByteArray::init_bindings();
PackedInt32Array::init_bindings();
PackedInt64Array::init_bindings();
PackedFloat32Array::init_bindings();
PackedFloat64Array::init_bindings();
PackedStringArray::init_bindings();
PackedVector2Array::init_bindings();
PackedVector3Array::init_bindings();
PackedColorArray::init_bindings();
}
Variant::Variant() {
internal::gdextension_interface_variant_new_nil(_native_ptr());
}
Variant::Variant(GDExtensionConstVariantPtr native_ptr) {
internal::gdextension_interface_variant_new_copy(_native_ptr(), native_ptr);
}
Variant::Variant(const Variant &other) {
internal::gdextension_interface_variant_new_copy(_native_ptr(), other._native_ptr());
}
Variant::Variant(Variant &&other) {
std::swap(opaque, other.opaque);
}
Variant::Variant(bool v) {
GDExtensionBool encoded;
PtrToArg<bool>::encode(v, &encoded);
from_type_constructor[BOOL](_native_ptr(), &encoded);
}
Variant::Variant(int64_t v) {
GDExtensionInt encoded;
PtrToArg<int64_t>::encode(v, &encoded);
from_type_constructor[INT](_native_ptr(), &encoded);
}
Variant::Variant(double v) {
double encoded;
PtrToArg<double>::encode(v, &encoded);
from_type_constructor[FLOAT](_native_ptr(), &encoded);
}
Variant::Variant(const String &v) {
from_type_constructor[STRING](_native_ptr(), v._native_ptr());
}
Variant::Variant(const Vector2 &v) {
from_type_constructor[VECTOR2](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Vector2i &v) {
from_type_constructor[VECTOR2I](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Rect2 &v) {
from_type_constructor[RECT2](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Rect2i &v) {
from_type_constructor[RECT2I](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Vector3 &v) {
from_type_constructor[VECTOR3](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Vector3i &v) {
from_type_constructor[VECTOR3I](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Transform2D &v) {
from_type_constructor[TRANSFORM2D](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Vector4 &v) {
from_type_constructor[VECTOR4](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Vector4i &v) {
from_type_constructor[VECTOR4I](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Plane &v) {
from_type_constructor[PLANE](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Quaternion &v) {
from_type_constructor[QUATERNION](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const godot::AABB &v) {
from_type_constructor[AABB](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Basis &v) {
from_type_constructor[BASIS](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Transform3D &v) {
from_type_constructor[TRANSFORM3D](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Projection &v) {
from_type_constructor[PROJECTION](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const Color &v) {
from_type_constructor[COLOR](_native_ptr(), (GDExtensionTypePtr)&v);
}
Variant::Variant(const StringName &v) {
from_type_constructor[STRING_NAME](_native_ptr(), v._native_ptr());
}
Variant::Variant(const NodePath &v) {
from_type_constructor[NODE_PATH](_native_ptr(), v._native_ptr());
}
Variant::Variant(const godot::RID &v) {
from_type_constructor[RID](_native_ptr(), v._native_ptr());
}
Variant::Variant(const Object *v) {
if (v) {
from_type_constructor[OBJECT](_native_ptr(), const_cast<GodotObject **>(&v->_owner));
} else {
GodotObject *nullobject = nullptr;
from_type_constructor[OBJECT](_native_ptr(), &nullobject);
}
}
Variant::Variant(const ObjectID &p_id) :
Variant(p_id.operator uint64_t()) {
}
Variant::Variant(const Callable &v) {
from_type_constructor[CALLABLE](_native_ptr(), v._native_ptr());
}
Variant::Variant(const Signal &v) {
from_type_constructor[SIGNAL](_native_ptr(), v._native_ptr());
}
Variant::Variant(const Dictionary &v) {
from_type_constructor[DICTIONARY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const Array &v) {
from_type_constructor[ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedByteArray &v) {
from_type_constructor[PACKED_BYTE_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedInt32Array &v) {
from_type_constructor[PACKED_INT32_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedInt64Array &v) {
from_type_constructor[PACKED_INT64_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedFloat32Array &v) {
from_type_constructor[PACKED_FLOAT32_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedFloat64Array &v) {
from_type_constructor[PACKED_FLOAT64_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedStringArray &v) {
from_type_constructor[PACKED_STRING_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedVector2Array &v) {
from_type_constructor[PACKED_VECTOR2_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedVector3Array &v) {
from_type_constructor[PACKED_VECTOR3_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::Variant(const PackedColorArray &v) {
from_type_constructor[PACKED_COLOR_ARRAY](_native_ptr(), v._native_ptr());
}
Variant::~Variant() {
internal::gdextension_interface_variant_destroy(_native_ptr());
}
Variant::operator bool() const {
GDExtensionBool result;
to_type_constructor[BOOL](&result, _native_ptr());
return PtrToArg<bool>::convert(&result);
}
Variant::operator int64_t() const {
GDExtensionInt result;
to_type_constructor[INT](&result, _native_ptr());
return PtrToArg<int64_t>::convert(&result);
}
Variant::operator int32_t() const {
return static_cast<int32_t>(operator int64_t());
}
Variant::operator int16_t() const {
return static_cast<int16_t>(operator int64_t());
}
Variant::operator int8_t() const {
return static_cast<int8_t>(operator int64_t());
}
Variant::operator uint64_t() const {
return static_cast<uint64_t>(operator int64_t());
}
Variant::operator uint32_t() const {
return static_cast<uint32_t>(operator int64_t());
}
Variant::operator uint16_t() const {
return static_cast<uint16_t>(operator int64_t());
}
Variant::operator uint8_t() const {
return static_cast<uint8_t>(operator int64_t());
}
Variant::operator double() const {
double result;
to_type_constructor[FLOAT](&result, _native_ptr());
return PtrToArg<double>::convert(&result);
}
Variant::operator float() const {
return static_cast<float>(operator double());
}
Variant::operator String() const {
String result;
to_type_constructor[STRING](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator Vector2() const {
Vector2 result;
to_type_constructor[VECTOR2]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Vector2i() const {
Vector2i result;
to_type_constructor[VECTOR2I]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Rect2() const {
Rect2 result;
to_type_constructor[RECT2]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Rect2i() const {
Rect2i result;
to_type_constructor[RECT2I]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Vector3() const {
Vector3 result;
to_type_constructor[VECTOR3]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Vector3i() const {
Vector3i result;
to_type_constructor[VECTOR3I]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Transform2D() const {
Transform2D result;
to_type_constructor[TRANSFORM2D]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Vector4() const {
Vector4 result;
to_type_constructor[VECTOR4]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Vector4i() const {
Vector4i result;
to_type_constructor[VECTOR4I]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Plane() const {
Plane result;
to_type_constructor[PLANE]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Quaternion() const {
Quaternion result;
to_type_constructor[QUATERNION]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator godot::AABB() const {
godot::AABB result;
to_type_constructor[AABB]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Basis() const {
Basis result;
to_type_constructor[BASIS]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Transform3D() const {
Transform3D result;
to_type_constructor[TRANSFORM3D]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Projection() const {
Projection result;
to_type_constructor[PROJECTION]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator Color() const {
Color result;
to_type_constructor[COLOR]((GDExtensionTypePtr)&result, _native_ptr());
return result;
}
Variant::operator StringName() const {
StringName result;
to_type_constructor[STRING_NAME](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator NodePath() const {
NodePath result;
to_type_constructor[NODE_PATH](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator godot::RID() const {
godot::RID result;
to_type_constructor[RID](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator Object *() const {
GodotObject *obj;
to_type_constructor[OBJECT](&obj, _native_ptr());
if (obj == nullptr) {
return nullptr;
}
return internal::get_object_instance_binding(obj);
}
Variant::operator ObjectID() const {
if (get_type() == Type::INT) {
return ObjectID(operator uint64_t());
} else if (get_type() == Type::OBJECT) {
Object *obj = operator Object *();
if (obj != nullptr) {
return ObjectID(obj->get_instance_id());
} else {
return ObjectID();
}
} else {
return ObjectID();
}
}
Variant::operator Callable() const {
Callable result;
to_type_constructor[CALLABLE](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator Signal() const {
Signal result;
to_type_constructor[SIGNAL](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator Dictionary() const {
Dictionary result;
to_type_constructor[DICTIONARY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator Array() const {
Array result;
to_type_constructor[ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedByteArray() const {
PackedByteArray result;
to_type_constructor[PACKED_BYTE_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedInt32Array() const {
PackedInt32Array result;
to_type_constructor[PACKED_INT32_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedInt64Array() const {
PackedInt64Array result;
to_type_constructor[PACKED_INT64_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedFloat32Array() const {
PackedFloat32Array result;
to_type_constructor[PACKED_FLOAT32_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedFloat64Array() const {
PackedFloat64Array result;
to_type_constructor[PACKED_FLOAT64_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedStringArray() const {
PackedStringArray result;
to_type_constructor[PACKED_STRING_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedVector2Array() const {
PackedVector2Array result;
to_type_constructor[PACKED_VECTOR2_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedVector3Array() const {
PackedVector3Array result;
to_type_constructor[PACKED_VECTOR3_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant::operator PackedColorArray() const {
PackedColorArray result;
to_type_constructor[PACKED_COLOR_ARRAY](result._native_ptr(), _native_ptr());
return result;
}
Variant &Variant::operator=(const Variant &other) {
clear();
internal::gdextension_interface_variant_new_copy(_native_ptr(), other._native_ptr());
return *this;
}
Variant &Variant::operator=(Variant &&other) {
std::swap(opaque, other.opaque);
return *this;
}
bool Variant::operator==(const Variant &other) const {
if (get_type() != other.get_type()) {
return false;
}
bool valid = false;
Variant result;
evaluate(OP_EQUAL, *this, other, result, valid);
return result.operator bool();
}
bool Variant::operator!=(const Variant &other) const {
if (get_type() != other.get_type()) {
return true;
}
bool valid = false;
Variant result;
evaluate(OP_NOT_EQUAL, *this, other, result, valid);
return result.operator bool();
}
bool Variant::operator<(const Variant &other) const {
if (get_type() != other.get_type()) {
return get_type() < other.get_type();
}
bool valid = false;
Variant result;
evaluate(OP_LESS, *this, other, result, valid);
return result.operator bool();
}
void Variant::callp(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
internal::gdextension_interface_variant_call(_native_ptr(), method._native_ptr(), reinterpret_cast<GDExtensionConstVariantPtr *>(args), argcount, r_ret._native_ptr(), &r_error);
}
void Variant::callp_static(Variant::Type type, const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
internal::gdextension_interface_variant_call_static(static_cast<GDExtensionVariantType>(type), method._native_ptr(), reinterpret_cast<GDExtensionConstVariantPtr *>(args), argcount, r_ret._native_ptr(), &r_error);
}
void Variant::evaluate(const Operator &op, const Variant &a, const Variant &b, Variant &r_ret, bool &r_valid) {
GDExtensionBool valid;
internal::gdextension_interface_variant_evaluate(static_cast<GDExtensionVariantOperator>(op), a._native_ptr(), b._native_ptr(), r_ret._native_ptr(), &valid);
r_valid = PtrToArg<bool>::convert(&valid);
}
void Variant::set(const Variant &key, const Variant &value, bool *r_valid) {
GDExtensionBool valid;
internal::gdextension_interface_variant_set(_native_ptr(), key._native_ptr(), value._native_ptr(), &valid);
if (r_valid) {
*r_valid = PtrToArg<bool>::convert(&valid);
}
}
void Variant::set_named(const StringName &name, const Variant &value, bool &r_valid) {
GDExtensionBool valid;
internal::gdextension_interface_variant_set_named(_native_ptr(), name._native_ptr(), value._native_ptr(), &valid);
r_valid = PtrToArg<bool>::convert(&valid);
}
void Variant::set_indexed(int64_t index, const Variant &value, bool &r_valid, bool &r_oob) {
GDExtensionBool valid, oob;
internal::gdextension_interface_variant_set_indexed(_native_ptr(), index, value._native_ptr(), &valid, &oob);
r_valid = PtrToArg<bool>::convert(&valid);
r_oob = PtrToArg<bool>::convert(&oob);
}
void Variant::set_keyed(const Variant &key, const Variant &value, bool &r_valid) {
GDExtensionBool valid;
internal::gdextension_interface_variant_set_keyed(_native_ptr(), key._native_ptr(), value._native_ptr(), &valid);
r_valid = PtrToArg<bool>::convert(&valid);
}
Variant Variant::get(const Variant &key, bool *r_valid) const {
Variant result;
GDExtensionBool valid;
internal::gdextension_interface_variant_get(_native_ptr(), key._native_ptr(), result._native_ptr(), &valid);
if (r_valid) {
*r_valid = PtrToArg<bool>::convert(&valid);
}
return result;
}
Variant Variant::get_named(const StringName &name, bool &r_valid) const {
Variant result;
GDExtensionBool valid;
internal::gdextension_interface_variant_get_named(_native_ptr(), name._native_ptr(), result._native_ptr(), &valid);
r_valid = PtrToArg<bool>::convert(&valid);
return result;
}
Variant Variant::get_indexed(int64_t index, bool &r_valid, bool &r_oob) const {
Variant result;
GDExtensionBool valid;
GDExtensionBool oob;
internal::gdextension_interface_variant_get_indexed(_native_ptr(), index, result._native_ptr(), &valid, &oob);
r_valid = PtrToArg<bool>::convert(&valid);
r_oob = PtrToArg<bool>::convert(&oob);
return result;
}
Variant Variant::get_keyed(const Variant &key, bool &r_valid) const {
Variant result;
GDExtensionBool valid;
internal::gdextension_interface_variant_get_keyed(_native_ptr(), key._native_ptr(), result._native_ptr(), &valid);
r_valid = PtrToArg<bool>::convert(&valid);
return result;
}
bool Variant::in(const Variant &index, bool *r_valid) const {
Variant result;
bool valid;
evaluate(OP_IN, *this, index, result, valid);
if (r_valid) {
*r_valid = valid;
}
return result.operator bool();
}
bool Variant::iter_init(Variant &r_iter, bool &r_valid) const {
GDExtensionBool valid;
GDExtensionBool result = internal::gdextension_interface_variant_iter_init(_native_ptr(), r_iter._native_ptr(), &valid);
r_valid = PtrToArg<bool>::convert(&valid);
return PtrToArg<bool>::convert(&result);
}
bool Variant::iter_next(Variant &r_iter, bool &r_valid) const {
GDExtensionBool valid;
GDExtensionBool result = internal::gdextension_interface_variant_iter_next(_native_ptr(), r_iter._native_ptr(), &valid);
r_valid = PtrToArg<bool>::convert(&valid);
return PtrToArg<bool>::convert(&result);
}
Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
Variant result;
GDExtensionBool valid;
internal::gdextension_interface_variant_iter_get(_native_ptr(), r_iter._native_ptr(), result._native_ptr(), &valid);
r_valid = PtrToArg<bool>::convert(&valid);
return result;
}
Variant::Type Variant::get_type() const {
return static_cast<Variant::Type>(internal::gdextension_interface_variant_get_type(_native_ptr()));
}
bool Variant::has_method(const StringName &method) const {
GDExtensionBool has = internal::gdextension_interface_variant_has_method(_native_ptr(), method._native_ptr());
return PtrToArg<bool>::convert(&has);
}
bool Variant::has_key(const Variant &key, bool *r_valid) const {
GDExtensionBool valid;
GDExtensionBool has = internal::gdextension_interface_variant_has_key(_native_ptr(), key._native_ptr(), &valid);
if (r_valid) {
*r_valid = PtrToArg<bool>::convert(&valid);
}
return PtrToArg<bool>::convert(&has);
}
bool Variant::has_member(Variant::Type type, const StringName &member) {
GDExtensionBool has = internal::gdextension_interface_variant_has_member(static_cast<GDExtensionVariantType>(type), member._native_ptr());
return PtrToArg<bool>::convert(&has);
}
uint32_t Variant::hash() const {
GDExtensionInt hash = internal::gdextension_interface_variant_hash(_native_ptr());
return PtrToArg<uint32_t>::convert(&hash);
}
uint32_t Variant::recursive_hash(int recursion_count) const {
GDExtensionInt hash = internal::gdextension_interface_variant_recursive_hash(_native_ptr(), recursion_count);
return PtrToArg<uint32_t>::convert(&hash);
}
bool Variant::hash_compare(const Variant &variant) const {
GDExtensionBool compare = internal::gdextension_interface_variant_hash_compare(_native_ptr(), variant._native_ptr());
return PtrToArg<bool>::convert(&compare);
}
bool Variant::booleanize() const {
GDExtensionBool booleanized = internal::gdextension_interface_variant_booleanize(_native_ptr());
return PtrToArg<bool>::convert(&booleanized);
}
String Variant::stringify() const {
String result;
internal::gdextension_interface_variant_stringify(_native_ptr(), result._native_ptr());
return result;
}
Variant Variant::duplicate(bool deep) const {
Variant result;
GDExtensionBool _deep;
PtrToArg<bool>::encode(deep, &_deep);
internal::gdextension_interface_variant_duplicate(_native_ptr(), result._native_ptr(), _deep);
return result;
}
String Variant::get_type_name(Variant::Type type) {
String result;
internal::gdextension_interface_variant_get_type_name(static_cast<GDExtensionVariantType>(type), result._native_ptr());
return result;
}
bool Variant::can_convert(Variant::Type from, Variant::Type to) {
GDExtensionBool can = internal::gdextension_interface_variant_can_convert(static_cast<GDExtensionVariantType>(from), static_cast<GDExtensionVariantType>(to));
return PtrToArg<bool>::convert(&can);
}
bool Variant::can_convert_strict(Variant::Type from, Variant::Type to) {
GDExtensionBool can = internal::gdextension_interface_variant_can_convert_strict(static_cast<GDExtensionVariantType>(from), static_cast<GDExtensionVariantType>(to));
return PtrToArg<bool>::convert(&can);
}
void Variant::clear() {
static const bool needs_deinit[Variant::VARIANT_MAX] = {
false, // NIL,
false, // BOOL,
false, // INT,
false, // FLOAT,
true, // STRING,
false, // VECTOR2,
false, // VECTOR2I,
false, // RECT2,
false, // RECT2I,
false, // VECTOR3,
false, // VECTOR3I,
true, // TRANSFORM2D,
false, // VECTOR4,
false, // VECTOR4I,
false, // PLANE,
false, // QUATERNION,
true, // AABB,
true, // BASIS,
true, // TRANSFORM3D,
true, // PROJECTION,
// misc types
false, // COLOR,
true, // STRING_NAME,
true, // NODE_PATH,
false, // RID,
true, // OBJECT,
true, // CALLABLE,
true, // SIGNAL,
true, // DICTIONARY,
true, // ARRAY,
// typed arrays
true, // PACKED_BYTE_ARRAY,
true, // PACKED_INT32_ARRAY,
true, // PACKED_INT64_ARRAY,
true, // PACKED_FLOAT32_ARRAY,
true, // PACKED_FLOAT64_ARRAY,
true, // PACKED_STRING_ARRAY,
true, // PACKED_VECTOR2_ARRAY,
true, // PACKED_VECTOR3_ARRAY,
true, // PACKED_COLOR_ARRAY,
};
if (unlikely(needs_deinit[get_type()])) { // Make it fast for types that don't need deinit.
internal::gdextension_interface_variant_destroy(_native_ptr());
}
internal::gdextension_interface_variant_new_nil(_native_ptr());
}
} // namespace godot