diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-03-09 20:48:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 20:48:45 +0100 |
commit | 33c907f9f5b3ec1a43d0251d7cac80da49b5b658 (patch) | |
tree | 6adb187024a8de7ed0b2ebf3e7c75ae07d8407bf /core/object/message_queue.h | |
parent | f17c5501eb4bb6a86d9f2f07567da081eb8991b0 (diff) | |
parent | 21637dfc2535a00f531b8b664c1e66ba34d11eb0 (diff) |
Merge pull request #58929 from reduz/remove-variant-arg-macros
Remove VARIANT_ARG* macros
Diffstat (limited to 'core/object/message_queue.h')
-rw-r--r-- | core/object/message_queue.h | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/core/object/message_queue.h b/core/object/message_queue.h index a4449cf473..eaab01d0aa 100644 --- a/core/object/message_queue.h +++ b/core/object/message_queue.h @@ -31,8 +31,11 @@ #ifndef MESSAGE_QUEUE_H #define MESSAGE_QUEUE_H -#include "core/object/class_db.h" +#include "core/object/object_id.h" #include "core/os/thread_safe.h" +#include "core/variant/variant.h" + +class Object; class MessageQueue { _THREAD_SAFE_CLASS_ @@ -73,14 +76,42 @@ class MessageQueue { public: static MessageQueue *get_singleton(); - Error push_call(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error = false); - Error push_call(ObjectID p_id, const StringName &p_method, VARIANT_ARG_LIST); + Error push_callp(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error = false); + template <typename... VarArgs> + Error push_call(ObjectID p_id, const StringName &p_method, VarArgs... p_args) { + Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported. + const Variant *argptrs[sizeof...(p_args) + 1]; + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + argptrs[i] = &args[i]; + } + return push_callp(p_id, p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args)); + } + Error push_notification(ObjectID p_id, int p_notification); Error push_set(ObjectID p_id, const StringName &p_prop, const Variant &p_value); - Error push_callable(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error = false); - Error push_callable(const Callable &p_callable, VARIANT_ARG_LIST); + Error push_callablep(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error = false); + + template <typename... VarArgs> + Error push_callable(const Callable &p_callable, VarArgs... p_args) { + Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported. + const Variant *argptrs[sizeof...(p_args) + 1]; + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + argptrs[i] = &args[i]; + } + return push_callablep(p_callable, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args)); + } + + Error push_callp(Object *p_object, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error = false); + template <typename... VarArgs> + Error push_call(Object *p_object, const StringName &p_method, VarArgs... p_args) { + Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported. + const Variant *argptrs[sizeof...(p_args) + 1]; + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + argptrs[i] = &args[i]; + } + return push_callp(p_object, p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args)); + } - Error push_call(Object *p_object, const StringName &p_method, VARIANT_ARG_LIST); Error push_notification(Object *p_object, int p_notification); Error push_set(Object *p_object, const StringName &p_prop, const Variant &p_value); |