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
|
#ifndef VARIANT_H
#define VARIANT_H
#include <godot/godot_variant.h>
#include "Defs.h"
#include "Basis.h"
#include "Color.h"
#include "Image.h"
#include "InputEvent.h"
#include "NodePath.h"
#include "Plane.h"
#include "PoolArrays.h"
#include "Quat.h"
#include "Rect2.h"
#include "Rect3.h"
#include "RID.h"
#include "String.h"
#include "Transform.h"
#include "Transform2D.h"
#include "Vector2.h"
#include "Vector3.h"
#include <iostream>
namespace godot {
class Dictionary;
class Array;
class Variant {
godot_variant _godot_variant;
public:
enum Type {
NIL,
// atomic types
BOOL,
INT,
REAL,
STRING,
// math types
VECTOR2, // 5
RECT2,
VECTOR3,
TRANSFORM2D,
PLANE,
QUAT, // 10
RECT3, //sorry naming convention fail :( not like it's used often
BASIS,
TRANSFORM,
// misc types
COLOR,
IMAGE, // 15
NODE_PATH,
_RID,
OBJECT,
INPUT_EVENT,
DICTIONARY, // 20
ARRAY,
// arrays
POOL_BYTE_ARRAY,
POOL_INT_ARRAY,
POOL_REAL_ARRAY,
POOL_STRING_ARRAY, // 25
POOL_VECTOR2_ARRAY,
POOL_VECTOR3_ARRAY,
POOL_COLOR_ARRAY,
VARIANT_MAX
};
Variant()
{
godot_variant_new_nil(&_godot_variant);
}
Variant(const Variant& v)
{
godot_variant_copy(&_godot_variant, &v._godot_variant);
}
Variant(bool p_bool)
{
godot_variant_new_bool(&_godot_variant, p_bool);
}
Variant(signed int p_int) // real one
{
godot_variant_new_int(&_godot_variant, p_int);
}
Variant(unsigned int p_int)
{
godot_variant_new_int(&_godot_variant, p_int);
}
Variant(signed short p_short) // real one
{
godot_variant_new_int(&_godot_variant, (int) p_short);
}
Variant(unsigned short p_short) : Variant((unsigned int) p_short) {}
Variant(signed char p_char) : Variant((signed int) p_char) {}// real one
Variant(unsigned char p_char) : Variant((unsigned int) p_char) {}
Variant(int64_t p_char) // real one
{
godot_variant_new_int(&_godot_variant, p_char);
}
Variant(uint64_t p_char)
{
godot_variant_new_int(&_godot_variant, p_char);
}
Variant(float p_float)
{
godot_variant_new_real(&_godot_variant, p_float);
}
Variant(double p_double)
{
godot_variant_new_real(&_godot_variant, p_double);
}
Variant(const String& p_string)
{
godot_variant_new_string(&_godot_variant, (godot_string *) &p_string);
}
Variant(const char * const p_cstring)
{
String s = String(p_cstring);
godot_variant_new_string(&_godot_variant, (godot_string *) &s);
}
Variant(const wchar_t * p_wstring)
{
String s = p_wstring;
godot_variant_new_string(&_godot_variant, (godot_string *) &s);
}
Variant(const Vector2& p_vector2)
{
godot_variant_new_vector2(&_godot_variant, (godot_vector2 *) &p_vector2);
}
Variant(const Rect2& p_rect2)
{
godot_variant_new_rect2(&_godot_variant, (godot_rect2 *) &p_rect2);
}
Variant(const Vector3& p_vector3)
{
godot_variant_new_vector3(&_godot_variant, (godot_vector3 *) &p_vector3);
}
Variant(const Plane& p_plane)
{
godot_variant_new_plane(&_godot_variant, (godot_plane *) &p_plane);
}
Variant(const Rect3& p_aabb)
{
godot_variant_new_rect3(&_godot_variant, (godot_rect3 *) &p_aabb);
}
Variant(const Quat& p_quat)
{
godot_variant_new_quat(&_godot_variant, (godot_quat *) &p_quat);
}
Variant(const Basis& p_transform)
{
godot_variant_new_basis(&_godot_variant, (godot_basis *) &p_transform);
}
Variant(const Transform2D& p_transform)
{
godot_variant_new_transform2d(&_godot_variant, (godot_transform2d *) &p_transform);
}
Variant(const Transform& p_transform)
{
godot_variant_new_transform(&_godot_variant, (godot_transform *) &p_transform);
}
Variant(const Color& p_color)
{
godot_variant_new_color(&_godot_variant, (godot_color *) &p_color);
}
Variant(const Image& p_image)
{
godot_variant_new_image(&_godot_variant, (godot_image *) &p_image);
}
Variant(const NodePath& p_path)
{
godot_variant_new_node_path(&_godot_variant, (godot_node_path *) &p_path);
}
Variant(const RID& p_rid)
{
godot_variant_new_rid(&_godot_variant, (godot_rid *) &p_rid);
}
Variant(const Object* p_object)
{
godot_variant_new_object(&_godot_variant, (godot_object *) p_object);
}
Variant(const InputEvent& p_input_event)
{
godot_variant_new_input_event(&_godot_variant, (godot_input_event *) &p_input_event);
}
Variant(const Dictionary& p_dictionary)
{
godot_variant_new_dictionary(&_godot_variant, (godot_dictionary *) &p_dictionary);
}
Variant(const Array& p_array)
{
godot_variant_new_array(&_godot_variant, (godot_array *) &p_array);
}
Variant(const PoolByteArray& p_raw_array)
{
godot_variant_new_pool_byte_array(&_godot_variant, (godot_pool_byte_array *) &p_raw_array);
}
Variant(const PoolIntArray& p_int_array)
{
godot_variant_new_pool_int_array(&_godot_variant, (godot_pool_int_array *) &p_int_array);
}
Variant(const PoolRealArray& p_real_array)
{
godot_variant_new_pool_real_array(&_godot_variant, (godot_pool_real_array *) &p_real_array);
}
Variant(const PoolStringArray& p_string_array)
{
godot_variant_new_pool_string_array(&_godot_variant, (godot_pool_string_array *) &p_string_array);
}
Variant(const PoolVector2Array& p_vector2_array)
{
godot_variant_new_pool_vector2_array(&_godot_variant, (godot_pool_vector2_array *) &p_vector2_array);
}
Variant(const PoolVector3Array& p_vector3_array)
{
godot_variant_new_pool_vector3_array(&_godot_variant, (godot_pool_vector3_array *) &p_vector3_array);
}
Variant(const PoolColorArray& p_color_array)
{
godot_variant_new_pool_color_array(&_godot_variant, (godot_pool_color_array *) &p_color_array);
}
Variant &operator =(const Variant& v)
{
godot_variant_copy(&_godot_variant, &v._godot_variant);
return *this;
}
operator bool() const
{
bool valid = false;
bool result = booleanize(valid);
return valid && result;
}
operator signed int() const
{
return godot_variant_as_int(&_godot_variant);
}
operator unsigned int() const // this is the real one
{
return godot_variant_as_int(&_godot_variant);
}
operator signed short() const
{
return godot_variant_as_int(&_godot_variant);
}
operator unsigned short() const
{
return godot_variant_as_int(&_godot_variant);
}
operator signed char() const
{
return godot_variant_as_int(&_godot_variant);
}
operator unsigned char() const
{
return godot_variant_as_int(&_godot_variant);
}
operator int64_t() const
{
return godot_variant_as_int(&_godot_variant);
}
operator uint64_t() const
{
return godot_variant_as_int(&_godot_variant);
}
operator wchar_t() const
{
return godot_variant_as_int(&_godot_variant);
}
operator float() const
{
return godot_variant_as_real(&_godot_variant);
}
operator double() const
{
return godot_variant_as_real(&_godot_variant);
}
operator String() const
{
godot_string s = godot_variant_as_string(&_godot_variant);
return *(String *) &s;
}
operator Vector2() const
{
godot_vector2 s = godot_variant_as_vector2(&_godot_variant);
return *(Vector2 *) &s;
}
operator Rect2() const
{
godot_rect2 s = godot_variant_as_rect2(&_godot_variant);
return *(Rect2 *) &s;
}
operator Vector3() const
{
godot_vector3 s = godot_variant_as_vector3(&_godot_variant);
return *(Vector3 *) &s;
}
operator Plane() const
{
godot_plane s = godot_variant_as_plane(&_godot_variant);
return *(Plane *) &s;
}
operator Rect3() const
{
godot_rect3 s = godot_variant_as_rect3(&_godot_variant);
return *(Rect3 *) &s;
}
operator Quat() const
{
godot_quat s = godot_variant_as_quat(&_godot_variant);
return *(Quat *) &s;
}
operator Basis() const
{
godot_basis s = godot_variant_as_basis(&_godot_variant);
return *(Basis *) &s;
}
operator Transform() const
{
godot_transform s = godot_variant_as_transform(&_godot_variant);
return *(Transform *) &s;
}
operator Transform2D() const
{
godot_transform2d s = godot_variant_as_transform2d(&_godot_variant);
return *(Transform2D *) &s;
}
operator Color() const
{
godot_color s = godot_variant_as_color(&_godot_variant);
return *(Color *) &s;
}
operator Image() const
{
godot_image s = godot_variant_as_image(&_godot_variant);
return *(Image *) &s;
}
operator NodePath() const
{
godot_node_path s = godot_variant_as_node_path(&_godot_variant);
return *(NodePath *) &s;
}
operator RID() const
{
godot_rid s = godot_variant_as_rid(&_godot_variant);
return *(RID *) &s;
}
operator InputEvent() const
{
godot_input_event s = godot_variant_as_input_event(&_godot_variant);
return *(InputEvent *) &s;
}
operator Object() const;
operator Dictionary() const;
operator Array() const;
operator PoolByteArray() const
{
godot_pool_byte_array s = godot_variant_as_pool_byte_array(&_godot_variant);
return *(PoolByteArray *) &s;
}
operator PoolIntArray() const
{
godot_pool_int_array s = godot_variant_as_pool_int_array(&_godot_variant);
return *(PoolIntArray *) &s;
}
operator PoolRealArray() const
{
godot_pool_real_array s = godot_variant_as_pool_real_array(&_godot_variant);
return *(PoolRealArray *) &s;
}
operator PoolStringArray() const
{
godot_pool_string_array s = godot_variant_as_pool_string_array(&_godot_variant);
return *(PoolStringArray *) &s;
}
operator PoolVector2Array() const
{
godot_pool_vector2_array s = godot_variant_as_pool_vector2_array(&_godot_variant);
return *(PoolVector2Array *) &s;
}
operator PoolVector3Array() const
{
godot_pool_vector3_array s = godot_variant_as_pool_vector3_array(&_godot_variant);
return *(PoolVector3Array *) &s;
}
operator PoolColorArray() const
{
godot_pool_color_array s = godot_variant_as_pool_color_array(&_godot_variant);
return *(PoolColorArray *) &s;
}
Type get_type() const
{
return (Type) godot_variant_get_type(&_godot_variant);
}
Variant call(const String& method, const Variant **args, const int arg_count)
{
Variant v;
*(godot_variant *) &v = godot_variant_call(&_godot_variant, (godot_string *) &method, (const godot_variant **)args, arg_count);
return v;
}
bool has_method(const String& method)
{
return godot_variant_has_method(&_godot_variant, (godot_string *) &method);
}
bool operator ==(const Variant& b) const
{
return godot_variant_operator_equal(&_godot_variant, &b._godot_variant);
}
bool operator !=(const Variant& b) const
{
return !(*this == b);
}
bool operator <(const Variant& b) const
{
return godot_variant_operator_less(&_godot_variant, &b._godot_variant);
}
bool operator <=(const Variant& b) const
{
return (*this < b) || (*this == b);
}
bool operator >(const Variant& b) const
{
return !(*this <= b);
}
bool operator >=(const Variant& b) const
{
return !(*this < b);
}
bool hash_compare(const Variant& b) const
{
return godot_variant_hash_compare(&_godot_variant, &b._godot_variant);
}
bool booleanize(bool &valid) const
{
return godot_variant_booleanize(&_godot_variant, &valid);
}
~Variant()
{
godot_variant_destroy(&_godot_variant);
}
};
}
#endif // VARIANT_H
|