From 91a804707bc7ab814f95d57f9881becb3a310f0a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 10 Dec 2017 20:37:44 -0500 Subject: [PATCH] ipc_helpers: Add member functions for pushing and popping strongly typed enums Alleviates the need to static_cast to an enum type at the call sites of the Push and Pop calls. We only allow strongly typed enums, as they have a defined type of int by default if an underlying type isn't explicitly specified, whereas with regular enums, if an underlying type isn't specified, an implementation-defined type is used that can fit all the enumeration values. --- src/core/hle/ipc_helpers.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 08843989b0..9e687b5185 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -98,6 +98,15 @@ public: template void Push(const First& first_value, const Other&... other_values); + template + void PushEnum(T value) { + static_assert(std::is_enum(), "T must be an enum type within a PushEnum call."); + static_assert(!std::is_convertible(), + "enum type in PushEnum must be a strongly typed enum."); + static_assert(sizeof(value) < sizeof(u64), "64-bit enums may not be pushed."); + Push(static_cast>(value)); + } + /** * @brief Copies the content of the given trivially copyable class to the buffer as a normal * param @@ -273,6 +282,15 @@ public: template void Pop(First& first_value, Other&... other_values); + template + T PopEnum() { + static_assert(std::is_enum(), "T must be an enum type within a PopEnum call."); + static_assert(!std::is_convertible(), + "enum type in PopEnum must be a strongly typed enum."); + static_assert(sizeof(T) < sizeof(u64), "64-bit enums cannot be popped."); + return static_cast(Pop>()); + } + /// Equivalent to calling `PopHandles<1>()[0]`. Kernel::Handle PopHandle();