Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Rename LogLevel enum values to use PascalCase; prefix enum class specific values with the enum name (fixes #39). #46

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/clp_ffi_js/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ 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",
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
4 changes: 2 additions & 2 deletions src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ 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
* node's value is not an integer or string.
* @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.
*/
[[nodiscard]] auto get_log_level(StructuredLogEvent::NodeIdValuePairs const& id_value_pairs
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
Loading