Skip to content

Commit

Permalink
Core: Refactor typing logic to use type_traits
Browse files Browse the repository at this point in the history
  • Loading branch information
Repiteo committed Feb 9, 2025
1 parent 36d90c7 commit 5b15263
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 182 deletions.
12 changes: 6 additions & 6 deletions core/object/method_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class MethodBindTR : public MethodBind {
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
return call_get_argument_type<P...>(p_arg);
} else {
return GetTypeInfo<R>::VARIANT_TYPE;
return variant_type_v<R>;
}
}

Expand All @@ -508,7 +508,7 @@ class MethodBindTR : public MethodBind {
if (p_arg >= 0) {
return call_get_argument_metadata<P...>(p_arg);
} else {
return GetTypeInfo<R>::METADATA;
return metadata_v<R>;
}
}
#endif
Expand Down Expand Up @@ -584,7 +584,7 @@ class MethodBindTRC : public MethodBind {
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
return call_get_argument_type<P...>(p_arg);
} else {
return GetTypeInfo<R>::VARIANT_TYPE;
return variant_type_v<R>;
}
}

Expand All @@ -604,7 +604,7 @@ class MethodBindTRC : public MethodBind {
if (p_arg >= 0) {
return call_get_argument_metadata<P...>(p_arg);
} else {
return GetTypeInfo<R>::METADATA;
return metadata_v<R>;
}
}
#endif
Expand Down Expand Up @@ -736,7 +736,7 @@ class MethodBindTRS : public MethodBind {
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
return call_get_argument_type<P...>(p_arg);
} else {
return GetTypeInfo<R>::VARIANT_TYPE;
return variant_type_v<R>;
}
}

Expand All @@ -756,7 +756,7 @@ class MethodBindTRS : public MethodBind {
if (p_arg >= 0) {
return call_get_argument_metadata<P...>(p_arg);
} else {
return GetTypeInfo<R>::METADATA;
return metadata_v<R>;
}
}

Expand Down
286 changes: 198 additions & 88 deletions core/variant/type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,163 @@
#define TYPE_INFO_H

#include "core/typedefs.h"
#include "core/variant/variant_enums.h"

#include <type_traits>
class Variant;
class String;
struct Vector2;
struct Vector2i;
struct Rect2;
struct Rect2i;
struct Vector3;
struct Vector3i;
struct Transform2D;
struct Vector4;
struct Vector4i;
struct Plane;
struct Quaternion;
struct AABB;
struct Basis;
struct Transform3D;
struct Projection;
struct Color;
class StringName;
class NodePath;
class RID;
class Object;
class Callable;
class Signal;
class Dictionary;
class Array;
struct IPAddress;

