DarkflameServer/dCommon/dEnums/StringifiedEnum.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
681 B
C
Raw Normal View History

feat: Improve console output to show packet enum names (magic_enum) (#1344) * add enum stringification functionality from third party source * squashed commit * Macros: Add test and improve speed Space macros out utilize cache locality ensure no lost functionality * moved stringify code to dCommon * Rename #defines in stringify enum tests * Revert "moved stringify code to dCommon" This reverts commit 33fa5f8d2fc273ede9fffbc15a62d9a5335ffe6a. * improve macro functionality change function handle formatting and function definition tweaks * typo fixes * moved code to dCommon/dEnums and tests to dCommonTests/dEnumsTests * initial magic_enums alternate implementation of enum stringification * deleted unused tests * reverted compile flag oopsy and fixed output types * fixed testing suite * test formatting improvement * formatting again :( * added gm string to "aborting gm!" message * Push my suggestion for CI tests. * updated magic enum test * fix test variable type * added gm test * making sure magic_enum is on a release branch * tidying up console outputs * re-implemented enum array access for performance * now it is bugged :( * nvm, working * helping out the snowflake compilers * changed return type too * optimization too * formatting too I guess because why not * being even more painfully specific * Update WorldServer.cpp to match emo's feedback * Update MagicEnumTests.cpp to use srand(time(NULL)) * Update eGameMessageType.h - formatting * Trying to fix the crash but can't actually compile the code to check on my own rn * Update WorldServer.cpp - third try at this * Update MagicEnumTests.cpp - use better macro definitions * Update MagicEnumTests.cpp - c string comparison fix * addressing all but the cmake feedback * fixed cmake to the best of my very limited ability * added tests to verify magic enum arrays are pre-sorted * updated --------- Co-authored-by: David Markowitz <EmosewaMC@gmail.com> Co-authored-by: Jettford <mrjettbradford@gmail.com>
2023-12-23 16:51:59 +00:00
#ifndef __STRINGIFIEDENUM_H__
#define __STRINGIFIEDENUM_H__
#include <string>
#include "magic_enum.hpp"
namespace StringifiedEnum {
template<typename T>
2024-03-08 21:44:02 +00:00
constexpr std::string_view ToString(const T e) {
static_assert(std::is_enum_v<T>, "Not an enum"); // Check type
2024-03-08 21:44:02 +00:00
constexpr const auto& sv = magic_enum::enum_entries<T>();
feat: Improve console output to show packet enum names (magic_enum) (#1344) * add enum stringification functionality from third party source * squashed commit * Macros: Add test and improve speed Space macros out utilize cache locality ensure no lost functionality * moved stringify code to dCommon * Rename #defines in stringify enum tests * Revert "moved stringify code to dCommon" This reverts commit 33fa5f8d2fc273ede9fffbc15a62d9a5335ffe6a. * improve macro functionality change function handle formatting and function definition tweaks * typo fixes * moved code to dCommon/dEnums and tests to dCommonTests/dEnumsTests * initial magic_enums alternate implementation of enum stringification * deleted unused tests * reverted compile flag oopsy and fixed output types * fixed testing suite * test formatting improvement * formatting again :( * added gm string to "aborting gm!" message * Push my suggestion for CI tests. * updated magic enum test * fix test variable type * added gm test * making sure magic_enum is on a release branch * tidying up console outputs * re-implemented enum array access for performance * now it is bugged :( * nvm, working * helping out the snowflake compilers * changed return type too * optimization too * formatting too I guess because why not * being even more painfully specific * Update WorldServer.cpp to match emo's feedback * Update MagicEnumTests.cpp to use srand(time(NULL)) * Update eGameMessageType.h - formatting * Trying to fix the crash but can't actually compile the code to check on my own rn * Update WorldServer.cpp - third try at this * Update MagicEnumTests.cpp - use better macro definitions * Update MagicEnumTests.cpp - c string comparison fix * addressing all but the cmake feedback * fixed cmake to the best of my very limited ability * added tests to verify magic enum arrays are pre-sorted * updated --------- Co-authored-by: David Markowitz <EmosewaMC@gmail.com> Co-authored-by: Jettford <mrjettbradford@gmail.com>
2023-12-23 16:51:59 +00:00
const auto it = std::lower_bound(
2024-01-20 23:22:56 +00:00
sv.begin(), sv.end(), e,
[&](const std::pair<T, std::string_view>& lhs, const T rhs) { return lhs.first < rhs; }
feat: Improve console output to show packet enum names (magic_enum) (#1344) * add enum stringification functionality from third party source * squashed commit * Macros: Add test and improve speed Space macros out utilize cache locality ensure no lost functionality * moved stringify code to dCommon * Rename #defines in stringify enum tests * Revert "moved stringify code to dCommon" This reverts commit 33fa5f8d2fc273ede9fffbc15a62d9a5335ffe6a. * improve macro functionality change function handle formatting and function definition tweaks * typo fixes * moved code to dCommon/dEnums and tests to dCommonTests/dEnumsTests * initial magic_enums alternate implementation of enum stringification * deleted unused tests * reverted compile flag oopsy and fixed output types * fixed testing suite * test formatting improvement * formatting again :( * added gm string to "aborting gm!" message * Push my suggestion for CI tests. * updated magic enum test * fix test variable type * added gm test * making sure magic_enum is on a release branch * tidying up console outputs * re-implemented enum array access for performance * now it is bugged :( * nvm, working * helping out the snowflake compilers * changed return type too * optimization too * formatting too I guess because why not * being even more painfully specific * Update WorldServer.cpp to match emo's feedback * Update MagicEnumTests.cpp to use srand(time(NULL)) * Update eGameMessageType.h - formatting * Trying to fix the crash but can't actually compile the code to check on my own rn * Update WorldServer.cpp - third try at this * Update MagicEnumTests.cpp - use better macro definitions * Update MagicEnumTests.cpp - c string comparison fix * addressing all but the cmake feedback * fixed cmake to the best of my very limited ability * added tests to verify magic enum arrays are pre-sorted * updated --------- Co-authored-by: David Markowitz <EmosewaMC@gmail.com> Co-authored-by: Jettford <mrjettbradford@gmail.com>
2023-12-23 16:51:59 +00:00
);
std::string_view output;
2024-01-20 23:22:56 +00:00
if (it != sv.end() && it->first == e) {
feat: Improve console output to show packet enum names (magic_enum) (#1344) * add enum stringification functionality from third party source * squashed commit * Macros: Add test and improve speed Space macros out utilize cache locality ensure no lost functionality * moved stringify code to dCommon * Rename #defines in stringify enum tests * Revert "moved stringify code to dCommon" This reverts commit 33fa5f8d2fc273ede9fffbc15a62d9a5335ffe6a. * improve macro functionality change function handle formatting and function definition tweaks * typo fixes * moved code to dCommon/dEnums and tests to dCommonTests/dEnumsTests * initial magic_enums alternate implementation of enum stringification * deleted unused tests * reverted compile flag oopsy and fixed output types * fixed testing suite * test formatting improvement * formatting again :( * added gm string to "aborting gm!" message * Push my suggestion for CI tests. * updated magic enum test * fix test variable type * added gm test * making sure magic_enum is on a release branch * tidying up console outputs * re-implemented enum array access for performance * now it is bugged :( * nvm, working * helping out the snowflake compilers * changed return type too * optimization too * formatting too I guess because why not * being even more painfully specific * Update WorldServer.cpp to match emo's feedback * Update MagicEnumTests.cpp to use srand(time(NULL)) * Update eGameMessageType.h - formatting * Trying to fix the crash but can't actually compile the code to check on my own rn * Update WorldServer.cpp - third try at this * Update MagicEnumTests.cpp - use better macro definitions * Update MagicEnumTests.cpp - c string comparison fix * addressing all but the cmake feedback * fixed cmake to the best of my very limited ability * added tests to verify magic enum arrays are pre-sorted * updated --------- Co-authored-by: David Markowitz <EmosewaMC@gmail.com> Co-authored-by: Jettford <mrjettbradford@gmail.com>
2023-12-23 16:51:59 +00:00
output = it->second;
} else {
feat: Improve console output to show packet enum names (magic_enum) (#1344) * add enum stringification functionality from third party source * squashed commit * Macros: Add test and improve speed Space macros out utilize cache locality ensure no lost functionality * moved stringify code to dCommon * Rename #defines in stringify enum tests * Revert "moved stringify code to dCommon" This reverts commit 33fa5f8d2fc273ede9fffbc15a62d9a5335ffe6a. * improve macro functionality change function handle formatting and function definition tweaks * typo fixes * moved code to dCommon/dEnums and tests to dCommonTests/dEnumsTests * initial magic_enums alternate implementation of enum stringification * deleted unused tests * reverted compile flag oopsy and fixed output types * fixed testing suite * test formatting improvement * formatting again :( * added gm string to "aborting gm!" message * Push my suggestion for CI tests. * updated magic enum test * fix test variable type * added gm test * making sure magic_enum is on a release branch * tidying up console outputs * re-implemented enum array access for performance * now it is bugged :( * nvm, working * helping out the snowflake compilers * changed return type too * optimization too * formatting too I guess because why not * being even more painfully specific * Update WorldServer.cpp to match emo's feedback * Update MagicEnumTests.cpp to use srand(time(NULL)) * Update eGameMessageType.h - formatting * Trying to fix the crash but can't actually compile the code to check on my own rn * Update WorldServer.cpp - third try at this * Update MagicEnumTests.cpp - use better macro definitions * Update MagicEnumTests.cpp - c string comparison fix * addressing all but the cmake feedback * fixed cmake to the best of my very limited ability * added tests to verify magic enum arrays are pre-sorted * updated --------- Co-authored-by: David Markowitz <EmosewaMC@gmail.com> Co-authored-by: Jettford <mrjettbradford@gmail.com>
2023-12-23 16:51:59 +00:00
output = "UNKNOWN";
}
return output;
}
}
#endif // !__STRINGIFIEDENUM_H__