From 5c60277610beda7d818df2761d597ead1b914789 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 18 Sep 2023 13:24:41 -0400 Subject: [PATCH] indentlog: strongly-typed fucntion_style enum --- example/ex3/ex3.cpp | 2 +- example/ex4/ex4.cpp | 9 ++++--- include/indentlog/function.hpp | 41 +++++++++++++++++++------------- include/indentlog/log_config.hpp | 2 +- include/indentlog/scope.hpp | 4 ++-- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/example/ex3/ex3.cpp b/example/ex3/ex3.cpp index cc592a5b..2a09d2d7 100644 --- a/example/ex3/ex3.cpp +++ b/example/ex3/ex3.cpp @@ -27,7 +27,7 @@ main(int argc, char ** argv) { log_config::min_log_level = log_level::info; log_config::time_enabled = true; log_config::time_local_flag = true; - log_config::style = FS_Streamlined; + log_config::style = function_style::streamlined; log_config::indent_width = 4; log_config::max_indent_width = 30; log_config::location_tab = 80; diff --git a/example/ex4/ex4.cpp b/example/ex4/ex4.cpp index 05ca39e0..d59e83c1 100644 --- a/example/ex4/ex4.cpp +++ b/example/ex4/ex4.cpp @@ -26,8 +26,7 @@ private: int main(int argc, char ** argv) { - //log_config::style = FS_Pretty; - log_config::style = FS_Streamlined; + log_config::style = function_style::streamlined; log_config::min_log_level = log_level::info; scope log(XO_ENTER0(info)); @@ -37,15 +36,15 @@ main(int argc, char ** argv) { double x = 3.0; double r = 0.0; - log_config::style = FS_Pretty; + log_config::style = function_style::pretty; r = quadratic(x); - log_config::style = FS_Streamlined; + log_config::style = function_style::streamlined; r = quadratic(x); - log_config::style = FS_Simple; + log_config::style = function_style::simple; r = quadratic(x); } diff --git a/include/indentlog/function.hpp b/include/indentlog/function.hpp index d68c75b9..5bbfbd05 100644 --- a/include/indentlog/function.hpp +++ b/include/indentlog/function.hpp @@ -6,15 +6,22 @@ #include namespace xo { - enum function_style { - /* literal: print given name, no alterations */ - FS_Literal, - /* pretty: print name, surrounded by [] */ - FS_Pretty, - /* streamlined: remove extraneous detail, try to print something like class::method */ - FS_Streamlined, - /* simple: remove everything except function/method name */ - FS_Simple + enum class function_style : std::uint8_t { + /* literal: print supplied text, no alterations */ + literal, + /* pretty: print name, surrounded by [] + * [double Quadratic::operator()(double) const] + */ + pretty, + /* streamlined: remove extraneous detail, + * try to print something like class::method + * Quadratic::operator() + */ + streamlined, + /* simple: remove everything except function/method name + * operator() + */ + simple }; /* Tag to drive header-only expression */ @@ -245,23 +252,23 @@ namespace xo { /* set text color */ switch(fn.style()) { - case FS_Literal: + case function_style::literal: os << with_color(fn.colorspec(), fn.pretty()); break; - case FS_Pretty: + case function_style::pretty: os << "[" << with_color(fn.colorspec(), fn.pretty()) << "]"; break; - case FS_Simple: - os << color_on(fn.colorspec()); - function_name::print_simple(os, fn.pretty()); - os << color_off(); - break; - case FS_Streamlined: + case function_style::streamlined: /* omit namespace qualifiers and template arguments */ os << color_on(fn.colorspec()); function_name::print_streamlined(os, fn.pretty()); os << color_off(); break; + case function_style::simple: + os << color_on(fn.colorspec()); + function_name::print_simple(os, fn.pretty()); + os << color_off(); + break; } return os; diff --git a/include/indentlog/log_config.hpp b/include/indentlog/log_config.hpp index 22371bb7..1630b5c2 100644 --- a/include/indentlog/log_config.hpp +++ b/include/indentlog/log_config.hpp @@ -76,7 +76,7 @@ namespace xo { template function_style - log_config_impl::style = FS_Streamlined; + log_config_impl::style = function_style::streamlined; template color_spec_type diff --git a/include/indentlog/scope.hpp b/include/indentlog/scope.hpp index fac759c2..fd0da297 100644 --- a/include/indentlog/scope.hpp +++ b/include/indentlog/scope.hpp @@ -56,7 +56,7 @@ namespace xo { /* threshold level for logging -- write messages with severity >= this level */ log_level log_level_ = log_level::error; /* FS_Pretty | FS_Streamlined | FS_Simple */ - function_style style_ = FS_Pretty; + function_style style_ = function_style::pretty; std::string_view name1_ = "<.name1>"; std::string_view name2_ = "<.name2>"; /* __FILE__ */ @@ -168,7 +168,7 @@ namespace xo { /* send indented output to this streambuf (e.g. std::clog.rdbuf()) */ std::streambuf * dest_sbuf_ = std::clog.rdbuf(); /* style for displaying .name1 */ - function_style style_ = FS_Pretty; + function_style style_ = function_style::pretty; /* name of this scope (part 1) */ std::string_view name1_ = ""; /* name of this scope (part 2) */