You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/08/13 20:05:27 UTC

[trafficserver] 01/03: BufferWriter: Some minor cleanups. Clean up use of std::literal, add bwf::Errno default constructor, move Date format to explicit default.

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit d3ab5b50a5d0897459f04b45b1a18aff0deef7fa
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Mon Jul 2 20:44:17 2018 -0500

    BufferWriter: Some minor cleanups.
    Clean up use of std::literal, add bwf::Errno default constructor, move Date format to explicit default.
    
    (cherry picked from commit b28833b7cce7a77fc03ab80811ae3247b3cf49af)
---
 lib/ts/BufferWriter.h   |  5 +++--
 lib/ts/bwf_std_format.h | 23 +++++++++++++++++++----
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/lib/ts/BufferWriter.h b/lib/ts/BufferWriter.h
index b1c4c9b..b459ee1 100644
--- a/lib/ts/BufferWriter.h
+++ b/lib/ts/BufferWriter.h
@@ -35,8 +35,6 @@
 #include <ts/MemSpan.h>
 #include <ts/BufferWriterForward.h>
 
-using namespace std::literals;
-
 namespace ts
 {
 /** Base (abstract) class for concrete buffer writers.
@@ -611,6 +609,7 @@ template <typename... Args>
 BufferWriter &
 BufferWriter::printv(TextView fmt, std::tuple<Args...> const &args)
 {
+  using namespace std::literals;
   static constexpr int N = sizeof...(Args); // used as loop limit
   static const auto fa   = bw_fmt::Get_Arg_Formatter_Array<decltype(args)>(std::index_sequence_for<Args...>{});
   int arg_idx            = 0; // the next argument index to be processed.
@@ -671,6 +670,7 @@ template <typename... Args>
 BufferWriter &
 BufferWriter::printv(BWFormat const &fmt, std::tuple<Args...> const &args)
 {
+  using namespace std::literals;
   static constexpr int N = sizeof...(Args);
   static const auto fa   = bw_fmt::Get_Arg_Formatter_Array<decltype(args)>(std::index_sequence_for<Args...>{});
 
@@ -795,6 +795,7 @@ bwformat(BufferWriter &w, BWFSpec const &, char c)
 inline BufferWriter &
 bwformat(BufferWriter &w, BWFSpec const &spec, bool f)
 {
+  using namespace std::literals;
   if ('s' == spec._type) {
     w.write(f ? "true"sv : "false"sv);
   } else if ('S' == spec._type) {
diff --git a/lib/ts/bwf_std_format.h b/lib/ts/bwf_std_format.h
index 60776c4..aee70f6 100644
--- a/lib/ts/bwf_std_format.h
+++ b/lib/ts/bwf_std_format.h
@@ -25,12 +25,14 @@
 
 #include <atomic>
 #include <string_view>
+#include <ts/TextView.h>
+#include <ts/BufferWriterForward.h>
 
 namespace std
 {
 template <typename T>
 ts::BufferWriter &
-bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, std::atomic<T> const &v)
+bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, atomic<T> const &v)
 {
   return ts::bwformat(w, spec, v.load());
 }
@@ -40,17 +42,30 @@ namespace ts
 {
 namespace bwf
 {
+  using namespace std::literals; // enable ""sv
+
+  /** Format wrapper for @c errno.
+   * This stores a copy of the argument or @c errno if an argument isn't provided. The output
+   * is then formatted with the short, long, and numeric value of @c errno. If the format specifier
+   * is type 'd' then just the numeric value is printed.
+   */
   struct Errno {
     int _e;
-    explicit Errno(int e) : _e(e) {}
+    explicit Errno(int e = errno) : _e(e) {}
   };
 
+  /** Format wrapper for time stamps.
+   * If the time isn't provided, the current epoch time is used. If the format string isn't
+   * provided a format like "2017 Jun 29 14:11:29" is used.
+   */
   struct Date {
+    static constexpr std::string_view DEFAULT_FORMAT{"%Y %b %d %H:%M:%S"_sv};
     time_t _epoch;
     std::string_view _fmt;
-    Date(time_t t, std::string_view fmt = "%Y %b %d %H:%M:%S"sv) : _epoch(t), _fmt(fmt) {}
-    Date(std::string_view fmt = "%Y %b %d %H:%M:%S"sv);
+    Date(time_t t, std::string_view fmt = DEFAULT_FORMAT) : _epoch(t), _fmt(fmt) {}
+    Date(std::string_view fmt = DEFAULT_FORMAT);
   };
+
 } // namespace bwf
 
 BufferWriter &bwformat(BufferWriter &w, BWFSpec const &spec, bwf::Errno const &e);