Add Class and Function Identifier Macro (#5481)
This adds a Macro which simply identifies the function and class name for error messages. Examples taken from the MojangAPI class [Choosen because I worked on that] processing is done during compile time. Should be cross compatible
This commit is contained in:
parent
20f3cb34ae
commit
26b7e5ad9e
@ -387,9 +387,21 @@ auto ToUnsigned(T a_Val)
|
|||||||
return static_cast<std::make_unsigned_t<T>>(a_Val);
|
return static_cast<std::make_unsigned_t<T>>(a_Val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/1666802/is-there-a-class-macro-in-c
|
||||||
|
constexpr std::string_view methodName(std::string_view a_PrettyFunction)
|
||||||
|
{
|
||||||
|
size_t Bracket = a_PrettyFunction.rfind("(");
|
||||||
|
size_t Space = a_PrettyFunction.rfind(" ", Bracket) + 1;
|
||||||
|
|
||||||
|
return a_PrettyFunction.substr(Space, Bracket - Space);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/48857887/pretty-function-in-visual-c
|
||||||
|
#if !defined(__PRETTY_FUNCTION__) && !defined(__GNUC__)
|
||||||
|
#define __PRETTY_FUNCTION__ __FUNCSIG__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
|
||||||
|
|
||||||
// Common headers (part 2, with macros):
|
// Common headers (part 2, with macros):
|
||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
|
@ -564,7 +564,7 @@ void cMojangAPI::QueryNamesToUUIDs(AStringVector & a_NamesToQuery)
|
|||||||
AString ParseError;
|
AString ParseError;
|
||||||
if (!JsonUtils::ParseString(Response, root, &ParseError) || !root.isArray())
|
if (!JsonUtils::ParseString(Response, root, &ParseError) || !root.isArray())
|
||||||
{
|
{
|
||||||
LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON: \"%s\"", __FUNCTION__, ParseError);
|
LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON: \"%s\"", __METHOD_NAME__, ParseError);
|
||||||
LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16));
|
LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -727,7 +727,7 @@ void cMojangAPI::Update(void)
|
|||||||
}
|
}
|
||||||
if (!PlayerNames.empty())
|
if (!PlayerNames.empty())
|
||||||
{
|
{
|
||||||
LOG("cMojangAPI: Updating name-to-uuid cache for %u names", static_cast<unsigned>(PlayerNames.size()));
|
LOG("%s: Updating name-to-uuid cache for %u names", __METHOD_NAME__, static_cast<unsigned>(PlayerNames.size()));
|
||||||
QueryNamesToUUIDs(PlayerNames);
|
QueryNamesToUUIDs(PlayerNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,7 +745,7 @@ void cMojangAPI::Update(void)
|
|||||||
}
|
}
|
||||||
if (!ProfileUUIDs.empty())
|
if (!ProfileUUIDs.empty())
|
||||||
{
|
{
|
||||||
LOG("cMojangAPI: Updating uuid-to-profile cache for %u uuids", static_cast<unsigned>(ProfileUUIDs.size()));
|
LOG("%s: Updating uuid-to-profile cache for %u uuids", __METHOD_NAME__, static_cast<unsigned>(ProfileUUIDs.size()));
|
||||||
for (const auto & UUID : ProfileUUIDs)
|
for (const auto & UUID : ProfileUUIDs)
|
||||||
{
|
{
|
||||||
QueryUUIDToProfile(UUID);
|
QueryUUIDToProfile(UUID);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user