template <typename T>
class TypedArray;
template <typename K, typename V>
class TypedDictionary;
template <typename T>
class Ref;
template <typename T>
class BitField;
template <typename T>
struct Vector;

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/o threads (target=template_release, threads=no)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/o threads (target=template_release, threads=no)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/o threads (target=template_release, threads=no)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/ threads (target=template_release, threads=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/ threads (target=template_release, threads=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/ threads (target=template_release, threads=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor, tests=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor, tests=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor, tests=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

the following warning is treated as an error

Check warning on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'Vector': type name first seen using 'class' now seen using 'struct'

Check warning on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'Vector': type name first seen using 'class' now seen using 'struct'

Check warning on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'Vector': type name first seen using 'class' now seen using 'struct'

Check warning on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'Vector': type name first seen using 'class' now seen using 'struct'

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

the following warning is treated as an error

Check warning on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'Vector': type name first seen using 'class' now seen using 'struct'

Check warning on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'Vector': type name first seen using 'class' now seen using 'struct'

Check warning on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'Vector': type name first seen using 'class' now seen using 'struct'

Check warning on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'Vector': type name first seen using 'class' now seen using 'struct'

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

Check failure on line 74 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)

struct template 'Vector' was previously declared as a class template; this is valid, but may result in linker errors under the Microsoft C++ ABI

using PackedByteArray = Vector<uint8_t>;
using PackedInt32Array = Vector<int32_t>;
using PackedInt64Array = Vector<int64_t>;
using PackedFloat32Array = Vector<float>;
using PackedFloat64Array = Vector<double>;
using PackedStringArray = Vector<String>;
using PackedVector2Array = Vector<Vector2>;
using PackedVector3Array = Vector<Vector3>;
using PackedColorArray = Vector<Color>;
using PackedVector4Array = Vector<Vector4>;

namespace godot {
namespace details {

template <typename T>
struct _VariantType {
static constexpr VariantType value() {
if constexpr (std::is_same_v<T, Variant>) {
return VariantType::NIL;
} else if constexpr (std::is_same_v<T, bool>) {
return VariantType::BOOL;
} else if constexpr (std::is_integral_v<T> || std::is_enum_v<T>) {
return VariantType::INT;
} else if constexpr (std::is_floating_point_v<T>) {
return VariantType::FLOAT;
} else if constexpr (std::is_same_v<T, String> || std::is_same_v<T, IPAddress> || std::is_same_v<T, char *> || std::is_same_v<T, char16_t *> || std::is_same_v<T, char32_t *> || std::is_same_v<T, wchar_t *>) {
return VariantType::STRING;
} else if constexpr (std::is_same_v<T, Vector2>) {
return VariantType::VECTOR2;
} else if constexpr (std::is_same_v<T, Vector2i>) {
return VariantType::VECTOR2I;
} else if constexpr (std::is_same_v<T, Rect2>) {
return VariantType::RECT2;
} else if constexpr (std::is_same_v<T, Rect2i>) {
return VariantType::RECT2I;
} else if constexpr (std::is_same_v<T, Vector3>) {
return VariantType::VECTOR3;
} else if constexpr (std::is_same_v<T, Vector3i>) {
return VariantType::VECTOR3I;
} else if constexpr (std::is_same_v<T, Transform2D>) {
return VariantType::TRANSFORM2D;
} else if constexpr (std::is_same_v<T, Vector4>) {
return VariantType::VECTOR4;
} else if constexpr (std::is_same_v<T, Vector4i>) {
return VariantType::VECTOR4I;
} else if constexpr (std::is_same_v<T, Plane>) {
return VariantType::PLANE;
} else if constexpr (std::is_same_v<T, Quaternion>) {
return VariantType::QUATERNION;
} else if constexpr (std::is_same_v<T, ::AABB>) {
return VariantType::AABB;
} else if constexpr (std::is_same_v<T, Basis>) {
return VariantType::BASIS;
} else if constexpr (std::is_same_v<T, Transform3D>) {
return VariantType::TRANSFORM3D;
} else if constexpr (std::is_same_v<T, Projection>) {
return VariantType::PROJECTION;
} else if constexpr (std::is_same_v<T, Color>) {
return VariantType::COLOR;
} else if constexpr (std::is_same_v<T, StringName>) {
return VariantType::STRING_NAME;
} else if constexpr (std::is_same_v<T, NodePath>) {
return VariantType::NODE_PATH;
} else if constexpr (std::is_same_v<T, ::RID>) {
return VariantType::RID;
} else if constexpr (std::is_pointer_v<T>) {
return VariantType::OBJECT;
} else if constexpr (std::is_same_v<T, Callable>) {
return VariantType::CALLABLE;
} else if constexpr (std::is_same_v<T, Signal>) {
return VariantType::SIGNAL;
} else if constexpr (std::is_same_v<T, Dictionary>) {
return VariantType::DICTIONARY;
} else if constexpr (std::is_same_v<T, Array>) {
return VariantType::ARRAY;
} else if constexpr (std::is_same_v<T, PackedByteArray>) {
return VariantType::PACKED_BYTE_ARRAY;
} else if constexpr (std::is_same_v<T, PackedInt32Array>) {
return VariantType::PACKED_INT32_ARRAY;
} else if constexpr (std::is_same_v<T, PackedInt64Array>) {
return VariantType::PACKED_INT64_ARRAY;
} else if constexpr (std::is_same_v<T, PackedFloat32Array>) {
return VariantType::PACKED_FLOAT32_ARRAY;
} else if constexpr (std::is_same_v<T, PackedFloat64Array>) {
return VariantType::PACKED_FLOAT64_ARRAY;
} else if constexpr (std::is_same_v<T, PackedStringArray> || std::is_same_v<T, Vector<StringName>>) {
return VariantType::PACKED_STRING_ARRAY;
} else if constexpr (std::is_same_v<T, PackedVector2Array>) {
return VariantType::PACKED_VECTOR2_ARRAY;
} else if constexpr (std::is_same_v<T, PackedVector3Array>) {
return VariantType::PACKED_VECTOR3_ARRAY;
} else if constexpr (std::is_same_v<T, PackedColorArray>) {
return VariantType::PACKED_COLOR_ARRAY;
} else if constexpr (std::is_same_v<T, PackedVector4Array>) {
return VariantType::PACKED_VECTOR4_ARRAY;
} else {
static_assert(false, "Unassigned variant type!");

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

static_assert failed "Unassigned variant type!"

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

static assertion failed: Unassigned variant type!

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

static assertion failed: Unassigned variant type!

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

static assertion failed: Unassigned variant type!

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

static assertion failed: Unassigned variant type!

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

static assertion failed: Unassigned variant type!

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

static assertion failed: Unassigned variant type!

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor, tests=yes)

static assertion failed: Unassigned variant type!

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor, tests=yes)

static assertion failed: Unassigned variant type!

Check failure on line 172 in core/variant/type_info.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor, tests=yes)

static assertion failed: Unassigned variant type!
}
}
};

template <typename T>
struct _VariantType<Ref<T>> {
static constexpr VariantType value() { return VariantType::OBJECT; }
};

template <typename T>
struct _VariantType<BitField<T>> {
static constexpr VariantType value() { return VariantType::INT; }
};

} // namespace details
} // namespace godot

