From 5ea3f6ec168b84e3a8a3cbbdbba98e3bcdbf7ada Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 20 May 2024 11:19:54 +0100 Subject: [PATCH] chore(developer): refactor CompMsg.cpp to use a std::map --- developer/src/kmcmplib/src/CompMsg.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/developer/src/kmcmplib/src/CompMsg.cpp b/developer/src/kmcmplib/src/CompMsg.cpp index 86a9b4d475..5bfbeb9a09 100644 --- a/developer/src/kmcmplib/src/CompMsg.cpp +++ b/developer/src/kmcmplib/src/CompMsg.cpp @@ -1,11 +1,7 @@ #include +#include -struct CompilerError { - KMX_DWORD ErrorCode; - const KMX_CHAR* Text; - }; - -const struct CompilerError CompilerErrors[] = { +std::map CompilerErrorMap = { { CERR_InvalidLayoutLine , "Invalid 'layout' command"}, { CERR_NoVersionLine , "No version line found for file"}, { CERR_InvalidGroupLine , "Invalid 'group' command"}, @@ -150,14 +146,8 @@ const struct CompilerError CompilerErrors[] = { { CWARN_VirtualKeyInOutput , "Virtual keys are not supported in output"}, { 0, nullptr } - }; +}; -KMX_CHAR *GetCompilerErrorString(KMX_DWORD code) -{ - for(int i = 0; CompilerErrors[i].ErrorCode; i++) { - if(CompilerErrors[i].ErrorCode == code) { - return ( KMX_CHAR*) CompilerErrors[i].Text; - } - } - return nullptr; +KMX_CHAR *GetCompilerErrorString(KMX_DWORD code) { + return (KMX_CHAR*) CompilerErrorMap[code]; }