Browse Source

Remove macros, re-arrange structs.

Sam Jaffe 5 years ago
parent
commit
95d4a44f38
1 changed files with 25 additions and 27 deletions
  1. 25 27
      src/loggers/pattern_layout_format.cxx

+ 25 - 27
src/loggers/pattern_layout_format.cxx

@@ -49,14 +49,26 @@ namespace logging { namespace {
     }
   };
   
+  struct message_gen : public format::generator_t {
+    void write(logpacket const & lp, std::ostream & os) const override {
+      os << lp.message.str();
+    }
+  };
+  
+  struct literal_gen : public format::generator_t {
+    std::string value;
+
+    literal_gen(std::string const & value) : value(value) {}
+
+    void write(logpacket const & lp, std::ostream & os) const override {
+      os << value;
+    }
+  };
+
   struct class_info_gen : public detail::calling_class_helper,
                           public format::generator_t {
     static size_t components(char const * token) {
-      if (token && *token == '{') {
-        return atol(token + 1);
-      } else {
-        return 0;
-      }
+      return (token && *token == '{') ? atol(token + 1) : 0;
     }
 
     class_info_gen(char const * token)
@@ -111,23 +123,13 @@ namespace logging { namespace {
       write(lp, os, where);
     }
   };
-
-  struct message_gen : public format::generator_t {
-    void write(logpacket const & lp, std::ostream & os) const override {
-      os << lp.message.str();
-    }
-  };
-  
-  struct literal_gen : public format::generator_t {
-    literal_gen(std::string const & value) : value(value) {}
-
-    void write(logpacket const & lp, std::ostream & os) const override {
-      os << value;
-    }
-    std::string value;
-  };
   
   struct bounds_gen : public format::generator_t {
+    format::generator impl;
+    bool is_left;
+    int min;
+    size_t max;
+
     bounds_gen(format::generator impl, bool is_left, int min, size_t max)
     : impl(impl), is_left(is_left), min(min), max(max) {}
     
@@ -135,14 +137,10 @@ namespace logging { namespace {
       auto align = is_left ? std::left : std::right;
       std::string str = impl->str(lp);
       if (str.length() > max) {
-        str.erase(str.begin()+max, str.end());
+        str.erase(max);
       }
       os << align << std::setw(min) << str;
     }
-    format::generator impl;
-    bool is_left;
-    int min;
-    size_t max;
   };
 } }
 
@@ -153,11 +151,10 @@ namespace logging {
     return ss.str();
   }
   
-#define is( chr ) *next == chr
-#define is_string( str ) ! strncmp(next, str, strlen(str))
   format::generator date_token(char const * next);
 
   format::generator handle( char const * & next ) {
+    auto is = [&next](char c) { return *next == c; };
     if (is('c')) {
       return std::make_shared<log_handle_gen>();
     } else if (is('p')) {
@@ -200,6 +197,7 @@ namespace logging {
     char const * curr = fmt.c_str();
     char const * next = nullptr;
     char const * const end = curr + fmt.size();
+    auto is = [&next](char c) { return *next == c; };
     
     while ((next = std::strchr(curr, '%')) != nullptr) {
       ++next;