浏览代码

Remove dependency of variant.h in print_string.h

Co-authored-by: Lukas Tenbrink <[email protected]>
Co-authored-by: A Thousand Ships <[email protected]>
Yufeng Ying 3 月之前
父节点
当前提交
05dae23f18

+ 10 - 2
core/string/print_string.cpp

@@ -341,6 +341,14 @@ bool is_print_verbose_enabled() {
 	return OS::get_singleton()->is_stdout_verbose();
 	return OS::get_singleton()->is_stdout_verbose();
 }
 }
 
 
-String stringify_variants(const Variant &p_var) {
-	return p_var.operator String();
+String stringify_variants(const Span<Variant> &p_vars) {
+	if (p_vars.is_empty()) {
+		return String();
+	}
+	String result = String(p_vars[0]);
+	for (const Variant &v : Span(p_vars.ptr() + 1, p_vars.size() - 1)) {
+		result += ' ';
+		result += v.operator String();
+	}
+	return result;
 }
 }

+ 10 - 19
core/string/print_string.h

@@ -30,7 +30,9 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "core/variant/variant.h"
+#include "core/string/ustring.h"
+
+class Variant;
 
 
 extern void (*_print_func)(String);
 extern void (*_print_func)(String);
 
 
@@ -45,12 +47,7 @@ struct PrintHandlerList {
 	PrintHandlerList() {}
 	PrintHandlerList() {}
 };
 };
 
 
-String stringify_variants(const Variant &p_var);
-
-template <typename... Args>
-String stringify_variants(const Variant &p_var, Args... p_args) {
-	return p_var.operator String() + " " + stringify_variants(p_args...);
-}
+String stringify_variants(const Span<Variant> &p_vars);
 
 
 void add_print_handler(PrintHandlerList *p_handler);
 void add_print_handler(PrintHandlerList *p_handler);
 void remove_print_handler(const PrintHandlerList *p_handler);
 void remove_print_handler(const PrintHandlerList *p_handler);
@@ -69,20 +66,14 @@ extern bool is_print_verbose_enabled();
 		}                                 \
 		}                                 \
 	}
 	}
 
 
-inline void print_line(const Variant &v) {
-	__print_line(stringify_variants(v));
-}
-
-inline void print_line_rich(const Variant &v) {
-	__print_line_rich(stringify_variants(v));
-}
-
 template <typename... Args>
 template <typename... Args>
-void print_line(const Variant &p_var, Args... p_args) {
-	__print_line(stringify_variants(p_var, p_args...));
+void print_line(Args... p_args) {
+	Variant variants[sizeof...(p_args)] = { p_args... };
+	__print_line(stringify_variants(Span(variants)));
 }
 }
 
 
 template <typename... Args>
 template <typename... Args>
-void print_line_rich(const Variant &p_var, Args... p_args) {
-	__print_line_rich(stringify_variants(p_var, p_args...));
+void print_line_rich(Args... p_args) {
+	Variant variants[sizeof...(p_args)] = { p_args... };
+	__print_line_rich(stringify_variants(Span(variants)));
 }
 }

+ 1 - 1
core/templates/rid_owner.h

@@ -34,8 +34,8 @@
 #include "core/os/mutex.h"
 #include "core/os/mutex.h"
 #include "core/string/print_string.h"
 #include "core/string/print_string.h"
 #include "core/templates/local_vector.h"
 #include "core/templates/local_vector.h"
-#include "core/templates/rid.h"
 #include "core/templates/safe_refcount.h"
 #include "core/templates/safe_refcount.h"
+#include "core/variant/variant.h"
 
 
 #include <cstdio>
 #include <cstdio>
 #include <typeinfo> // IWYU pragma: keep // Used in macro.
 #include <typeinfo> // IWYU pragma: keep // Used in macro.

+ 1 - 1
modules/jolt_physics/jolt_globals.cpp

@@ -35,8 +35,8 @@
 #include "shapes/jolt_custom_ray_shape.h"
 #include "shapes/jolt_custom_ray_shape.h"
 #include "shapes/jolt_custom_user_data_shape.h"
 #include "shapes/jolt_custom_user_data_shape.h"
 
 
-#include "core/os/memory.h"
 #include "core/string/print_string.h"
 #include "core/string/print_string.h"
+#include "core/variant/variant.h"
 
 
 #include "Jolt/Jolt.h"
 #include "Jolt/Jolt.h"
 
 

+ 1 - 1
platform/linuxbsd/wayland/detect_prime_egl.cpp

@@ -34,7 +34,7 @@
 #include "detect_prime_egl.h"
 #include "detect_prime_egl.h"
 
 
 #include "core/string/print_string.h"
 #include "core/string/print_string.h"
-#include "core/string/ustring.h"
+#include "core/variant/variant.h"
 
 
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/wait.h>

+ 1 - 1
platform/linuxbsd/x11/detect_prime_x11.cpp

@@ -33,7 +33,7 @@
 #include "detect_prime_x11.h"
 #include "detect_prime_x11.h"
 
 
 #include "core/string/print_string.h"
 #include "core/string/print_string.h"
-#include "core/string/ustring.h"
+#include "core/variant/variant.h"
 
 
 #include "thirdparty/glad/glad/gl.h"
 #include "thirdparty/glad/glad/gl.h"
 #include "thirdparty/glad/glad/glx.h"
 #include "thirdparty/glad/glad/glx.h"