template <typename T>
inline constexpr VariantType variant_type_v = godot::details::_VariantType<std::decay_t<T>>::value();

namespace GodotTypeInfo {
enum Metadata {
Expand All @@ -53,6 +208,48 @@ enum Metadata {
};
}

namespace godot {
namespace details {

template <typename T>
struct _Metadata {
static constexpr GodotTypeInfo::Metadata value() {
if constexpr (std::is_same_v<T, int8_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_INT8;
} else if constexpr (std::is_same_v<T, int16_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_INT16;
} else if constexpr (std::is_same_v<T, int32_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_INT32;
} else if constexpr (std::is_same_v<T, int64_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_INT64;
} else if constexpr (std::is_same_v<T, uint8_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_UINT8;
} else if constexpr (std::is_same_v<T, uint16_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_UINT16;
} else if constexpr (std::is_same_v<T, uint32_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_UINT32;
} else if constexpr (std::is_same_v<T, uint64_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_UINT64;
} else if constexpr (std::is_same_v<T, float>) {
return GodotTypeInfo::Metadata::METADATA_REAL_IS_FLOAT;
} else if constexpr (std::is_same_v<T, double>) {
return GodotTypeInfo::Metadata::METADATA_REAL_IS_DOUBLE;
} else if constexpr (std::is_same_v<T, char16_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_CHAR16;
} else if constexpr (std::is_same_v<T, char32_t>) {
return GodotTypeInfo::Metadata::METADATA_INT_IS_CHAR32;
} else {
return GodotTypeInfo::Metadata::METADATA_NONE;
}
}
};

} // namespace details
} // namespace godot

template <typename T>
inline constexpr GodotTypeInfo::Metadata metadata_v = godot::details::_Metadata<std::decay_t<T>>::value();

// If the compiler fails because it's trying to instantiate the primary 'GetTypeInfo' template
// instead of one of the specializations, it's most likely because the type 'T' is not supported.
// If 'T' is a class that inherits 'Object', make sure it can see the actual class declaration
Expand All @@ -61,93 +258,6 @@ enum Metadata {
template <typename T, typename = void>
struct GetTypeInfo;

#define MAKE_TYPE_INFO(m_type, m_var_type) \
template <> \
struct GetTypeInfo<m_type> { \
static const Variant::Type VARIANT_TYPE = m_var_type; \
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return PropertyInfo(VARIANT_TYPE, String()); \
} \
}; \
template <> \
struct GetTypeInfo<const m_type &> { \
static const Variant::Type VARIANT_TYPE = m_var_type; \
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return PropertyInfo(VARIANT_TYPE, String()); \
} \
};

#define MAKE_TYPE_INFO_WITH_META(m_type, m_var_type, m_metadata) \
template <> \
struct GetTypeInfo<m_type> { \
static const Variant::Type VARIANT_TYPE = m_var_type; \
static const GodotTypeInfo::Metadata METADATA = m_metadata; \
static inline PropertyInfo get_class_info() { \
return PropertyInfo(VARIANT_TYPE, String()); \
} \
}; \
template <> \
struct GetTypeInfo<const m_type &> { \
static const Variant::Type VARIANT_TYPE = m_var_type; \
static const GodotTypeInfo::Metadata METADATA = m_metadata; \
static inline PropertyInfo get_class_info() { \
return PropertyInfo(VARIANT_TYPE, String()); \
} \
};

MAKE_TYPE_INFO(bool, Variant::BOOL)
MAKE_TYPE_INFO_WITH_META(uint8_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_UINT8)
MAKE_TYPE_INFO_WITH_META(int8_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_INT8)
MAKE_TYPE_INFO_WITH_META(uint16_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_UINT16)
MAKE_TYPE_INFO_WITH_META(int16_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_INT16)
MAKE_TYPE_INFO_WITH_META(uint32_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_UINT32)
MAKE_TYPE_INFO_WITH_META(int32_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_INT32)
MAKE_TYPE_INFO_WITH_META(uint64_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_UINT64)
MAKE_TYPE_INFO_WITH_META(int64_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_INT64)
MAKE_TYPE_INFO_WITH_META(char16_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_CHAR16)
MAKE_TYPE_INFO_WITH_META(char32_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_CHAR32)
MAKE_TYPE_INFO_WITH_META(float, Variant::FLOAT, GodotTypeInfo::METADATA_REAL_IS_FLOAT)
MAKE_TYPE_INFO_WITH_META(double, Variant::FLOAT, GodotTypeInfo::METADATA_REAL_IS_DOUBLE)

MAKE_TYPE_INFO(String, Variant::STRING)
MAKE_TYPE_INFO(Vector2, Variant::VECTOR2)
MAKE_TYPE_INFO(Rect2, Variant::RECT2)
MAKE_TYPE_INFO(Vector3, Variant::VECTOR3)
MAKE_TYPE_INFO(Vector2i, Variant::VECTOR2I)
MAKE_TYPE_INFO(Rect2i, Variant::RECT2I)
MAKE_TYPE_INFO(Vector3i, Variant::VECTOR3I)
MAKE_TYPE_INFO(Vector4, Variant::VECTOR4)
MAKE_TYPE_INFO(Vector4i, Variant::VECTOR4I)
MAKE_TYPE_INFO(Transform2D, Variant::TRANSFORM2D)
MAKE_TYPE_INFO(Plane, Variant::PLANE)
MAKE_TYPE_INFO(Quaternion, Variant::QUATERNION)
MAKE_TYPE_INFO(AABB, Variant::AABB)
MAKE_TYPE_INFO(Basis, Variant::BASIS)
MAKE_TYPE_INFO(Transform3D, Variant::TRANSFORM3D)
MAKE_TYPE_INFO(Projection, Variant::PROJECTION)
MAKE_TYPE_INFO(Color, Variant::COLOR)
MAKE_TYPE_INFO(StringName, Variant::STRING_NAME)
MAKE_TYPE_INFO(NodePath, Variant::NODE_PATH)
MAKE_TYPE_INFO(RID, Variant::RID)
MAKE_TYPE_INFO(Callable, Variant::CALLABLE)
MAKE_TYPE_INFO(Signal, Variant::SIGNAL)
MAKE_TYPE_INFO(Dictionary, Variant::DICTIONARY)
MAKE_TYPE_INFO(Array, Variant::ARRAY)
MAKE_TYPE_INFO(PackedByteArray, Variant::PACKED_BYTE_ARRAY)
MAKE_TYPE_INFO(PackedInt32Array, Variant::PACKED_INT32_ARRAY)
MAKE_TYPE_INFO(PackedInt64Array, Variant::PACKED_INT64_ARRAY)
MAKE_TYPE_INFO(PackedFloat32Array, Variant::PACKED_FLOAT32_ARRAY)
MAKE_TYPE_INFO(PackedFloat64Array, Variant::PACKED_FLOAT64_ARRAY)
MAKE_TYPE_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY)
MAKE_TYPE_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPE_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPE_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY)
MAKE_TYPE_INFO(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY)

MAKE_TYPE_INFO(IPAddress, Variant::STRING)

//objectID
template <>
struct GetTypeInfo<ObjectID> {
Expand Down
Loading

0 comments on commit 5b15263

Please sign in to comment.