chore: Less verbose name for enum underlying type casts (#1494)

* Less verbose name for enum underlying type casts

* Remove redundant call
This commit is contained in:
jadebenn 2024-03-06 23:45:04 -06:00 committed by GitHub
parent fe4b29f643
commit 6e3b5acede
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 7 deletions

View File

@ -264,8 +264,8 @@ namespace GeneralUtils {
* @returns The enum entry's value in its underlying type
*/
template <Enum eType>
constexpr typename std::underlying_type_t<eType> CastUnderlyingType(const eType entry) noexcept {
return static_cast<typename std::underlying_type_t<eType>>(entry);
constexpr std::underlying_type_t<eType> ToUnderlying(const eType entry) noexcept {
return static_cast<std::underlying_type_t<eType>>(entry);
}
// on Windows we need to undef these or else they conflict with our numeric limits calls

View File

@ -229,7 +229,7 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd
RakNet::BitStream loginResponse;
BitStreamUtils::WriteHeader(loginResponse, eConnectionType::CLIENT, eClientMessageType::LOGIN_RESPONSE);
loginResponse.Write<uint8_t>(GeneralUtils::CastUnderlyingType(responseCode));
loginResponse.Write(responseCode);
// Event Gating
loginResponse.Write(LUString(Game::config->GetValue("event_1")));

View File

@ -1,7 +1,7 @@
set(DCOMMONTEST_SOURCES
"AMFDeserializeTests.cpp"
"Amf3Tests.cpp"
"CastUnderlyingTypeTests.cpp"
"ToUnderlyingTests.cpp"
"HeaderSkipTest.cpp"
"TestCDFeatureGatingTable.cpp"
"TestLDFFormat.cpp"

View File

@ -7,13 +7,13 @@
#include "eWorldMessageType.h"
#define ASSERT_TYPE_EQ(TYPE, ENUM)\
ASSERT_TRUE(typeid(TYPE) == typeid(GeneralUtils::CastUnderlyingType(static_cast<ENUM>(0))));
ASSERT_TRUE(typeid(TYPE) == typeid(GeneralUtils::ToUnderlying(static_cast<ENUM>(0))));
#define ASSERT_TYPE_NE(TYPE, ENUM)\
ASSERT_FALSE(typeid(TYPE) == typeid(GeneralUtils::CastUnderlyingType(static_cast<ENUM>(0))));
ASSERT_FALSE(typeid(TYPE) == typeid(GeneralUtils::ToUnderlying(static_cast<ENUM>(0))));
// Verify that the underlying enum types are being cast correctly
TEST(CastUnderlyingTypeTests, VerifyCastUnderlyingType) {
TEST(ToUnderlyingTests, VerifyToUnderlying) {
ASSERT_TYPE_EQ(uint8_t, eGameMasterLevel);
ASSERT_TYPE_EQ(uint16_t, eGameMessageType);
ASSERT_TYPE_EQ(uint32_t, eWorldMessageType)