Merge pull request #3268 from lioncash/ipc-enum
ipc_helpers: Add member functions for pushing and popping strongly typed enums
This commit is contained in:
commit
b4bb74a101
1 changed files with 18 additions and 0 deletions
|
@ -98,6 +98,15 @@ public:
|
||||||
template <typename First, typename... Other>
|
template <typename First, typename... Other>
|
||||||
void Push(const First& first_value, const Other&... other_values);
|
void Push(const First& first_value, const Other&... other_values);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void PushEnum(T value) {
|
||||||
|
static_assert(std::is_enum<T>(), "T must be an enum type within a PushEnum call.");
|
||||||
|
static_assert(!std::is_convertible<T, int>(),
|
||||||
|
"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<std::underlying_type_t<T>>(value));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copies the content of the given trivially copyable class to the buffer as a normal
|
* @brief Copies the content of the given trivially copyable class to the buffer as a normal
|
||||||
* param
|
* param
|
||||||
|
@ -273,6 +282,15 @@ public:
|
||||||
template <typename First, typename... Other>
|
template <typename First, typename... Other>
|
||||||
void Pop(First& first_value, Other&... other_values);
|
void Pop(First& first_value, Other&... other_values);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T PopEnum() {
|
||||||
|
static_assert(std::is_enum<T>(), "T must be an enum type within a PopEnum call.");
|
||||||
|
static_assert(!std::is_convertible<T, int>(),
|
||||||
|
"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<T>(Pop<std::underlying_type_t<T>>());
|
||||||
|
}
|
||||||
|
|
||||||
/// Equivalent to calling `PopHandles<1>()[0]`.
|
/// Equivalent to calling `PopHandles<1>()[0]`.
|
||||||
Kernel::Handle PopHandle();
|
Kernel::Handle PopHandle();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue