trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: CacheTool: Fix Scalar / bwformat issues for MacOS, Ubuntu [14, 16, 17].
Date Sun, 25 Mar 2018 16:01:14 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new a72eb6e  CacheTool: Fix Scalar / bwformat issues for MacOS, Ubuntu [14,16,17].
a72eb6e is described below

commit a72eb6e8560648f28723b36157b555ebe2585575
Author: Alan M. Carroll <amc@apache.org>
AuthorDate: Fri Mar 23 11:26:59 2018 -0500

    CacheTool: Fix Scalar / bwformat issues for MacOS, Ubuntu [14,16,17].
---
 cmd/traffic_cache_tool/CacheTool.cc | 16 +++++++-------
 lib/ts/BufferWriter.h               | 42 +++++++++++++++++--------------------
 lib/ts/BufferWriterFormat.cc        |  2 +-
 lib/ts/Scalar.h                     | 30 +++++++++++++++++++++-----
 4 files changed, 54 insertions(+), 36 deletions(-)

diff --git a/cmd/traffic_cache_tool/CacheTool.cc b/cmd/traffic_cache_tool/CacheTool.cc
index 6a5dbac..f1c40f6 100644
--- a/cmd/traffic_cache_tool/CacheTool.cc
+++ b/cmd/traffic_cache_tool/CacheTool.cc
@@ -26,25 +26,27 @@
 #include <memory>
 #include <vector>
 #include <map>
-#include <ts/ink_memory.h>
-#include <ts/ink_file.h>
 #include <getopt.h>
 #include <system_error>
 #include <string.h>
 #include <fcntl.h>
 #include <ctype.h>
-#include "File.h"
-#include "CacheDefs.h"
-#include "Command.h"
-#include "ts/ink_code.h"
 #include <cstring>
-#include <openssl/md5.h>
 #include <vector>
 #include <unordered_set>
 #include <time.h>
 #include <bitset>
 #include <inttypes.h>
 
+#include <ts/ink_memory.h>
+#include <ts/ink_file.h>
+#include <ts/BufferWriter.h>
+#include <ts/CryptoHash.h>
+
+#include "File.h"
+#include "CacheDefs.h"
+#include "Command.h"
+
 using ts::Bytes;
 using ts::Megabytes;
 using ts::CacheStoreBlocks;
diff --git a/lib/ts/BufferWriter.h b/lib/ts/BufferWriter.h
index 370a697..0e9616d 100644
--- a/lib/ts/BufferWriter.h
+++ b/lib/ts/BufferWriter.h
@@ -676,38 +676,34 @@ bwformat(BufferWriter &w, BWFSpec const &spec, TextView const
&tv)
   return bwformat(w, spec, static_cast<string_view>(tv));
 }
 
-//-- Integral types
-inline BufferWriter &
-bwformat(BufferWriter &w, BWFSpec const &spec, uintmax_t const &i)
-{
-  return bw_fmt::Format_Integer(w, spec, i, false);
-}
-
-inline BufferWriter &
-bwformat(BufferWriter &w, BWFSpec const &spec, intmax_t const &i)
-{
-  return i < 0 ? bw_fmt::Format_Integer(w, spec, -i, true) : bw_fmt::Format_Integer(w,
spec, i, false);
-}
+/* Integer types.
+
+   Due to some oddities for MacOS building, need a bit more template magic here. The underlying
+   integer rendering is in @c Format_Integer which takes @c intmax_t or @c uintmax_t. For
@c
+   bwformat templates are defined, one for signed and one for unsigned. These forward their
argument
+   to the internal renderer. To avoid additional ambiguity the template argument is checked
with @c
+   std::enable_if to invalidate the overload if the argument type isn't a signed / unsigned
+   integer. One exception to this is @c char which is handled by a previous overload in order
to
+   treat the value as a character and not an integer. The overall benefit is this works for
any set
+   of integer types, rather tuning and hoping to get just the right set of overloads.
+ */
 
-inline BufferWriter &
-bwformat(BufferWriter &w, BWFSpec const &spec, unsigned int const &i)
+template <typename I>
+auto
+bwformat(BufferWriter &w, BWFSpec const &spec, I const &i) ->
+  typename std::enable_if<std::is_unsigned<I>::value, BufferWriter &>::type
 {
   return bw_fmt::Format_Integer(w, spec, i, false);
 }
 
-inline BufferWriter &
-bwformat(BufferWriter &w, BWFSpec const &spec, int const &i)
+template <typename I>
+auto
+bwformat(BufferWriter &w, BWFSpec const &spec, I const &i) ->
+  typename std::enable_if<std::is_signed<I>::value, BufferWriter &>::type
 {
   return i < 0 ? bw_fmt::Format_Integer(w, spec, -i, true) : bw_fmt::Format_Integer(w,
spec, i, false);
 }
 
-// Annoying but otherwise ambiguous with char
-inline BufferWriter &
-operator<<(BufferWriter &w, int const &i)
-{
-  return bwformat(w, BWFSpec::DEFAULT, static_cast<intmax_t>(i));
-}
-
 // std::string support
 /** Print to a @c std::string
 
diff --git a/lib/ts/BufferWriterFormat.cc b/lib/ts/BufferWriterFormat.cc
index 2145a7d..d660e8f 100644
--- a/lib/ts/BufferWriterFormat.cc
+++ b/lib/ts/BufferWriterFormat.cc
@@ -589,7 +589,7 @@ BWF_Now(ts::BufferWriter &w, ts::BWFSpec const &spec)
   w.fill(std::strftime(w.auxBuffer(), w.remaining(), "%Y%b%d:%H%M%S", std::localtime(&t)));
 }
 
-static bool BW_INITIALIZED = []() -> bool {
+static bool BW_INITIALIZED __attribute__((unused)) = []() -> bool {
   ts::bw_fmt::BWF_GLOBAL_TABLE.emplace("now", &BWF_Now);
   return true;
 }();
diff --git a/lib/ts/Scalar.h b/lib/ts/Scalar.h
index 783f8c2..20c1f95 100644
--- a/lib/ts/Scalar.h
+++ b/lib/ts/Scalar.h
@@ -25,13 +25,13 @@
   limitations under the License.
  */
 
-#if !defined(TS_SCALAR_H)
-#define TS_SCALAR_H
+#pragma once
 
 #include <cstdint>
 #include <ratio>
 #include <ostream>
 #include <type_traits>
+#include <ts/BufferWriter.h>
 
 namespace tag
 {
@@ -911,14 +911,35 @@ namespace detail
     return s;
   }
   template <typename T>
+  inline BufferWriter &
+  tag_label(BufferWriter &w, BWFSpec const &, tag_label_A const &)
+  {
+    return w;
+  }
+  template <typename T>
   inline auto
   tag_label(std::ostream &s, tag_label_B const &) -> decltype(s << T::label,
s)
   {
     return s << T::label;
   }
+  template <typename T>
+  inline auto
+  tag_label(BufferWriter &w, BWFSpec const &spec, tag_label_B const &) ->
decltype(bwformat(w, spec, T::label), w)
+  {
+    return bwformat(w, spec, T::label);
+  }
 } // detail
 
-} // namespace
+template <intmax_t N, typename C, typename T>
+BufferWriter &
+bwformat(BufferWriter &w, BWFSpec const &spec, Scalar<N, C, T> const &x)
+{
+  static constexpr ts::detail::tag_label_B b{};
+  bwformat(w, spec, x.value());
+  return ts::detail::tag_label<T>(w, spec, b);
+}
+
+} // ts
 
 namespace std
 {
@@ -938,5 +959,4 @@ template <intmax_t N, typename C, intmax_t S, typename I, typename
T> struct com
   typedef std::ratio<N, S> R;
   typedef ts::Scalar<N / R::num, typename common_type<C, I>::type, T> type;
 };
-}
-#endif // TS_SCALAR_H
+} // std

-- 
To stop receiving notification emails like this one, please contact
amc@apache.org.

Mime
View raw message