/*************************************************************************/ /* variant_internal.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* 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. */ /*************************************************************************/ #ifndef VARIANT_INTERNAL_H #define VARIANT_INTERNAL_H #include "variant.h" // For use when you want to access the internal pointer of a Variant directly. // Use with caution. You need to be sure that the type is correct. class VariantInternal { public: // Set type. _FORCE_INLINE_ static void initialize(Variant *v, Variant::Type p_type) { v->type = p_type; } // Atomic types. _FORCE_INLINE_ static bool *get_bool(Variant *v) { return &v->_data._bool; } _FORCE_INLINE_ static const bool *get_bool(const Variant *v) { return &v->_data._bool; } _FORCE_INLINE_ static int64_t *get_int(Variant *v) { return &v->_data._int; } _FORCE_INLINE_ static const int64_t *get_int(const Variant *v) { return &v->_data._int; } _FORCE_INLINE_ static double *get_float(Variant *v) { return &v->_data._float; } _FORCE_INLINE_ static const double *get_float(const Variant *v) { return &v->_data._float; } _FORCE_INLINE_ static String *get_string(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const String *get_string(const Variant *v) { return reinterpret_cast(v->_data._mem); } // Math types. _FORCE_INLINE_ static Vector2 *get_vector2(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Vector2 *get_vector2(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Vector2i *get_vector2i(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Vector2i *get_vector2i(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Rect2 *get_rect2(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Rect2 *get_rect2(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Rect2i *get_rect2i(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Rect2i *get_rect2i(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Vector3 *get_vector3(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Vector3 *get_vector3(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Vector3i *get_vector3i(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Vector3i *get_vector3i(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Transform2D *get_transform2d(Variant *v) { return v->_data._transform2d; } _FORCE_INLINE_ static const Transform2D *get_transform2d(const Variant *v) { return v->_data._transform2d; } _FORCE_INLINE_ static Plane *get_plane(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Plane *get_plane(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Quat *get_quat(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Quat *get_quat(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static ::AABB *get_aabb(Variant *v) { return v->_data._aabb; } _FORCE_INLINE_ static const ::AABB *get_aabb(const Variant *v) { return v->_data._aabb; } _FORCE_INLINE_ static Basis *get_basis(Variant *v) { return v->_data._basis; } _FORCE_INLINE_ static const Basis *get_basis(const Variant *v) { return v->_data._basis; } _FORCE_INLINE_ static Transform *get_transform(Variant *v) { return v->_data._transform; } _FORCE_INLINE_ static const Transform *get_transform(const Variant *v) { return v->_data._transform; } // Misc types. _FORCE_INLINE_ static Color *get_color(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Color *get_color(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static StringName *get_string_name(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const StringName *get_string_name(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static NodePath *get_node_path(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const NodePath *get_node_path(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static ::RID *get_rid(Variant *v) { return reinterpret_cast<::RID *>(v->_data._mem); } _FORCE_INLINE_ static const ::RID *get_rid(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Callable *get_callable(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Callable *get_callable(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Signal *get_signal(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Signal *get_signal(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Dictionary *get_dictionary(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Dictionary *get_dictionary(const Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static Array *get_array(Variant *v) { return reinterpret_cast(v->_data._mem); } _FORCE_INLINE_ static const Array *get_array(const Variant *v) { return reinterpret_cast(v->_data._mem); } // Typed arrays. _FORCE_INLINE_ static PackedByteArray *get_byte_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedByteArray *get_byte_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedInt32Array *get_int32_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedInt32Array *get_int32_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedInt64Array *get_int64_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedInt64Array *get_int64_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedFloat32Array *get_float32_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedFloat32Array *get_float32_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedFloat64Array *get_float64_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedFloat64Array *get_float64_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedStringArray *get_string_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedStringArray *get_string_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedVector2Array *get_vector2_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedVector2Array *get_vector2_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedVector3Array *get_vector3_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedVector3Array *get_vector3_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedColorArray *get_color_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedColorArray *get_color_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static Object **get_object(Variant *v) { return (Object **)&v->_get_obj().obj; } _FORCE_INLINE_ static const Object **get_object(const Variant *v) { return (const Object **)&v->_get_obj().obj; } _FORCE_INLINE_ static const ObjectID get_object_id(const Variant *v) { return v->_get_obj().id; } template _FORCE_INLINE_ static void init_generic(Variant *v) { v->type = GetTypeInfo::VARIANT_TYPE; } _FORCE_INLINE_ static void init_string(Variant *v) { memnew_placement(v->_data._mem, String); v->type = Variant::STRING; } _FORCE_INLINE_ static void init_transform2d(Variant *v) { v->_data._transform2d = memnew(Transform2D); v->type = Variant::TRANSFORM2D; } _FORCE_INLINE_ static void init_aabb(Variant *v) { v->_data._aabb = memnew(AABB); v->type = Variant::AABB; } _FORCE_INLINE_ static void init_basis(Variant *v) { v->_data._basis = memnew(Basis); v->type = Variant::BASIS; } _FORCE_INLINE_ static void init_transform(Variant *v) { v->_data._transform = memnew(Transform); v->type = Variant::TRANSFORM; } _FORCE_INLINE_ static void init_string_name(Variant *v) { memnew_placement(v->_data._mem, StringName); v->type = Variant::STRING_NAME; } _FORCE_INLINE_ static void init_node_path(Variant *v) { memnew_placement(v->_data._mem, NodePath); v->type = Variant::NODE_PATH; } _FORCE_INLINE_ static void init_callable(Variant *v) { memnew_placement(v->_data._mem, Callable); v->type = Variant::CALLABLE; } _FORCE_INLINE_ static void init_signal(Variant *v) { memnew_placement(v->_data._mem, Signal); v->type = Variant::SIGNAL; } _FORCE_INLINE_ static void init_dictionary(Variant *v) { memnew_placement(v->_data._mem, Dictionary); v->type = Variant::DICTIONARY; } _FORCE_INLINE_ static void init_array(Variant *v) { memnew_placement(v->_data._mem, Array); v->type = Variant::ARRAY; } _FORCE_INLINE_ static void init_byte_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_BYTE_ARRAY; } _FORCE_INLINE_ static void init_int32_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_INT32_ARRAY; } _FORCE_INLINE_ static void init_int64_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_INT64_ARRAY; } _FORCE_INLINE_ static void init_float32_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_FLOAT32_ARRAY; } _FORCE_INLINE_ static void init_float64_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_FLOAT64_ARRAY; } _FORCE_INLINE_ static void init_string_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_STRING_ARRAY; } _FORCE_INLINE_ static void init_vector2_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_VECTOR2_ARRAY; } _FORCE_INLINE_ static void init_vector3_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_VECTOR3_ARRAY; } _FORCE_INLINE_ static void init_color_array(Variant *v) { v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_COLOR_ARRAY; } _FORCE_INLINE_ static void clear(Variant *v) { v->clear(); } static void object_assign(Variant *v, const Variant *o); //needs to use reference, do away _FORCE_INLINE_ static void object_assign_null(Variant *v) { v->_get_obj().obj = nullptr; v->_get_obj().id = ObjectID(); } }; template struct VariantGetInternalPtr { }; template <> struct VariantGetInternalPtr { static bool *get_ptr(Variant *v) { return VariantInternal::get_bool(v); } static const bool *get_ptr(const Variant *v) { return VariantInternal::get_bool(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; template <> struct VariantGetInternalPtr { static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); } static const double *get_ptr(const Variant *v) { return VariantInternal::get_float(v); } }; template <> struct VariantGetInternalPtr { static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); } static const double *get_ptr(const Variant *v) { return VariantInternal::get_float(v); } }; template <> struct VariantGetInternalPtr { static String *get_ptr(Variant *v) { return VariantInternal::get_string(v); } static const String *get_ptr(const Variant *v) { return VariantInternal::get_string(v); } }; template <> struct VariantGetInternalPtr { static Vector2 *get_ptr(Variant *v) { return VariantInternal::get_vector2(v); } static const Vector2 *get_ptr(const Variant *v) { return VariantInternal::get_vector2(v); } }; template <> struct VariantGetInternalPtr { static Vector2i *get_ptr(Variant *v) { return VariantInternal::get_vector2i(v); } static const Vector2i *get_ptr(const Variant *v) { return VariantInternal::get_vector2i(v); } }; template <> struct VariantGetInternalPtr { static Rect2 *get_ptr(Variant *v) { return VariantInternal::get_rect2(v); } static const Rect2 *get_ptr(const Variant *v) { return VariantInternal::get_rect2(v); } }; template <> struct VariantGetInternalPtr { static Rect2i *get_ptr(Variant *v) { return VariantInternal::get_rect2i(v); } static const Rect2i *get_ptr(const Variant *v) { return VariantInternal::get_rect2i(v); } }; template <> struct VariantGetInternalPtr { static Vector3 *get_ptr(Variant *v) { return VariantInternal::get_vector3(v); } static const Vector3 *get_ptr(const Variant *v) { return VariantInternal::get_vector3(v); } }; template <> struct VariantGetInternalPtr { static Vector3i *get_ptr(Variant *v) { return VariantInternal::get_vector3i(v); } static const Vector3i *get_ptr(const Variant *v) { return VariantInternal::get_vector3i(v); } }; template <> struct VariantGetInternalPtr { static Transform2D *get_ptr(Variant *v) { return VariantInternal::get_transform2d(v); } static const Transform2D *get_ptr(const Variant *v) { return VariantInternal::get_transform2d(v); } }; template <> struct VariantGetInternalPtr { static Transform *get_ptr(Variant *v) { return VariantInternal::get_transform(v); } static const Transform *get_ptr(const Variant *v) { return VariantInternal::get_transform(v); } }; template <> struct VariantGetInternalPtr { static Plane *get_ptr(Variant *v) { return VariantInternal::get_plane(v); } static const Plane *get_ptr(const Variant *v) { return VariantInternal::get_plane(v); } }; template <> struct VariantGetInternalPtr { static Quat *get_ptr(Variant *v) { return VariantInternal::get_quat(v); } static const Quat *get_ptr(const Variant *v) { return VariantInternal::get_quat(v); } }; template <> struct VariantGetInternalPtr<::AABB> { static ::AABB *get_ptr(Variant *v) { return VariantInternal::get_aabb(v); } static const ::AABB *get_ptr(const Variant *v) { return VariantInternal::get_aabb(v); } }; template <> struct VariantGetInternalPtr { static Basis *get_ptr(Variant *v) { return VariantInternal::get_basis(v); } static const Basis *get_ptr(const Variant *v) { return VariantInternal::get_basis(v); } }; // template <> struct VariantGetInternalPtr { static Color *get_ptr(Variant *v) { return VariantInternal::get_color(v); } static const Color *get_ptr(const Variant *v) { return VariantInternal::get_color(v); } }; template <> struct VariantGetInternalPtr { static StringName *get_ptr(Variant *v) { return VariantInternal::get_string_name(v); } static const StringName *get_ptr(const Variant *v) { return VariantInternal::get_string_name(v); } }; template <> struct VariantGetInternalPtr { static NodePath *get_ptr(Variant *v) { return VariantInternal::get_node_path(v); } static const NodePath *get_ptr(const Variant *v) { return VariantInternal::get_node_path(v); } }; template <> struct VariantGetInternalPtr<::RID> { static ::RID *get_ptr(Variant *v) { return VariantInternal::get_rid(v); } static const ::RID *get_ptr(const Variant *v) { return VariantInternal::get_rid(v); } }; template <> struct VariantGetInternalPtr { static Callable *get_ptr(Variant *v) { return VariantInternal::get_callable(v); } static const Callable *get_ptr(const Variant *v) { return VariantInternal::get_callable(v); } }; template <> struct VariantGetInternalPtr { static Signal *get_ptr(Variant *v) { return VariantInternal::get_signal(v); } static const Signal *get_ptr(const Variant *v) { return VariantInternal::get_signal(v); } }; template <> struct VariantGetInternalPtr { static Dictionary *get_ptr(Variant *v) { return VariantInternal::get_dictionary(v); } static const Dictionary *get_ptr(const Variant *v) { return VariantInternal::get_dictionary(v); } }; template <> struct VariantGetInternalPtr { static Array *get_ptr(Variant *v) { return VariantInternal::get_array(v); } static const Array *get_ptr(const Variant *v) { return VariantInternal::get_array(v); } }; template <> struct VariantGetInternalPtr { static PackedByteArray *get_ptr(Variant *v) { return VariantInternal::get_byte_array(v); } static const PackedByteArray *get_ptr(const Variant *v) { return VariantInternal::get_byte_array(v); } }; template <> struct VariantGetInternalPtr { static PackedInt32Array *get_ptr(Variant *v) { return VariantInternal::get_int32_array(v); } static const PackedInt32Array *get_ptr(const Variant *v) { return VariantInternal::get_int32_array(v); } }; template <> struct VariantGetInternalPtr { static PackedInt64Array *get_ptr(Variant *v) { return VariantInternal::get_int64_array(v); } static const PackedInt64Array *get_ptr(const Variant *v) { return VariantInternal::get_int64_array(v); } }; template <> struct VariantGetInternalPtr { static PackedFloat32Array *get_ptr(Variant *v) { return VariantInternal::get_float32_array(v); } static const PackedFloat32Array *get_ptr(const Variant *v) { return VariantInternal::get_float32_array(v); } }; template <> struct VariantGetInternalPtr { static PackedFloat64Array *get_ptr(Variant *v) { return VariantInternal::get_float64_array(v); } static const PackedFloat64Array *get_ptr(const Variant *v) { return VariantInternal::get_float64_array(v); } }; template <> struct VariantGetInternalPtr { static PackedStringArray *get_ptr(Variant *v) { return VariantInternal::get_string_array(v); } static const PackedStringArray *get_ptr(const Variant *v) { return VariantInternal::get_string_array(v); } }; template <> struct VariantGetInternalPtr { static PackedVector2Array *get_ptr(Variant *v) { return VariantInternal::get_vector2_array(v); } static const PackedVector2Array *get_ptr(const Variant *v) { return VariantInternal::get_vector2_array(v); } }; template <> struct VariantGetInternalPtr { static PackedVector3Array *get_ptr(Variant *v) { return VariantInternal::get_vector3_array(v); } static const PackedVector3Array *get_ptr(const Variant *v) { return VariantInternal::get_vector3_array(v); } }; template <> struct VariantGetInternalPtr { static PackedColorArray *get_ptr(Variant *v) { return VariantInternal::get_color_array(v); } static const PackedColorArray *get_ptr(const Variant *v) { return VariantInternal::get_color_array(v); } }; template struct VariantInternalAccessor { }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ bool get(const Variant *v) { return *VariantInternal::get_bool(v); } static _FORCE_INLINE_ void set(Variant *v, bool p_value) { *VariantInternal::get_bool(v) = p_value; } }; #define VARIANT_ACCESSOR_NUMBER(m_type) \ template <> \ struct VariantInternalAccessor { \ static _FORCE_INLINE_ m_type get(const Variant *v) { return (m_type)*VariantInternal::get_int(v); } \ static _FORCE_INLINE_ void set(Variant *v, m_type p_value) { *VariantInternal::get_int(v) = p_value; } \ }; VARIANT_ACCESSOR_NUMBER(int8_t) VARIANT_ACCESSOR_NUMBER(uint8_t) VARIANT_ACCESSOR_NUMBER(int16_t) VARIANT_ACCESSOR_NUMBER(uint16_t) VARIANT_ACCESSOR_NUMBER(int32_t) VARIANT_ACCESSOR_NUMBER(uint32_t) VARIANT_ACCESSOR_NUMBER(int64_t) VARIANT_ACCESSOR_NUMBER(uint64_t) VARIANT_ACCESSOR_NUMBER(char32_t) VARIANT_ACCESSOR_NUMBER(Error) VARIANT_ACCESSOR_NUMBER(Margin) template <> struct VariantInternalAccessor { static _FORCE_INLINE_ ObjectID get(const Variant *v) { return ObjectID(*VariantInternal::get_int(v)); } static _FORCE_INLINE_ void set(Variant *v, ObjectID p_value) { *VariantInternal::get_int(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ float get(const Variant *v) { return *VariantInternal::get_float(v); } static _FORCE_INLINE_ void set(Variant *v, float p_value) { *VariantInternal::get_float(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ double get(const Variant *v) { return *VariantInternal::get_float(v); } static _FORCE_INLINE_ void set(Variant *v, double p_value) { *VariantInternal::get_float(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const String &get(const Variant *v) { return *VariantInternal::get_string(v); } static _FORCE_INLINE_ void set(Variant *v, const String &p_value) { *VariantInternal::get_string(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Vector2 &get(const Variant *v) { return *VariantInternal::get_vector2(v); } static _FORCE_INLINE_ void set(Variant *v, const Vector2 &p_value) { *VariantInternal::get_vector2(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Vector2i &get(const Variant *v) { return *VariantInternal::get_vector2i(v); } static _FORCE_INLINE_ void set(Variant *v, const Vector2i &p_value) { *VariantInternal::get_vector2i(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Rect2 &get(const Variant *v) { return *VariantInternal::get_rect2(v); } static _FORCE_INLINE_ void set(Variant *v, const Rect2 &p_value) { *VariantInternal::get_rect2(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Rect2i &get(const Variant *v) { return *VariantInternal::get_rect2i(v); } static _FORCE_INLINE_ void set(Variant *v, const Rect2i &p_value) { *VariantInternal::get_rect2i(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Vector3 &get(const Variant *v) { return *VariantInternal::get_vector3(v); } static _FORCE_INLINE_ void set(Variant *v, const Vector3 &p_value) { *VariantInternal::get_vector3(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Vector3i &get(const Variant *v) { return *VariantInternal::get_vector3i(v); } static _FORCE_INLINE_ void set(Variant *v, const Vector3i &p_value) { *VariantInternal::get_vector3i(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Transform2D &get(const Variant *v) { return *VariantInternal::get_transform2d(v); } static _FORCE_INLINE_ void set(Variant *v, const Transform2D &p_value) { *VariantInternal::get_transform2d(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Transform &get(const Variant *v) { return *VariantInternal::get_transform(v); } static _FORCE_INLINE_ void set(Variant *v, const Transform &p_value) { *VariantInternal::get_transform(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Plane &get(const Variant *v) { return *VariantInternal::get_plane(v); } static _FORCE_INLINE_ void set(Variant *v, const Plane &p_value) { *VariantInternal::get_plane(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Quat &get(const Variant *v) { return *VariantInternal::get_quat(v); } static _FORCE_INLINE_ void set(Variant *v, const Quat &p_value) { *VariantInternal::get_quat(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const AABB &get(const Variant *v) { return *VariantInternal::get_aabb(v); } static _FORCE_INLINE_ void set(Variant *v, const AABB &p_value) { *VariantInternal::get_aabb(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Basis &get(const Variant *v) { return *VariantInternal::get_basis(v); } static _FORCE_INLINE_ void set(Variant *v, const Basis &p_value) { *VariantInternal::get_basis(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Color &get(const Variant *v) { return *VariantInternal::get_color(v); } static _FORCE_INLINE_ void set(Variant *v, const Color &p_value) { *VariantInternal::get_color(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const StringName &get(const Variant *v) { return *VariantInternal::get_string_name(v); } static _FORCE_INLINE_ void set(Variant *v, const StringName &p_value) { *VariantInternal::get_string_name(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const NodePath &get(const Variant *v) { return *VariantInternal::get_node_path(v); } static _FORCE_INLINE_ void set(Variant *v, const NodePath &p_value) { *VariantInternal::get_node_path(v) = p_value; } }; template <> struct VariantInternalAccessor<::RID> { static _FORCE_INLINE_ const ::RID &get(const Variant *v) { return *VariantInternal::get_rid(v); } static _FORCE_INLINE_ void set(Variant *v, const ::RID &p_value) { *VariantInternal::get_rid(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Callable &get(const Variant *v) { return *VariantInternal::get_callable(v); } static _FORCE_INLINE_ void set(Variant *v, const Callable &p_value) { *VariantInternal::get_callable(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Signal &get(const Variant *v) { return *VariantInternal::get_signal(v); } static _FORCE_INLINE_ void set(Variant *v, const Signal &p_value) { *VariantInternal::get_signal(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Dictionary &get(const Variant *v) { return *VariantInternal::get_dictionary(v); } static _FORCE_INLINE_ void set(Variant *v, const Dictionary &p_value) { *VariantInternal::get_dictionary(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const Array &get(const Variant *v) { return *VariantInternal::get_array(v); } static _FORCE_INLINE_ void set(Variant *v, const Array &p_value) { *VariantInternal::get_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedByteArray &get(const Variant *v) { return *VariantInternal::get_byte_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedByteArray &p_value) { *VariantInternal::get_byte_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedInt32Array &get(const Variant *v) { return *VariantInternal::get_int32_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedInt32Array &p_value) { *VariantInternal::get_int32_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedInt64Array &get(const Variant *v) { return *VariantInternal::get_int64_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedInt64Array &p_value) { *VariantInternal::get_int64_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedFloat32Array &get(const Variant *v) { return *VariantInternal::get_float32_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedFloat32Array &p_value) { *VariantInternal::get_float32_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedFloat64Array &get(const Variant *v) { return *VariantInternal::get_float64_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedFloat64Array &p_value) { *VariantInternal::get_float64_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedStringArray &get(const Variant *v) { return *VariantInternal::get_string_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedStringArray &p_value) { *VariantInternal::get_string_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedVector2Array &get(const Variant *v) { return *VariantInternal::get_vector2_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedVector2Array &p_value) { *VariantInternal::get_vector2_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedVector3Array &get(const Variant *v) { return *VariantInternal::get_vector3_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedVector3Array &p_value) { *VariantInternal::get_vector3_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ const PackedColorArray &get(const Variant *v) { return *VariantInternal::get_color_array(v); } static _FORCE_INLINE_ void set(Variant *v, const PackedColorArray &p_value) { *VariantInternal::get_color_array(v) = p_value; } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ Object *get(const Variant *v) { return const_cast(*VariantInternal::get_object(v)); } static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { *VariantInternal::get_object(v) = const_cast(p_value); } }; template <> struct VariantInternalAccessor { static _FORCE_INLINE_ Variant &get(Variant *v) { return *v; } static _FORCE_INLINE_ const Variant &get(const Variant *v) { return *v; } static _FORCE_INLINE_ void set(Variant *v, const Variant &p_value) { *v = p_value; } }; template <> struct VariantInternalAccessor> { static _FORCE_INLINE_ Vector get(const Variant *v) { Vector ret; int s = VariantInternal::get_array(v)->size(); ret.resize(s); for (int i = 0; i < s; i++) { ret.write[i] = VariantInternal::get_array(v)->get(i); } return ret; } static _FORCE_INLINE_ void set(Variant *v, const Vector &p_value) { int s = p_value.size(); VariantInternal::get_array(v)->resize(s); for (int i = 0; i < s; i++) { VariantInternal::get_array(v)->set(i, p_value[i]); } } }; template struct VariantInitializer { }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; #define INITIALIZER_INT(m_type) \ template <> \ struct VariantInitializer { \ static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } \ }; INITIALIZER_INT(uint8_t) INITIALIZER_INT(int8_t) INITIALIZER_INT(uint16_t) INITIALIZER_INT(int16_t) INITIALIZER_INT(uint32_t) INITIALIZER_INT(int32_t) INITIALIZER_INT(uint64_t) INITIALIZER_INT(int64_t) INITIALIZER_INT(char32_t) INITIALIZER_INT(Error) INITIALIZER_INT(ObjectID) template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform2d(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_aabb(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_basis(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string_name(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_node_path(v); } }; template <> struct VariantInitializer<::RID> { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<::RID>(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_callable(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_signal(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_dictionary(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_byte_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_int32_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_int64_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_float32_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_float64_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector2_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector3_array(v); } }; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_color_array(v); } }; template struct VariantZeroAssigner { }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_bool(v) = false; } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_int(v) = 0; } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_float(v) = 0.0; } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_float(v) = 0.0; } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector2(v) = Vector2(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector2i(v) = Vector2i(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_rect2(v) = Rect2(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_rect2i(v) = Rect2i(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector3(v) = Vector3(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector3i(v) = Vector3i(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_transform2d(v) = Transform2D(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_plane(v) = Plane(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_quat(v) = Quat(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_aabb(v) = AABB(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_basis(v) = Basis(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_transform(v) = Transform(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_color(v) = Color(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner<::RID> { static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_rid(v) = RID(); } }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template <> struct VariantZeroAssigner { static _FORCE_INLINE_ void zero(Variant *v) {} }; template struct VariantTypeChanger { static _FORCE_INLINE_ void change(Variant *v) { if (v->get_type() != GetTypeInfo::VARIANT_TYPE || GetTypeInfo::VARIANT_TYPE >= Variant::PACKED_BYTE_ARRAY) { //second condition removed by optimizer VariantInternal::clear(v); VariantInitializer::init(v); } } static _FORCE_INLINE_ void change_and_reset(Variant *v) { if (v->get_type() != GetTypeInfo::VARIANT_TYPE || GetTypeInfo::VARIANT_TYPE >= Variant::PACKED_BYTE_ARRAY) { //second condition removed by optimizer VariantInternal::clear(v); VariantInitializer::init(v); } VariantZeroAssigner::zero(v); } }; #endif // VARIANT_INTERNAL_H