From 6e3b5acede696d07f45bb564d822f1b8e65cf8f4 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Wed, 6 Mar 2024 23:45:04 -0600 Subject: [PATCH] chore: Less verbose name for enum underlying type casts (#1494) * Less verbose name for enum underlying type casts * Remove redundant call --- dCommon/GeneralUtils.h | 4 ++-- dNet/AuthPackets.cpp | 2 +- tests/dCommonTests/CMakeLists.txt | 2 +- .../{CastUnderlyingTypeTests.cpp => ToUnderlyingTests.cpp} | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) rename tests/dCommonTests/{CastUnderlyingTypeTests.cpp => ToUnderlyingTests.cpp} (68%) diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index f57be9a2..c3422b05 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -264,8 +264,8 @@ namespace GeneralUtils { * @returns The enum entry's value in its underlying type */ template - constexpr typename std::underlying_type_t CastUnderlyingType(const eType entry) noexcept { - return static_cast>(entry); + constexpr std::underlying_type_t ToUnderlying(const eType entry) noexcept { + return static_cast>(entry); } // on Windows we need to undef these or else they conflict with our numeric limits calls diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index dce7e8e9..a2bf731c 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -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(GeneralUtils::CastUnderlyingType(responseCode)); + loginResponse.Write(responseCode); // Event Gating loginResponse.Write(LUString(Game::config->GetValue("event_1"))); diff --git a/tests/dCommonTests/CMakeLists.txt b/tests/dCommonTests/CMakeLists.txt index cf0a03ed..ef7c4cba 100644 --- a/tests/dCommonTests/CMakeLists.txt +++ b/tests/dCommonTests/CMakeLists.txt @@ -1,7 +1,7 @@ set(DCOMMONTEST_SOURCES "AMFDeserializeTests.cpp" "Amf3Tests.cpp" - "CastUnderlyingTypeTests.cpp" + "ToUnderlyingTests.cpp" "HeaderSkipTest.cpp" "TestCDFeatureGatingTable.cpp" "TestLDFFormat.cpp" diff --git a/tests/dCommonTests/CastUnderlyingTypeTests.cpp b/tests/dCommonTests/ToUnderlyingTests.cpp similarity index 68% rename from tests/dCommonTests/CastUnderlyingTypeTests.cpp rename to tests/dCommonTests/ToUnderlyingTests.cpp index 9cdfcdd3..4cbf4635 100644 --- a/tests/dCommonTests/CastUnderlyingTypeTests.cpp +++ b/tests/dCommonTests/ToUnderlyingTests.cpp @@ -7,13 +7,13 @@ #include "eWorldMessageType.h" #define ASSERT_TYPE_EQ(TYPE, ENUM)\ - ASSERT_TRUE(typeid(TYPE) == typeid(GeneralUtils::CastUnderlyingType(static_cast(0)))); + ASSERT_TRUE(typeid(TYPE) == typeid(GeneralUtils::ToUnderlying(static_cast(0)))); #define ASSERT_TYPE_NE(TYPE, ENUM)\ - ASSERT_FALSE(typeid(TYPE) == typeid(GeneralUtils::CastUnderlyingType(static_cast(0)))); + ASSERT_FALSE(typeid(TYPE) == typeid(GeneralUtils::ToUnderlying(static_cast(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)