Skip to content

Commit

Permalink
Rename LogLevel enum values to use PascalCase; prefix enum class spec…
Browse files Browse the repository at this point in the history
…ific values with the enum name.
  • Loading branch information
junhaoliao committed Dec 27, 2024
1 parent beff6ae commit 2bc7873
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions src/clp_ffi_js/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ namespace clp_ffi_js {
* Enum of known log levels.
*/
enum class LogLevel : std::uint8_t {
NONE = 0, // This isn't a valid log level.
TRACE,
DEBUG,
INFO,
WARN,
ERROR,
FATAL,
LENGTH, // This isn't a valid log level.
LogLevelNone = 0, // This isn't a valid log level.
Trace,
Debug,
Info,
Warn,
Error,
Fatal,
LogLevelLength,
};
constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::TRACE};
constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::Trace};

/**
* Strings corresponding to `LogLevel`.
*
* NOTE: These must be kept in sync manually.
*/
constexpr std::array<std::string_view, clp::enum_to_underlying_type(LogLevel::LENGTH)>
constexpr std::array<std::string_view, clp::enum_to_underlying_type(LogLevel::LogLevelLength)>
cLogLevelNames{
"NONE", // This isn't a valid log level.
"TRACE",
"Trace",
"DEBUG",
"INFO",
"WARN",
Expand Down
8 changes: 4 additions & 4 deletions src/clp_ffi_js/ir/StructuredIrUnitHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {
* Parses a string to determine the corresponding `LogLevel` enum value.
* @param str
* @return `LogLevel` enum corresponding to `str` if `str` matches a string in `cLogLevelNames`.
* @return `LogLevel::NONE` otherwise.
* @return `LogLevel::LogLevelNone` otherwise.
*/
auto parse_log_level(std::string_view str) -> LogLevel;

Expand All @@ -48,7 +48,7 @@ auto parse_log_level(std::string_view str) -> LogLevel {
log_level_name_upper_case
);
if (it == cLogLevelNames.end()) {
return LogLevel::NONE;
return LogLevel::LogLevelNone;
}

return static_cast<LogLevel>(std::distance(cLogLevelNames.begin(), it));
Expand Down Expand Up @@ -96,7 +96,7 @@ auto StructuredIrUnitHandler::handle_end_of_stream() -> clp::ffi::ir_stream::IRE
auto StructuredIrUnitHandler::get_log_level(
StructuredLogEvent::NodeIdValuePairs const& id_value_pairs
) const -> LogLevel {
LogLevel log_level{LogLevel::NONE};
LogLevel log_level{LogLevel::LogLevelNone};

if (false == m_log_level_node_id.has_value()) {
return log_level;
Expand All @@ -113,7 +113,7 @@ auto StructuredIrUnitHandler::get_log_level(
} else if (log_level_value.is<clp::ffi::value_int_t>()) {
auto const& log_level_int = log_level_value.get_immutable_view<clp::ffi::value_int_t>();
if (log_level_int >= clp::enum_to_underlying_type(cValidLogLevelsBeginIdx)
&& log_level_int < clp::enum_to_underlying_type(LogLevel::LENGTH))
&& log_level_int < clp::enum_to_underlying_type(LogLevel::LogLevelLength))
{
log_level = static_cast<LogLevel>(log_level_int);
}
Expand Down
2 changes: 1 addition & 1 deletion src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class StructuredIrUnitHandler {
// Methods
/**
* @param id_value_pairs
* @return `LogLevel::NONE` if `m_log_level_node_id` is unset, the node has no value, or the
* @return `LogLevel::LogLevelNone` if `m_log_level_node_id` is unset, the node has no value, or the
* node's value is not an integer or string.
* @return `LogLevel` from node with id `m_log_level_node_id` otherwise.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ auto UnstructuredIrStreamReader::deserialize_stream() -> size_t {

auto const& logtype = message.get_logtype();
constexpr size_t cLogLevelPositionInMessages{1};
LogLevel log_level{LogLevel::NONE};
LogLevel log_level{LogLevel::LogLevelNone};
if (logtype.length() > cLogLevelPositionInMessages) {
// NOLINTNEXTLINE(readability-qualified-auto)
auto const log_level_name_it{std::find_if(
Expand Down

0 comments on commit 2bc7873

Please sign in to comment.