Skip to content

Commit

Permalink
Enforce template syntax typename over class
Browse files Browse the repository at this point in the history
  • Loading branch information
Repiteo committed Mar 10, 2024
1 parent cc1217a commit 87f5fb0
Show file tree
Hide file tree
Showing 38 changed files with 228 additions and 228 deletions.
14 changes: 7 additions & 7 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl

vararg = method["is_vararg"]
if vararg:
result.append("\ttemplate<class... Args>")
result.append("\ttemplate<typename... Args>")

method_signature = "\t"
if "is_static" in method and method["is_static"]:
Expand Down Expand Up @@ -786,7 +786,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
result.append("\tchar32_t *ptrw();")

if class_name == "Array":
result.append("\ttemplate <class... Args>")
result.append("\ttemplate <typename... Args>")
result.append("\tstatic Array make(Args... args) {")
result.append("\t\treturn helpers::append_all(Array(), args...);")
result.append("\t}")
Expand Down Expand Up @@ -1527,7 +1527,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
result.append("protected:")
# T is the custom class we want to register (from which the call initiates, going up the inheritance chain),
# B is its base class (can be a custom class too, that's why we pass it).
result.append("\ttemplate <class T, class B>")
result.append("\ttemplate <typename T, typename B>")
result.append("\tstatic void register_virtuals() {")
if class_name != "Object":
result.append(f"\t\t{inherits}::register_virtuals<T, B>();")
Expand Down Expand Up @@ -1573,16 +1573,16 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
if class_name == "Object":
result.append("")

result.append("\ttemplate<class T>")
result.append("\ttemplate<typename T>")
result.append("\tstatic T *cast_to(Object *p_object);")

result.append("\ttemplate<class T>")
result.append("\ttemplate<typename T>")
result.append("\tstatic const T *cast_to(const Object *p_object);")

result.append("\tvirtual ~Object() = default;")

elif use_template_get_node and class_name == "Node":
result.append("\ttemplate<class T>")
result.append("\ttemplate<typename T>")
result.append(
"\tT *get_node(const NodePath &p_path) const { return Object::cast_to<T>(get_node_internal(p_path)); }"
)
Expand Down Expand Up @@ -2216,7 +2216,7 @@ def make_varargs_template(
if with_public_declare:
function_signature = "public: "

function_signature += "template<class... Args> "
function_signature += "template<typename... Args> "

if static:
function_signature += "static "
Expand Down
4 changes: 2 additions & 2 deletions include/godot_cpp/classes/editor_plugin_registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class EditorPlugins {
static void remove_plugin_class(const StringName &p_class_name);
static void deinitialize(GDExtensionInitializationLevel p_level);

template <class T>
template <typename T>
static void add_by_type() {
add_plugin_class(T::get_class_static());
}
template <class T>
template <typename T>
static void remove_by_type() {
remove_plugin_class(T::get_class_static());
}
Expand Down
16 changes: 8 additions & 8 deletions include/godot_cpp/classes/ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace godot {

class RefCounted;

template <class T>
template <typename T>
class Ref {
T *reference = nullptr;

Expand Down Expand Up @@ -108,7 +108,7 @@ class Ref {
ref(p_from);
}

template <class T_Other>
template <typename T_Other>
void operator=(const Ref<T_Other> &p_from) {
RefCounted *refb = const_cast<RefCounted *>(static_cast<const RefCounted *>(p_from.ptr()));
if (!refb) {
Expand Down Expand Up @@ -144,7 +144,7 @@ class Ref {
}
}

template <class T_Other>
template <typename T_Other>
void reference_ptr(T_Other *p_ptr) {
if (reference == p_ptr) {
return;
Expand All @@ -161,7 +161,7 @@ class Ref {
ref(p_from);
}

template <class T_Other>
template <typename T_Other>
Ref(const Ref<T_Other> &p_from) {
RefCounted *refb = const_cast<RefCounted *>(static_cast<const RefCounted *>(p_from.ptr()));
if (!refb) {
Expand Down Expand Up @@ -226,7 +226,7 @@ class Ref {
}
};

template <class T>
template <typename T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
GDExtensionRefPtr ref = (GDExtensionRefPtr)p_ptr;
Expand All @@ -248,7 +248,7 @@ struct PtrToArg<Ref<T>> {
}
};

template <class T>
template <typename T>
struct PtrToArg<const Ref<T> &> {
typedef Ref<T> EncodeT;

Expand All @@ -259,7 +259,7 @@ struct PtrToArg<const Ref<T> &> {
}
};

template <class T>
template <typename T>
struct GetTypeInfo<Ref<T>, typename EnableIf<TypeInherits<RefCounted, T>::value>::type> {
static const GDExtensionVariantType VARIANT_TYPE = GDEXTENSION_VARIANT_TYPE_OBJECT;
static const GDExtensionClassMethodArgumentMetadata METADATA = GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;
Expand All @@ -269,7 +269,7 @@ struct GetTypeInfo<Ref<T>, typename EnableIf<TypeInherits<RefCounted, T>::value>
}
};

template <class T>
template <typename T>
struct GetTypeInfo<const Ref<T> &, typename EnableIf<TypeInherits<RefCounted, T>::value>::type> {
static const GDExtensionVariantType VARIANT_TYPE = GDEXTENSION_VARIANT_TYPE_OBJECT;
static const GDExtensionClassMethodArgumentMetadata METADATA = GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;
Expand Down
8 changes: 4 additions & 4 deletions include/godot_cpp/classes/wrapped.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ _FORCE_INLINE_ void snarray_add_str(Vector<StringName> &arr, const StringName &p
arr.push_back(p_str);
}

template <class... P>
template <typename... P>
_FORCE_INLINE_ void snarray_add_str(Vector<StringName> &arr, const StringName &p_str, P... p_args) {
arr.push_back(p_str);
snarray_add_str(arr, p_args...);
}

template <class... P>
template <typename... P>
_FORCE_INLINE_ Vector<StringName> snarray(P... p_args) {
Vector<StringName> arr;
snarray_add_str(arr, p_args...);
Expand All @@ -138,7 +138,7 @@ void add_engine_class_registration_callback(EngineClassRegistrationCallback p_ca
void register_engine_class(const StringName &p_name, const GDExtensionInstanceBindingCallbacks *p_callbacks);
void register_engine_classes();

template <class T>
template <typename T>
struct EngineClassRegistration {
EngineClassRegistration() {
add_engine_class_registration_callback(&EngineClassRegistration<T>::callback);
Expand Down Expand Up @@ -207,7 +207,7 @@ protected:
return (::godot::String(::godot::Wrapped::*)() const) & m_class::_to_string; \
} \
\
template <class T, class B> \
template <typename T, typename B> \
static void register_virtuals() { \
m_inherits::register_virtuals<T, B>(); \
} \
Expand Down
Loading

0 comments on commit 87f5fb0

Please sign in to comment.