-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve compile time string view logging levels
- Loading branch information
Showing
11 changed files
with
148 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "parseloglevel.hpp" | ||
|
||
#include <cstdint> | ||
#include <string_view> | ||
#include <type_traits> | ||
|
||
#include "cct_exception.hpp" | ||
#include "logginginfo.hpp" | ||
#include "static_string_view_helpers.hpp" | ||
|
||
namespace cct { | ||
int8_t LogPosFromLogStr(std::string_view logStr) { | ||
if (logStr.size() == 1) { | ||
const int8_t logLevelPos = logStr.front() - '0'; | ||
if (logLevelPos < 0 || | ||
logLevelPos >= static_cast<std::remove_const_t<decltype(logLevelPos)>>(LoggingInfo::kNbLogLevels)) { | ||
throw exception("Unrecognized log level {}. Possible values are [0-{}]", logStr, | ||
'0' + (LoggingInfo::kNbLogLevels - 1U)); | ||
} | ||
return logLevelPos; | ||
} | ||
|
||
int8_t logLevel = 0; | ||
for (const auto logName : LoggingInfo::kLogLevelNames) { | ||
if (logStr == logName) { | ||
return logLevel; | ||
} | ||
++logLevel; | ||
} | ||
|
||
static constexpr std::string_view kPrintLogNameSep = "|"; | ||
throw exception("Unrecognized log level name {}. Possible values are {}", logStr, | ||
make_joined_string_view<kPrintLogNameSep, LoggingInfo::kLogLevelNames>::value); | ||
} | ||
} // namespace cct |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters