summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2018-07-20 14:49:13 -0400
committerGravatar Lioncash2018-07-20 15:00:58 -0400
commit0a0b3c4b9ff55020ef490106ff8f1d12c8f122e4 (patch)
tree35e7886a5d09f822badff4efa4f617e214a57cee
parentMerge pull request #740 from Subv/acc_crash (diff)
downloadyuzu-0a0b3c4b9ff55020ef490106ff8f1d12c8f122e4.tar.gz
yuzu-0a0b3c4b9ff55020ef490106ff8f1d12c8f122e4.tar.xz
yuzu-0a0b3c4b9ff55020ef490106ff8f1d12c8f122e4.zip
ipc_helpers: Add PushEnum() member function to ResponseBuilder
Allows pushing strongly-typed enum members without the need to always cast them at the call sites. Note that we *only* allow strongly-typed enums in this case. The reason for this is that strongly typed enums have a guaranteed defined size, so the size of the data being pushed is always deterministic. With regular enums this can be a little more error-prone, so we disallow them. This function simply uses the underlying type of the enum to determine the size of the data. For example, if an enum is defined as: enum class SomeEnum : u16 { SomeEntry }; if PushEnum(SomeEnum::SomeEntry); is called, then it will push a u16-size amount of data.
-rw-r--r--src/core/hle/ipc_helpers.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h
index 24605a273..8b5b06f31 100644
--- a/src/core/hle/ipc_helpers.h
+++ b/src/core/hle/ipc_helpers.h
@@ -175,6 +175,25 @@ public:
175 void Push(const First& first_value, const Other&... other_values); 175 void Push(const First& first_value, const Other&... other_values);
176 176
177 /** 177 /**
178 * Helper function for pushing strongly-typed enumeration values.
179 *
180 * @tparam Enum The enumeration type to be pushed
181 *
182 * @param value The value to push.
183 *
184 * @note The underlying size of the enumeration type is the size of the
185 * data that gets pushed. e.g. "enum class SomeEnum : u16" will
186 * push a u16-sized amount of data.
187 */
188 template <typename Enum>
189 void PushEnum(Enum value) {
190 static_assert(std::is_enum_v<Enum>, "T must be an enum type within a PushEnum call.");
191 static_assert(!std::is_convertible_v<Enum, int>,
192 "enum type in PushEnum must be a strongly typed enum.");
193 Push(static_cast<std::underlying_type_t<Enum>>(value));
194 }
195
196 /**
178 * @brief Copies the content of the given trivially copyable class to the buffer as a normal 197 * @brief Copies the content of the given trivially copyable class to the buffer as a normal
179 * param 198 * param
180 * @note: The input class must be correctly packed/padded to fit hardware layout. 199 * @note: The input class must be correctly packed/padded to fit hardware layout.