(trafficserver) branch master updated: Unify Dynamic Table implementation (#10997)

2024-01-30 Thread maskit
This is an automated email from the ASF dual-hosted git repository.

maskit 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 367962abc5 Unify Dynamic Table implementation (#10997)
367962abc5 is described below

commit 367962abc5f9f8773b7a1d40b05e2845d984af91
Author: Masakazu Kitajo 
AuthorDate: Tue Jan 30 10:20:50 2024 -0700

Unify Dynamic Table implementation (#10997)
---
 include/proxy/hdrs/XPACK.h  |  78 +++
 include/proxy/http2/HPACK.h |  35 +---
 include/proxy/http3/QPACK.h |  77 +--
 src/proxy/hdrs/CMakeLists.txt   |   4 +-
 src/proxy/hdrs/XPACK.cc | 354 +++
 src/proxy/hdrs/unit_tests/test_XPACK.cc | 182 
 src/proxy/http2/HPACK.cc| 231 ++---
 src/proxy/http3/QPACK.cc| 357 ++--
 8 files changed, 706 insertions(+), 612 deletions(-)

diff --git a/include/proxy/hdrs/XPACK.h b/include/proxy/hdrs/XPACK.h
index 70814a512b..f4b705a761 100644
--- a/include/proxy/hdrs/XPACK.h
+++ b/include/proxy/hdrs/XPACK.h
@@ -24,6 +24,7 @@
 #pragma once
 
 #include 
+#include 
 #include "tscore/Arena.h"
 
 const static int XPACK_ERROR_COMPRESSION_ERROR   = -1;
@@ -35,3 +36,80 @@ int64_t xpack_decode_integer(uint64_t , const uint8_t 
*buf_start, const uint
 int64_t xpack_encode_string(uint8_t *buf_start, const uint8_t *buf_end, const 
char *value, uint64_t value_len, uint8_t n = 7);
 int64_t xpack_decode_string(Arena , char **str, uint64_t _length, 
const uint8_t *buf_start, const uint8_t *buf_end,
 uint8_t n = 7);
+
+struct XpackLookupResult {
+  uint32_t index  = 0;
+  enum MatchType { NONE, NAME, EXACT } match_type = MatchType::NONE;
+};
+
+struct XpackDynamicTableEntry {
+  uint32_t index = 0;
+  uint32_t offset= 0;
+  uint32_t name_len  = 0;
+  uint32_t value_len = 0;
+  uint32_t ref_count = 0;
+  const char *wks= nullptr;
+};
+
+class XpackDynamicTableStorage
+{
+public:
+  XpackDynamicTableStorage(uint32_t size);
+  ~XpackDynamicTableStorage();
+  void read(uint32_t offset, const char **name, uint32_t name_len, const char 
**value, uint32_t value_len) const;
+  uint32_t write(const char *name, uint32_t name_len, const char *value, 
uint32_t value_len);
+  void erase(uint32_t name_len, uint32_t value_len);
+
+private:
+  uint32_t _overwrite_threshold = 0;
+  uint8_t *_data= nullptr;
+  uint32_t _data_size   = 0;
+  uint32_t _head= 0;
+  uint32_t _tail= 0;
+};
+
+class XpackDynamicTable
+{
+public:
+  XpackDynamicTable(uint32_t size);
+  ~XpackDynamicTable();
+
+  const XpackLookupResult lookup(uint32_t absolute_index, const char **name, 
size_t *name_len, const char **value,
+ size_t *value_len) const;
+  const XpackLookupResult lookup(const char *name, size_t name_len, const char 
*value, size_t value_len) const;
+  const XpackLookupResult lookup(const std::string_view name, const 
std::string_view value) const;
+  const XpackLookupResult lookup_relative(uint32_t relative_index, const char 
**name, size_t *name_len, const char **value,
+  size_t *value_len) const;
+  const XpackLookupResult lookup_relative(const char *name, size_t name_len, 
const char *value, size_t value_len) const;
+  const XpackLookupResult lookup_relative(const std::string_view name, const 
std::string_view value) const;
+  const XpackLookupResult insert_entry(const char *name, size_t name_len, 
const char *value, size_t value_len);
+  const XpackLookupResult insert_entry(const std::string_view name, const 
std::string_view value);
+  const XpackLookupResult duplicate_entry(uint32_t current_index);
+  bool should_duplicate(uint32_t index);
+  bool update_maximum_size(uint32_t max_size);
+  uint32_t size() const;
+  uint32_t maximum_size() const;
+  void ref_entry(uint32_t index);
+  void unref_entry(uint32_t index);
+  bool is_empty() const;
+  uint32_t largest_index() const;
+  uint32_t count() const;
+
+private:
+  static constexpr uint8_t ADDITIONAL_32_BYTES = 32;
+  uint32_t _maximum_size   = 0;
+  uint32_t _available  = 0;
+  uint32_t _entries_inserted   = 0;
+
+  struct XpackDynamicTableEntry *_entries = nullptr;
+  uint32_t _max_entries   = 0;
+  uint32_t _entries_head  = 0;
+  uint32_t _entries_tail  = 0;
+  XpackDynamicTableStorage _storage;
+
+  /**
+   * The type of reuired_size is uint64 so that we can handle a size that is 
begger than the table capacity.
+   * Passing a value more than UINT32_MAX evicts every entry and return false.
+   */
+  bool _make_space(uint64_t required_size);
+};
diff --git 

(trafficserver-libswoc) 01/01: IPSpace: fix for blend problem.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch blend-fix
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit e67581c6c4022bd299790e37944855d98de2eb7f
Author: Alan M. Carroll 
AuthorDate: Wed May 27 17:31:57 2020 -0500

IPSpace: fix for blend problem.
---
 code/include/swoc/DiscreteRange.h   |   2 +-
 example/ex_netcompact.cc|  47 +++
 example/ex_netdb.cc |   4 +-
 unit_tests/ex_ipspace_properties.cc |   2 +-
 unit_tests/test_ip.cc   | 621 +++-
 5 files changed, 671 insertions(+), 5 deletions(-)

diff --git a/code/include/swoc/DiscreteRange.h 
b/code/include/swoc/DiscreteRange.h
index 56e8e68..280e836 100644
--- a/code/include/swoc/DiscreteRange.h
+++ b/code/include/swoc/DiscreteRange.h
@@ -1307,12 +1307,12 @@ DiscreteSpace::blend(DiscreteSpace::range_type const& range, U
 if (same_color_p && n->max() >= remaining.max()) {
   return *this; // incoming range is completely covered by @a n in the 
same color, done.
 }
-remaining.assign_min(++metric_type(n->max())); // going to fill up 
n->max(), clip target.
 if (!same_color_p) {
   n->assign_max(--metric_type(remaining.min())); // clip @a n down.
   this->insert_after(n, fill.get()); // add intersection node in 
different color.
   n = fill.release(); // skip to use new node as current node.
 }
+remaining.assign_min(++metric_type(n->max())); // going to fill up 
n->max(), clip target.
   } else { // clear, don't fill.
 auto n_r = n->range(); // cache to avoid ordering requirements.
 if (n_r.max() > remaining.max()) { // overhang on the right, must 
split.
diff --git a/example/ex_netcompact.cc b/example/ex_netcompact.cc
index 6e62d60..0114df9 100644
--- a/example/ex_netcompact.cc
+++ b/example/ex_netcompact.cc
@@ -38,6 +38,8 @@ using W = swoc::LocalBufferWriter<512>;
 /// IPSpace for mapping address. Treating it as a set so use a no-data payload.
 using Space = swoc::IPSpace;
 
+void post_processing_performance_test(Space & space);
+
 /// Process the @a content of a file in to @a space.
 unsigned process(Space& space, TextView content) {
   int line_no = 0; /// Track for error reporting.
@@ -99,5 +101,50 @@ int main(int argc, char *argv[]) {
 , n_ranges, space.count(), n_nets
 , std::chrono::duration_cast(delta).count());
 
+  post_processing_performance_test(space);
   return 0;
 }
+
+void post_processing_performance_test(Space & space) {
+  using swoc::IP4Addr;
+  using swoc::IP6Addr;
+
+  std::vector a4;
+  std::vector a6;
+  for ( auto && [ r, p] : space) {
+if (r.is_ip4()) {
+  IP4Addr a = r.min().ip4();
+  a4.push_back(a);
+  a4.push_back(--IP4Addr(a));
+  a4.push_back(++IP4Addr(a));
+  a = r.max().ip4();
+  a4.push_back(a);
+  a4.push_back(--IP4Addr(a));
+  a4.push_back(++IP4Addr(a));
+} else if (r.is_ip6()) {
+  IP6Addr a = r.min().ip6();
+  a6.push_back(a);
+  a6.push_back(--IP6Addr(a));
+  a6.push_back(++IP6Addr(a));
+  a = r.max().ip6();
+  a6.push_back(a);
+  a6.push_back(--IP6Addr(a));
+  a6.push_back(++IP6Addr(a));
+}
+  }
+  auto t0 = std::chrono::system_clock::now();
+  for ( auto const& addr : a4) {
+[[maybe_unused]] auto spot = space.find(addr);
+  }
+  auto delta = std::chrono::system_clock::now() - t0;
+  std::cout << W().print("IPv4 time - {} addresses, {} ns total, {} ns per 
lookup\n",
+a4.size(), delta.count(), delta.count() / a4.size());
+
+  t0 = std::chrono::system_clock::now();
+  for ( auto const& addr : a6) {
+[[maybe_unused]] auto spot = space.find(addr);
+  }
+  delta = std::chrono::system_clock::now() - t0;
+  std::cout << W().print("IPv6 time - {} addresses, {} ns total, {} ns per 
lookup\n",
+  a6.size(), delta.count(), delta.count() / a6.size());
+}
diff --git a/example/ex_netdb.cc b/example/ex_netdb.cc
index ffb563f..fc02e30 100644
--- a/example/ex_netdb.cc
+++ b/example/ex_netdb.cc
@@ -338,7 +338,7 @@ void post_processing_performance_test(Space & old_space) {
   }
   vz_delta = std::chrono::system_clock::now() - t0;
   std::cout << W().print("IPv6 time - {} addresses, {} ns total, {} ns per 
lookup\n",
-  a4.size(), vz_delta.count(), vz_delta.count() / a4.size());
+  a6.size(), vz_delta.count(), vz_delta.count() / a6.size());
 
   t0 = std::chrono::system_clock::now();
   for ( auto const& addr : a4) {
@@ -354,7 +354,7 @@ void post_processing_performance_test(Space & old_space) {
   }
   vz_delta = std::chrono::system_clock::now() - t0;
   std::cout << W().print("IPv6 time (pre-cleaning) - {} addresses, {} ns 
total, {} ns per lookup\n",
-  a4.size(), vz_delta.count(), vz_delta.count() / a4.size());
+  a6.size(), vz_delta.count(), vz_delta.count() / a6.size());
 }
 
 int main(int argc, char *argv[]) {
diff --git a/unit_tests/ex_ipspace_properties.cc 

(trafficserver-libswoc) branch blend-fix created (now e67581c)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch blend-fix
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at e67581c  IPSpace: fix for blend problem.

This branch includes the following new commits:

 new e67581c  IPSpace: fix for blend problem.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) branch training created (now be8ff88)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at be8ff88  Checkpoint - vectray.

This branch includes the following new commits:

 new 47cc132  Training: Vectray sketch.
 new c02bced  Add Vectray files.
 new 2f932bf  CMake: update target to include version.
 new c0cd064  CMake: Update pkg_config file to include version.
 new b0d0713  BWF: Add support for std::error_code.
 new 18e2197  Refactor using std:;variant.
 new 48b4c39  Working on constructors.
 new be8ff88  Checkpoint - vectray.

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 06/08: Refactor using std:;variant.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 18e21970bdd2e3c90887378a7b3babc0e27c2c7f
Author: Alan M. Carroll 
AuthorDate: Wed Jun 9 09:41:44 2021 -0500

Refactor using std:;variant.
---
 code/include/swoc/Vectray.h | 416 ++--
 unit_tests/test_Vectray.cc  |  20 +++
 unit_tests/test_meta.cc |   6 +-
 3 files changed, 151 insertions(+), 291 deletions(-)

diff --git a/code/include/swoc/Vectray.h b/code/include/swoc/Vectray.h
index f22710c..dc8deb9 100644
--- a/code/include/swoc/Vectray.h
+++ b/code/include/swoc/Vectray.h
@@ -2,9 +2,13 @@
 
 #include 
 #include 
-#include 
+#include 
+#include 
 #include 
 
+#include 
+#include 
+
 namespace swoc { inline namespace SWOC_VERSION_NS {
 
 /** Vectray provides a combination of static and dynamic storage modeled as an 
array.
@@ -25,200 +29,108 @@ template < typename T, size_t N, class A = 
std::allocator >
 class Vectray {
   using self_type = Vectray; ///< Self reference type.
   using vector_type = std::vector;
-protected:
-  /// Raw storage for an instance.
-  union TBlock {
-struct {} _nil; ///< Target for default constructor.
-T _t; ///< aliased instance.
-
-/// Default constructor, required to make this default constructable for 
@c std::array.
-/// @internal By design, this does nothing. It a goal to not construct a 
@a T instance.
-TBlock() {}
-  };
 
-  using StaticStore = std::array; ///< Static (instance local) 
storage.
-  using DynamicStore = std::vector; ///< Dynamic (heap) storage.
-
-public:
-  /// STL compliance types.
+public: // STL compliance types.
   using value_type = T;
   using allocator_type = A;
   using size_type = typename vector_type::size_type;
   using difference_type = typename vector_type::difference_type;
+  using iterator = typename swoc::MemSpan::iterator;
+  using const_iterator = typename swoc::MemSpan::iterator;
 
+protected:
+  /// Internal (fixed) storage.
+  struct FixedStore {
+size_t _count = 0; ///< Number of valid elements.
+allocator_type _a; ///< Allocator instance - used for construction.
+std::array _raw; ///< Raw memory for element 
storage.
+
+FixedStore() = default;
+explicit FixedStore(allocator_type const& a) : _a(a) {}
+  };
+  using DynamicStore = vector_type; ///< Dynamic (heap) storage.
+
+  /// Generic form for referencing stored objects.
+  using span = swoc::MemSpan;
+  using const_span = swoc::MemSpan;
+
+public:
   /// Default constructor, construct an empty container.
   Vectray();
 
+  /// Construct empty instance with allocator.
+  explicit Vectray(allocator_type const& a) : 
_store(std::in_place_type_t{}, a) {}
+
+  explicit Vectray(size_type n, allocator_type const& alloc = 
allocator_type());
+
+  /// @return The number of elements in the container.
+  size_type size() const;
+
   /** Index operator.
*
* @param idx Index of element.
* @return A reference to the element.
*/
-  T & operator [] (size_type idx);
+  T& operator[](size_type idx);
 
   /** Index operator (const).
*
* @param idx Index of element.
* @return A @c const reference to the element.
*/
-  T const& operator [] (size_type idx) const;
+  T const& operator[](size_type idx) const;
 
-  /** Add an element to the end of the current elements.
+  /** Append an element by copy.
*
* @param src Element to add.
* @return @a this.
*/
-  self_type & push_back(T const& src);
+  self_type& push_back(T const& t);
+
+  /** Append an element by direct construction.
+   *
+   * @tparam Args Constructor parameter types.
+   * @param args Constructor arguments.
+   * @return @a this
+   */
+  template < typename ... Args> self_type& emplace_back(Args... args);
 
   /** Remove an element from the end of the current elements.
*
* @return @a this.
*/
-  self_type & pop_back();
-
-   /// @return The number of elements in the container.
-  size_type size() const;
-
-  // iteration
-
-  /// Constant iteration.
-  class const_iterator {
-using self_type = const_iterator; ///< Self reference type.
-friend class Vectray; ///< Allow container access to internals.
-
-  public:
-// STL compliance.
-using value_type = const typename Vectray::value_type; /// Import for API 
compliance.
-using iterator_category = std::bidirectional_iterator_tag;
-using pointer   = value_type *;
-using reference = value_type &;
-using difference_type   = typename Vectray::difference_type;
-
-/// Default constructor.
-const_iterator();
-
-/// Pre-increment.
-/// Move to the next element in the list.
-/// @return The iterator.
-self_type ++();
-
-/// Pre-decrement.
-/// Move to the previous element in the list.
-/// @return The iterator.
-self_type ();
-
-/// Post-increment.
-/// Move to the 

(trafficserver-libswoc) 05/08: BWF: Add support for std::error_code.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit b0d07134b706c446228e7bd6c41a5d85db0d90ee
Author: Alan M. Carroll 
AuthorDate: Mon Jun 7 06:06:45 2021 -0500

BWF: Add support for std::error_code.
---
 code/src/bw_format.cc | 4 +---
 doc/code/BW_Format.en.rst | 7 +++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/code/src/bw_format.cc b/code/src/bw_format.cc
index afa3126..89e4dd8 100644
--- a/code/src/bw_format.cc
+++ b/code/src/bw_format.cc
@@ -837,10 +837,8 @@ operator<<(ostream , swoc::FixedBufferWriter )
 swoc::BufferWriter &
 bwformat(swoc::BufferWriter , swoc::bwf::Spec const , error_code const 
)
 {
-  // This provides convenient safe access to the errno short name array.
   static const swoc::bwf::Format number_fmt{"[{}]"_sv}; // numeric value 
format.
-  if (spec.has_numeric_type()) {// if numeric type, 
print just the numeric
-// part.
+  if (spec.has_numeric_type()) { // only the number
 w.print(number_fmt, ec.value());
   } else {
 w.write(ec.message());
diff --git a/doc/code/BW_Format.en.rst b/doc/code/BW_Format.en.rst
index d8a1e81..991c369 100644
--- a/doc/code/BW_Format.en.rst
+++ b/doc/code/BW_Format.en.rst
@@ -533,6 +533,13 @@ Specific types
 bw.print("{:>20: =a}",addr); // -> " 172. 19.  3.105"
   }
 
+:code:`std::error_code`
+   :code:`#include "swoc/bwf_std.h"
+
+   Formatting for :code:`std::error_code`. Generically the formatted output is 
the description and
+   the numeric value. A format type of ``d`` will generate the numeric value, 
while a format type of
+   ``s`` will generate the description.
+
 Format Classes
 --
 



(trafficserver-libswoc) 07/08: Working on constructors.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 48b4c392a8512599e55c2a425a846ae35c4de584
Author: Alan M. Carroll 
AuthorDate: Wed Jun 16 07:09:11 2021 -0500

Working on constructors.
---
 code/include/swoc/Vectray.h | 55 +++--
 1 file changed, 48 insertions(+), 7 deletions(-)

diff --git a/code/include/swoc/Vectray.h b/code/include/swoc/Vectray.h
index dc8deb9..4bf0149 100644
--- a/code/include/swoc/Vectray.h
+++ b/code/include/swoc/Vectray.h
@@ -59,9 +59,25 @@ public:
   Vectray();
 
   /// Construct empty instance with allocator.
-  explicit Vectray(allocator_type const& a) : 
_store(std::in_place_type_t{}, a) {}
+  constexpr explicit Vectray(allocator_type const& a) : 
_store(std::in_place_type_t{}, a) {}
 
-  explicit Vectray(size_type n, allocator_type const& alloc = 
allocator_type());
+  /** Construct with @a n default constructed elements.
+   *
+   * @param n Number of elements.
+   * @param alloc Allocator (optional - default constructed if not a 
parameter).
+   */
+  explicit Vectray(size_type n, allocator_type const& alloc = 
allocator_type{});
+
+  Vectray(self_type && that) {
+// If @a that is already a vector, always move that here.
+if (DYNAMIC == that._store.index()) {
+  _store = std::move(std::get(that._store));
+} else {
+  auto & fixed = std::get(_store);
+}
+  }
+
+  Vectray(self_type && that, allocator_type const& a);
 
   /// @return The number of elements in the container.
   size_type size() const;
@@ -128,9 +144,17 @@ protected:
   /// Get the span of the valid items.
   const_span items() const;
 
-  /// Transfer from fixed storage to dynamic storage.
-  /// Must not be called more than once per instance.
-  void transfer();
+  /// Default size to reserve in the vector when switching to dynamic.
+  static constexpr size_type BASE_DYNAMIC_SIZE = (7 * N) / 5;
+
+
+  /** Transfer from fixed storage to dynamic storage.
+   *
+   * @param rN Numer of elements of storage to reserve in the vector.
+   *
+   * @note Must be called at most once for any instance.
+   */
+  void transfer(size_type rN = BASE_DYNAMIC_SIZE);
 };
 
 // --- Implementation ---
@@ -138,6 +162,14 @@ protected:
 template
 Vectray::Vectray() {}
 
+template
+Vectray::Vectray(Vectray::size_type n, allocator_type const& alloc) : 
Vectray() {
+  this->reserve(n);
+  while (n-- > 0) {
+this->emplace_back();
+  }
+}
+
 template
 T& Vectray::operator[](size_type idx) {
   return this->items()[idx];
@@ -204,9 +236,9 @@ auto Vectray::end() -> iterator { return 
this->items().end(); }
 // --- iterators
 
 template
-void Vectray::transfer() {
+void Vectray::transfer(size_type rN) {
   DynamicStore tmp{std::get(_store)._a};
-  tmp.reserve((14 * N) / 10); // bump by approximately sqrt(2).
+  tmp.reserve(rN);
 
   for (auto&& item : this->items()) {
 tmp.emplace_back(item); // move if supported, copy if not.
@@ -231,5 +263,14 @@ auto Vectray::items() -> span {
   }, _store);
 }
 
+template
+void Vectray::reserve(Vectray::size_type n) {
+  if (DYNAMIC == _store.index()) {
+std::get(_store).reserve(n);
+  } else if (n > N) {
+this->transfer(n);
+  }
+}
+
 }} // namespace swoc
 



(trafficserver-libswoc) 08/08: Checkpoint - vectray.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit be8ff888b5f14f6e87606933a08b8bd7fa1abcc4
Author: Alan M. Carroll 
AuthorDate: Tue Jul 27 17:28:20 2021 -0500

Checkpoint - vectray.
---
 code/include/swoc/MemSpan.h | 32 +++-
 code/include/swoc/Vectray.h | 22 ++
 unit_tests/test_MemSpan.cc  | 16 
 3 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/code/include/swoc/MemSpan.h b/code/include/swoc/MemSpan.h
index 326a59d..c5ff7f4 100644
--- a/code/include/swoc/MemSpan.h
+++ b/code/include/swoc/MemSpan.h
@@ -17,8 +17,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
-
+#include 
 #include "swoc/swoc_version.h"
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
@@ -51,6 +52,18 @@ public:
   /// Copy constructor.
   constexpr MemSpan(self_type const ) = default;
 
+  /// Construct constant span from non-constant span of the same basic type.
+  /// @internal Must be inline here because it doesn't always exist.
+  template < typename U
+, typename META = std::enable_if_t<
+std::conjunction_v<
+std::is_const
+  , std::is_same>
+>
+  >
+>
+  constexpr MemSpan(MemSpan const& that) : _ptr(that.data()), 
_count(that.count()) {}
+
   /** Construct from a first element @a start and a @a count of elements.
*
* @param start First element.
@@ -72,6 +85,20 @@ public:
*/
   template  MemSpan(T ()[N]);
 
+  /** Construct from a @c std::array.
+   *
+   * @tparam N Array size.
+   * @param a Array instance.
+   */
+  template  constexpr MemSpan(std::array const& a);
+
+  /** Construct from a @c std::array.
+   *
+   * @tparam N Array size.
+   * @param a Array instance.
+   */
+  template  constexpr MemSpan(std::array & a);
+
   /** Construct from nullptr.
   This implicitly makes the length 0.
   */
@@ -599,6 +626,9 @@ template  constexpr MemSpan::MemSpan(T 
*first, T *last) : _ptr{fi
 
 template  template  MemSpan::MemSpan(T ()[N]) : 
_ptr{a}, _count{N} {}
 
+template  template  constexpr 
MemSpan::MemSpan(std::array const& a) : _ptr{a.data()} , 
_count{a.size()} {}
+template  template  constexpr 
MemSpan::MemSpan(std::array & a) : _ptr{a.data()} , _count{a.size()} {}
+
 template  constexpr MemSpan::MemSpan(std::nullptr_t) {}
 
 template 
diff --git a/code/include/swoc/Vectray.h b/code/include/swoc/Vectray.h
index 4bf0149..5252127 100644
--- a/code/include/swoc/Vectray.h
+++ b/code/include/swoc/Vectray.h
@@ -47,6 +47,7 @@ protected:
 
 FixedStore() = default;
 explicit FixedStore(allocator_type const& a) : _a(a) {}
+MemSpan span();
   };
   using DynamicStore = vector_type; ///< Dynamic (heap) storage.
 
@@ -68,12 +69,20 @@ public:
*/
   explicit Vectray(size_type n, allocator_type const& alloc = 
allocator_type{});
 
-  Vectray(self_type && that) {
+  template < size_t M >
+  Vectray(Vectray && that) {
 // If @a that is already a vector, always move that here.
 if (DYNAMIC == that._store.index()) {
   _store = std::move(std::get(that._store));
 } else {
-  auto & fixed = std::get(_store);
+  auto span = std::get(that._store).span();
+  if (span.size() > N) {
+
+  } else {
+for ( auto && item : span ) {
+  this->template emplace_back(std::move(item));
+}
+  }
 }
   }
 
@@ -170,6 +179,11 @@ Vectray::Vectray(Vectray::size_type n, 
allocator_type const& alloc) : V
   }
 }
 
+template
+MemSpan Vectray::FixedStore::span() {
+  return MemSpan(_raw).template rebind();
+}
+
 template
 T& Vectray::operator[](size_type idx) {
   return this->items()[idx];
@@ -250,7 +264,7 @@ void Vectray::transfer(size_type rN) {
 template
 auto Vectray::items() const -> const_span {
   return std::visit(swoc::meta::vary{
-  [](FixedStore const& fs) { return const_span(reinterpret_cast(fs._raw.data()), fs._count); }
+  [](FixedStore const& fs) { fs.span(); }
   , [](DynamicStore const& ds) { return const_span(ds.data(), ds.size()); }
   }, _store);
 }
@@ -258,7 +272,7 @@ auto Vectray::items() const -> const_span {
 template
 auto Vectray::items() -> span {
   return std::visit(swoc::meta::vary{
-  [](FixedStore & fs) { return span(reinterpret_cast(fs._raw.data()), 
fs._count); }
+  [](FixedStore & fs) { return fs.span(); }
   , [](DynamicStore & ds) { return span(ds.data(), ds.size()); }
   }, _store);
 }
diff --git a/unit_tests/test_MemSpan.cc b/unit_tests/test_MemSpan.cc
index 64aaf72..64a44ad 100644
--- a/unit_tests/test_MemSpan.cc
+++ b/unit_tests/test_MemSpan.cc
@@ -112,3 +112,19 @@ TEST_CASE("MemSpan", "[libswoc][MemSpan]")
   REQUIRE(left.size() + span.size() == 1024);
 
 };
+
+TEST_CASE("MemSpan Construction", "[libswoc][MemSpan]")
+{
+  std::array a{ 1, 2, 3 };
+  // Automatic construction from an array.
+  MemSpan aspan{a};
+
+  REQUIRE(a[1] 

(trafficserver-libswoc) 02/08: Add Vectray files.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit c02bceddec50b91513f27f2e0dbb260be0c1f520
Author: Alan M. Carroll 
AuthorDate: Wed May 5 09:03:13 2021 -0500

Add Vectray files.
---
 code/include/swoc/Vectray.h | 397 
 unit_tests/test_Vectray.cc  |  21 +++
 2 files changed, 418 insertions(+)

diff --git a/code/include/swoc/Vectray.h b/code/include/swoc/Vectray.h
new file mode 100644
index 000..f22710c
--- /dev/null
+++ b/code/include/swoc/Vectray.h
@@ -0,0 +1,397 @@
+#pragma once
+
+#include 
+#include 
+#include 
+#include 
+
+namespace swoc { inline namespace SWOC_VERSION_NS {
+
+/** Vectray provides a combination of static and dynamic storage modeled as an 
array.
+ *
+ * @tparam T Type of elements in the array.
+ * @tparam N Number of statically allocated elements.
+ * @tparam A Allocator.
+ *
+ * The goal is to provide static storage for the common case, avoiding memory 
allocation, while
+ * still handling exceptional cases that need more storage. A common case is 
for @a N == 1 where
+ * there is almost always a single value, but it is possible to have multiple 
values. @c Vectray
+ * makes the single value case require no allocation while transparently 
handling the multiple
+ * value case.
+ *
+ * The interface is designed to mimic that of @c std::vector.
+ */
+template < typename T, size_t N, class A = std::allocator >
+class Vectray {
+  using self_type = Vectray; ///< Self reference type.
+  using vector_type = std::vector;
+protected:
+  /// Raw storage for an instance.
+  union TBlock {
+struct {} _nil; ///< Target for default constructor.
+T _t; ///< aliased instance.
+
+/// Default constructor, required to make this default constructable for 
@c std::array.
+/// @internal By design, this does nothing. It a goal to not construct a 
@a T instance.
+TBlock() {}
+  };
+
+  using StaticStore = std::array; ///< Static (instance local) 
storage.
+  using DynamicStore = std::vector; ///< Dynamic (heap) storage.
+
+public:
+  /// STL compliance types.
+  using value_type = T;
+  using allocator_type = A;
+  using size_type = typename vector_type::size_type;
+  using difference_type = typename vector_type::difference_type;
+
+  /// Default constructor, construct an empty container.
+  Vectray();
+
+  /** Index operator.
+   *
+   * @param idx Index of element.
+   * @return A reference to the element.
+   */
+  T & operator [] (size_type idx);
+
+  /** Index operator (const).
+   *
+   * @param idx Index of element.
+   * @return A @c const reference to the element.
+   */
+  T const& operator [] (size_type idx) const;
+
+  /** Add an element to the end of the current elements.
+   *
+   * @param src Element to add.
+   * @return @a this.
+   */
+  self_type & push_back(T const& src);
+
+  /** Remove an element from the end of the current elements.
+   *
+   * @return @a this.
+   */
+  self_type & pop_back();
+
+   /// @return The number of elements in the container.
+  size_type size() const;
+
+  // iteration
+
+  /// Constant iteration.
+  class const_iterator {
+using self_type = const_iterator; ///< Self reference type.
+friend class Vectray; ///< Allow container access to internals.
+
+  public:
+// STL compliance.
+using value_type = const typename Vectray::value_type; /// Import for API 
compliance.
+using iterator_category = std::bidirectional_iterator_tag;
+using pointer   = value_type *;
+using reference = value_type &;
+using difference_type   = typename Vectray::difference_type;
+
+/// Default constructor.
+const_iterator();
+
+/// Pre-increment.
+/// Move to the next element in the list.
+/// @return The iterator.
+self_type ++();
+
+/// Pre-decrement.
+/// Move to the previous element in the list.
+/// @return The iterator.
+self_type ();
+
+/// Post-increment.
+/// Move to the next element in the list.
+/// @return The iterator value before the increment.
+self_type operator++(int);
+
+/// Post-decrement.
+/// Move to the previous element in the list.
+/// @return The iterator value before the decrement.
+self_type operator--(int);
+
+/// Dereference.
+/// @return A reference to the referent.
+value_type *() const;
+
+/// Dereference.
+/// @return A pointer to the referent.
+value_type *operator->() const;
+
+/// Equality
+bool operator==(self_type const ) const;
+
+/// Inequality
+bool operator!=(self_type const ) const;
+
+  protected:
+// Stored non-const to make implementing @c iterator easier. This class 
provides the required @c
+// const protection.
+
+bool _static_p = true; ///< Is the iterator a static storage iterator?
+
+// Use anonymous union to promote these into the enclosing class 

(trafficserver-libswoc) 03/08: CMake: update target to include version.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 2f932bffc340160e187a71dcb86e306acd5a5dfc
Author: Alan M. Carroll 
AuthorDate: Wed May 12 11:32:21 2021 -0500

CMake: update target to include version.
---
 code/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index cc5089b..80fb79b 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -46,7 +46,7 @@ set(CC_FILES
 )
 
 add_library(libswoc STATIC ${CC_FILES})
-set_target_properties(libswoc PROPERTIES OUTPUT_NAME swoc-static)
+set_target_properties(libswoc PROPERTIES OUTPUT_NAME 
swoc.static.${LIBSWOC_VERSION})
 if (CMAKE_COMPILER_IS_GNUCXX)
 target_compile_options(libswoc PRIVATE -fPIC -Wall -Wextra -Werror 
-Wnon-virtual-dtor -Wpedantic)
 endif()



(trafficserver-libswoc) 04/08: CMake: Update pkg_config file to include version.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit c0cd064dcbba619afa0da11b8e2d8b9640e84f71
Author: Alan M. Carroll 
AuthorDate: Wed May 12 11:35:34 2021 -0500

CMake: Update pkg_config file to include version.
---
 code/libswoc.pc.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/code/libswoc.pc.cmake b/code/libswoc.pc.cmake
index c65ba62..6599544 100644
--- a/code/libswoc.pc.cmake
+++ b/code/libswoc.pc.cmake
@@ -7,5 +7,5 @@ Name: LibSWOC++
 Description: A collection of solid C++ utilities and classes.
 Version: @LIBSWOC_VERSION@
 Requires:
-Libs: -L${libdir} -lswoc
+Libs: -L${libdir} -lswoc.static.@LIBSWOC_VERSION@
 Cflags: -I${includedir}



(trafficserver-libswoc) 01/08: Training: Vectray sketch.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch training
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 47cc132cdf542be5f36801128238c003d483
Author: Alan M. Carroll 
AuthorDate: Wed May 5 08:53:31 2021 -0500

Training: Vectray sketch.
---
 code/CMakeLists.txt   | 1 +
 code/src/bw_format.cc | 1 -
 unit_tests/CMakeLists.txt | 1 +
 3 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index 24b978e..cc5089b 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -25,6 +25,7 @@ set(HEADER_FILES
 include/swoc/TextView.h
 include/swoc/swoc_file.h
 include/swoc/swoc_meta.h
+include/swoc/Vectray.h
 )
 
 # These are external but required.
diff --git a/code/src/bw_format.cc b/code/src/bw_format.cc
index 35b01b8..afa3126 100644
--- a/code/src/bw_format.cc
+++ b/code/src/bw_format.cc
@@ -1,5 +1,4 @@
 // SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: Apache-2.0
 // Copyright Apache Software Foundation 2019
 /** @file
 
diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt
index 301262f..20c5cd6 100644
--- a/unit_tests/CMakeLists.txt
+++ b/unit_tests/CMakeLists.txt
@@ -18,6 +18,7 @@ add_executable(test_libswoc
 test_TextView.cc
 test_Scalar.cc
 test_swoc_file.cc
+test_Vectray.cc
 
 ex_bw_format.cc
 ex_IntrusiveDList.cc



(trafficserver-libswoc) 06/07: Update to 1.4.0

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch ipsrv
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 7333bfa276bf76ef298cc263d0a32728c84c697b
Author: Alan M. Carroll 
AuthorDate: Sun Nov 13 08:36:47 2022 -0600

Update to 1.4.0
---
 code/CMakeLists.txt  | 2 +-
 code/include/swoc/swoc_version.h | 6 +++---
 code/libswoc.part| 2 +-
 doc/Doxyfile | 2 +-
 doc/code/TextView.en.rst | 4 ++--
 doc/code/ip_networking.en.rst| 2 +-
 doc/conf.py  | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index 0eec6fe..de01ad4 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.11)
 
 project(Lib-SWOC CXX)
-set(LIBSWOC_VERSION "1.3.12")
+set(LIBSWOC_VERSION "1.4.0")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/code/include/swoc/swoc_version.h b/code/include/swoc/swoc_version.h
index 8f551f3..ee9d56a 100644
--- a/code/include/swoc/swoc_version.h
+++ b/code/include/swoc/swoc_version.h
@@ -23,11 +23,11 @@
 #pragma once
 
 #if !defined(SWOC_VERSION_NS)
-#define SWOC_VERSION_NS _1_3_12
+#define SWOC_VERSION_NS _1_4_0
 #endif
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 static constexpr unsigned MAJOR_VERSION = 1;
-static constexpr unsigned MINOR_VERSION = 3;
-static constexpr unsigned POINT_VERSION = 12;
+static constexpr unsigned MINOR_VERSION = 4;
+static constexpr unsigned POINT_VERSION = 0;
 }} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/libswoc.part b/code/libswoc.part
index de6293f..680fcc0 100644
--- a/code/libswoc.part
+++ b/code/libswoc.part
@@ -1,6 +1,6 @@
 Import("*")
 PartName("libswoc")
-PartVersion("1.3.12")
+PartVersion("1.4.0")
 
 src_files = [
 "src/ArenaWriter.cc",
diff --git a/doc/Doxyfile b/doc/Doxyfile
index 990e52a..e678b3b 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.3.12"
+PROJECT_NUMBER = "1.4.0"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 53c4d2a..260e5ba 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -343,7 +343,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, extracting each 
comma separated
 element. The resulting element is treated as a "list" with ``=`` as the 
separator. Note if there is
@@ -395,7 +395,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/code/ip_networking.en.rst b/doc/code/ip_networking.en.rst
index 08506de..2efcdb2 100644
--- a/doc/code/ip_networking.en.rst
+++ b/doc/code/ip_networking.en.rst
@@ -194,7 +194,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/conf.py b/doc/conf.py
index 6524e5e..7da6b01 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -79,7 +79,7 @@ project = u'Solid Wall Of C++'
 copyright = u'{}, a...@apache.org'.format(date.today().year)
 
 # The full version, including alpha/beta/rc tags.
-release = "1.3.12"
+release = "1.4.0"
 # The short X.Y version.
 version = '.'.join(release.split('.', 2)[:2])
 



(trafficserver-libswoc) 07/07: Fix overzealous refactor.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch ipsrv
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 109a69a3b28e5d550b9ea8e360a66cd3b654cd41
Author: Alan M. Carroll 
AuthorDate: Sun Nov 13 08:58:04 2022 -0600

Fix overzealous refactor.
---
 code/src/bw_format.cc | 61 ---
 doc/code/BW_Format.en.rst |  6 ++---
 doc/code/ip_networking.en.rst |  8 +++---
 unit_tests/test_ip.cc | 12 ++---
 4 files changed, 16 insertions(+), 71 deletions(-)

diff --git a/code/src/bw_format.cc b/code/src/bw_format.cc
index 29a06fb..ac9ce9e 100644
--- a/code/src/bw_format.cc
+++ b/code/src/bw_format.cc
@@ -943,67 +943,6 @@ bwformat(BufferWriter , bwf::Spec const , 
bwf::Pattern const ) {
   return w;
 }
 
-// --- IP address support ---
-
-#if 0
-BufferWriter &
-bwformat(BufferWriter , bwf::Spec const , IpAddr const )
-{
-  bwf::Spec local_spec{spec}; // Format for address elements and 
host_order_port.
-  bool addr_p{true};
-  bool family_p{false};
-
-  if (spec._ext.size()) {
-if (spec._ext.front() == '=') {
-  local_spec._ext.remove_prefix(1);
-} else if (spec._ext.size() > 1 && spec._ext[1] == '=') {
-  local_spec._ext.remove_prefix(2);
-}
-  }
-  if (local_spec._ext.size()) {
-addr_p = false;
-for (char c : local_spec._ext) {
-  switch (c) {
-case 'a':
-case 'A':
-  addr_p = true;
-  break;
-case 'f':
-case 'F':
-  family_p = true;
-  break;
-  }
-}
-  }
-
-  if (addr_p) {
-if (addr.isIp4()) {
-  bwformat(w, spec, addr._addr._ip4);
-} else if (addr.isIp6()) {
-  bwformat(w, spec, addr._addr._ip6);
-} else {
-  w.print("*Not IP address [{}]*", addr.family());
-}
-  }
-
-  if (family_p) {
-local_spec._min = 0;
-if (addr_p) {
-  w.write(' ');
-}
-if (spec.has_numeric_type()) {
-  bwformat(w, local_spec, static_cast(addr.family()));
-} else {
-  bwformat(w, local_spec, addr.family());
-}
-  }
-  return w;
-}
-#endif
-
-namespace {
-} // namespace
-
 }} // namespace swoc::SWOC_VERSION_NS
 
 namespace std {
diff --git a/doc/code/BW_Format.en.rst b/doc/code/BW_Format.en.rst
index 99f2eb5..d8a1e81 100644
--- a/doc/code/BW_Format.en.rst
+++ b/doc/code/BW_Format.en.rst
@@ -501,14 +501,14 @@ Specific types
  The pointer address is printed as hexadecimal lower ('p') or upper 
('P') case.
 
The extension can be used to control which parts of the address are 
printed. These can be in any order,
-   the output is always address, host_order_port, family. The default is the 
equivalent of "ap". In addition, the
+   the output is always address, port, family. The default is the equivalent 
of "ap". In addition, the
character '=' ("numeric align") can be used to internally right justify the 
elements.
 
'a'
   The address.
 
'p'
-  The host_order_port (host order).
+  The port (host order).
 
'f'
   The IP address family.
@@ -521,7 +521,7 @@ Specific types
 
   void func(sockaddr const* addr) {
 bw.print("To {}", addr); // -> "To 172.19.3.105:4951"
-bw.print("To {0::a} on host_order_port {0::p}", addr); // -> "To 
172.19.3.105 on host_order_port 4951"
+bw.print("To {0::a} on port {0::p}", addr); // -> "To 172.19.3.105 on 
port 4951"
 bw.print("To {::=}", addr); // -> "To 127.019.003.105:04951"
 bw.print("Using address family {::f}", addr);
 bw.print("{::a}",addr);  // -> "172.19.3.105"
diff --git a/doc/code/ip_networking.en.rst b/doc/code/ip_networking.en.rst
index 2efcdb2..055bd29 100644
--- a/doc/code/ip_networking.en.rst
+++ b/doc/code/ip_networking.en.rst
@@ -25,9 +25,9 @@ IPEndpoint
 
 :libswoc:`swoc::IPEndpoint` is a wrapper around :code:`sockaddr` and provides 
a number of utilities.
 It enables constructing an instance from the string representation of an 
address, supporting IPv4
-and IPv6. It will also parse and store the host_order_port if that is part of 
the string. Some of the internal
+and IPv6. It will also parse and store the port if that is part of the string. 
Some of the internal
 logic is exposed via :libswoc:`swoc::IPEndpoint::tokenize` which finds and 
returns the elements of
-an address string, the host (address), host_order_port, and any trailing 
remnants. This is useful for doing
+an address string, the host (address), port, and any trailing remnants. This 
is useful for doing
 syntax checks or more specialized processing of the address string.
 
 IPAddr
@@ -53,10 +53,10 @@ will conform to the family of the address in the 
:code:`sockaddr`.
 IPSrv
 =
 
-A container for an address and a host_order_port. There is no really good name 
for this therefore I used the
+A container for an address and a port. There is no really good name for this 
therefore I used the
 DNS term for such an object. This 

(trafficserver-libswoc) 04/07: IP fixes for refreshing ATS usage.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch ipsrv
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 3b6ed80a2597ad0df6a8bfbd191453fa4cd878f6
Author: Alan M. Carroll 
AuthorDate: Sat Nov 12 17:55:36 2022 -0600

IP fixes for refreshing ATS usage.
---
 code/include/swoc/DiscreteRange.h |  53 +---
 code/include/swoc/IPAddr.h| 175 
 code/include/swoc/IPRange.h   | 280 +++---
 code/include/swoc/IPSrv.h |  92 -
 code/include/swoc/TextView.h  |   2 +-
 code/include/swoc/bwf_fwd.h   |   4 +-
 code/src/bw_ip_format.cc  |   2 +-
 code/src/swoc_ip.cc   | 143 +++
 unit_tests/test_Errata.cc |   2 -
 unit_tests/test_ip.cc | 130 --
 10 files changed, 645 insertions(+), 238 deletions(-)

diff --git a/code/include/swoc/DiscreteRange.h 
b/code/include/swoc/DiscreteRange.h
index fa7cf7c..ee306a9 100644
--- a/code/include/swoc/DiscreteRange.h
+++ b/code/include/swoc/DiscreteRange.h
@@ -812,34 +812,27 @@ public:
   /** Find the payload at @a metric.
*
* @param metric The metric for which to search.
-   * @return The payload for @a metric if found, @c nullptr if not found.
+   * @return An iterator for the item or the @c end iterator if not.
*/
   iterator find(METRIC const );
 
+  /** Find the payload at @a metric.
+   *
+   * @param metric The metric for which to search.
+   * @return An iterator for the item or the @c end iterator if not.
+   */
+  const_iterator find(METRIC const ) const;
+
   /// @return The number of distinct ranges.
   size_t count() const;
 
-  iterator
-  begin() {
-return _list.begin();
-  }
-
-  iterator
-  end() {
-return _list.end();
-  }
+  iterator begin() { return _list.begin(); }
+  iterator end() { return _list.end(); }
+  const_iterator begin() const { return _list.begin(); }
+  const_iterator end() const { return _list.end(); }
 
   /// Remove all ranges.
-  void
-  clear() {
-for (auto  : _list) {
-  std::destroy_at(());
-}
-_list.clear();
-_root = nullptr;
-_arena.clear();
-_fa.clear();
-  }
+  void clear();
 
 protected:
   /** Find the lower bound range for @a target.
@@ -962,6 +955,13 @@ DiscreteSpace::find(METRIC const ) 
-> iterator {
   return this->end();
 }
 
+template 
+auto
+DiscreteSpace::find(METRIC const ) const -> 
const_iterator
+{
+  return const_cast(this)->find(metric);
+}
+
 template 
 auto
 DiscreteSpace::lower_bound(METRIC const ) -> Node * {
@@ -1519,4 +1519,17 @@ DiscreteSpace::blend(DiscreteSpace::range_type const , U
   return *this;
 }
 
+template 
+void
+DiscreteSpace::clear()
+{
+  for (auto  : _list) {
+std::destroy_at(());
+  }
+  _list.clear();
+  _root = nullptr;
+  _arena.clear();
+  _fa.clear();
+}
+
 }} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/include/swoc/IPAddr.h b/code/include/swoc/IPAddr.h
index 3a567d1..cacc455 100644
--- a/code/include/swoc/IPAddr.h
+++ b/code/include/swoc/IPAddr.h
@@ -53,9 +53,6 @@ public:
   /// If the @a text is invalid the result is an invalid instance.
   IP4Addr(string_view const );
 
-  /// Construct from generic address @a addr.
-  explicit IP4Addr(IPAddr const );
-
   /// Self assignment.
   self_type & operator=(self_type const& that) = default;
 
@@ -74,12 +71,11 @@ public:
   /** Byte access.
*
* @param idx Byte index.
-   * @return The byte at @a idx in the address.
+   * @return The byte at @a idx in the address (network order).
+   *
+   * For convenience, this returns in "text order" of the octets.
*/
-  uint8_t
-  operator[](unsigned idx) const {
-return reinterpret_cast(_addr)[idx];
-  }
+  uint8_t operator[](unsigned idx) const;
 
   /// Apply @a mask to address, leaving the network portion.
   self_type &=(IPMask const );
@@ -121,6 +117,12 @@ public:
   /// @return @c true if this is a loopback address, @c false if not.
   bool is_loopback() const;
 
+  /// @return @c true if the address is in the link local network.
+  bool is_link_local() const;
+
+  /// @return @c true if the address is private.
+  bool is_private() const;
+
   /** Left shift.
*
* @param n Number of bits to shift left.
@@ -215,11 +217,15 @@ public:
   explicit IP6Addr(sockaddr_in6 const *addr) { *this = addr; }
 
   /// Construct from text representation.
-  /// If the @a text is invalid the result is an invalid instance.
+  /// If the @a text is invalid the result is any address.
+  /// @see load
   IP6Addr(string_view const );
 
-  /// Construct from generic @a addr.
-  explicit IP6Addr(IPAddr const );
+  /** Construct mapped IPv4 address.
+   *
+   * @param addr IPv4 address
+   */
+  explicit IP6Addr(IP4Addr addr);
 
   /// Self assignment.
   self_type & operator=(self_type const& that) = default;
@@ -268,6 +274,13 @@ public:
   /// Set to the address in @a addr.
   self_type 

(trafficserver-libswoc) 05/07: Vectray - fix empty bug.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch ipsrv
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 71b312d03407ab876f3b2d8dab1c47d1bdbe5d24
Author: Alan M. Carroll 
AuthorDate: Sat Nov 12 21:59:26 2022 -0600

Vectray - fix empty bug.
---
 code/include/swoc/Vectray.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/code/include/swoc/Vectray.h b/code/include/swoc/Vectray.h
index a4c7246..75eb394 100644
--- a/code/include/swoc/Vectray.h
+++ b/code/include/swoc/Vectray.h
@@ -357,7 +357,7 @@ auto Vectray::size() const -> size_type {
 template
 bool Vectray::empty() const {
   return std::visit(swoc::meta::vary{
-   [](FixedStore const& fs) { return fs._count > 0; }
+   [](FixedStore const& fs) { return fs._count == 0; }
  , [](DynamicStore const& ds) { return ds.empty(); }
  }, _store);
 }



(trafficserver-libswoc) 02/07: Checkpoint - IPsrv

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch ipsrv
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit c0db5152dee101061368784c9ccf157d9d876b42
Author: Alan M. Carroll 
AuthorDate: Sun Oct 23 09:15:23 2022 -0500

Checkpoint - IPsrv
---
 code/include/swoc/IPAddr.h |   2 +
 code/include/swoc/IPEndpoint.h | 104 ++
 code/include/swoc/IPRange.h| 125 -
 code/include/swoc/swoc_ip.h|  28 -
 tools/ats-drop.sh  |   2 +
 5 files changed, 135 insertions(+), 126 deletions(-)

diff --git a/code/include/swoc/IPAddr.h b/code/include/swoc/IPAddr.h
index e49f660..3a567d1 100644
--- a/code/include/swoc/IPAddr.h
+++ b/code/include/swoc/IPAddr.h
@@ -10,6 +10,8 @@
 #include 
 
 #include "swoc/swoc_version.h"
+#include "swoc/swoc_meta.h"
+#include "swoc/MemSpan.h"
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 
diff --git a/code/include/swoc/IPEndpoint.h b/code/include/swoc/IPEndpoint.h
index f9e5001..4ae875c 100644
--- a/code/include/swoc/IPEndpoint.h
+++ b/code/include/swoc/IPEndpoint.h
@@ -5,11 +5,15 @@
  */
 
 #pragma once
+
 #include 
 #include 
 
+#include 
+
 #include "swoc/swoc_version.h"
 #include "swoc/TextView.h"
+
 namespace swoc { inline namespace SWOC_VERSION_NS {
 
 using ::std::string_view;
@@ -169,4 +173,104 @@ union IPEndpoint {
   static string_view family_name(sa_family_t family);
 };
 
+inline IPEndpoint::IPEndpoint() {
+  sa.sa_family = AF_UNSPEC;
+}
+
+inline IPEndpoint::IPEndpoint(IPAddr const ) {
+  this->assign(addr);
+}
+
+inline IPEndpoint::IPEndpoint(sockaddr const *sa) {
+  this->assign(sa);
+}
+
+inline IPEndpoint::IPEndpoint(IPEndpoint::self_type const ) : 
self_type() {}
+
+inline IPEndpoint &
+IPEndpoint::invalidate() {
+  sa.sa_family = AF_UNSPEC;
+  return *this;
+}
+
+inline void
+IPEndpoint::invalidate(sockaddr *addr) {
+  addr->sa_family = AF_UNSPEC;
+}
+
+inline bool
+IPEndpoint::is_valid() const {
+  return sa.sa_family == AF_INET || sa.sa_family == AF_INET6;
+}
+
+inline IPEndpoint &
+IPEndpoint::operator=(self_type const ) {
+  self_type::assign(, );
+  return *this;
+}
+
+inline IPEndpoint &
+IPEndpoint::assign(sockaddr const *src) {
+  self_type::assign(, src);
+  return *this;
+}
+
+inline IPEndpoint const &
+IPEndpoint::copy_to(sockaddr *addr) const {
+  self_type::assign(addr, );
+  return *this;
+}
+
+inline bool
+IPEndpoint::is_ip4() const {
+  return AF_INET == sa.sa_family;
+}
+
+inline bool
+IPEndpoint::is_ip6() const {
+  return AF_INET6 == sa.sa_family;
+}
+
+inline sa_family_t
+IPEndpoint::family() const {
+  return sa.sa_family;
+}
+
+inline in_port_t &
+IPEndpoint::network_order_port() {
+  return self_type::port();
+}
+
+inline in_port_t
+IPEndpoint::network_order_port() const {
+  return self_type::port();
+}
+
+inline in_port_t
+IPEndpoint::host_order_port() const {
+  return ntohs(this->network_order_port());
+}
+
+inline in_port_t &
+IPEndpoint::port(sockaddr *sa) {
+  switch (sa->sa_family) {
+  case AF_INET:
+return reinterpret_cast(sa)->sin_port;
+case AF_INET6:
+  return reinterpret_cast(sa)->sin6_port;
+  }
+  // Force a failure upstream by returning a null reference.
+  throw std::domain_error("sockaddr is not a valid IP address");
+}
+
+inline in_port_t
+IPEndpoint::port(sockaddr const *sa) {
+  return self_type::port(const_cast(sa));
+}
+
+inline in_port_t
+IPEndpoint::host_order_port(sockaddr const *sa) {
+  return ntohs(self_type::port(sa));
+}
+
 }} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/include/swoc/IPRange.h b/code/include/swoc/IPRange.h
index 51ed874..6e88705 100644
--- a/code/include/swoc/IPRange.h
+++ b/code/include/swoc/IPRange.h
@@ -1190,131 +1190,6 @@ IPSpace::iterator::operator--() -> self_type & 
{
 // --
 /// 

 
-inline IPEndpoint::IPEndpoint() {
-  sa.sa_family = AF_UNSPEC;
-}
-
-inline IPEndpoint::IPEndpoint(IPAddr const ) {
-  this->assign(addr);
-}
-
-inline IPEndpoint::IPEndpoint(sockaddr const *sa) {
-  this->assign(sa);
-}
-
-inline IPEndpoint::IPEndpoint(IPEndpoint::self_type const ) : 
self_type() {}
-
-inline IPEndpoint &
-IPEndpoint::invalidate() {
-  sa.sa_family = AF_UNSPEC;
-  return *this;
-}
-
-inline void
-IPEndpoint::invalidate(sockaddr *addr) {
-  addr->sa_family = AF_UNSPEC;
-}
-
-inline bool
-IPEndpoint::is_valid() const {
-  return sa.sa_family == AF_INET || sa.sa_family == AF_INET6;
-}
-
-inline IPEndpoint &
-IPEndpoint::operator=(self_type const ) {
-  self_type::assign(, );
-  return *this;
-}
-
-inline IPEndpoint &
-IPEndpoint::assign(sockaddr const *src) {
-  self_type::assign(, src);
-  return *this;
-}
-
-inline IPEndpoint const &
-IPEndpoint::copy_to(sockaddr *addr) const {
-  self_type::assign(addr, );
-  return *this;
-}
-
-inline 

(trafficserver-libswoc) branch ipsrv created (now 109a69a)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch ipsrv
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 109a69a  Fix overzealous refactor.

This branch includes the following new commits:

 new 6ba001c  IPSrv - checkpoint.
 new c0db515  Checkpoint - IPsrv
 new a0676f2  Fix typos.
 new 3b6ed80  IP fixes for refreshing ATS usage.
 new 71b312d  Vectray - fix empty bug.
 new 7333bfa  Update to 1.4.0
 new 109a69a  Fix overzealous refactor.

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 03/07: Fix typos.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch ipsrv
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit a0676f2701e8b0e27eec37794c88c422658e18c1
Author: Alan M. Carroll 
AuthorDate: Thu Oct 27 16:19:27 2022 -0500

Fix typos.
---
 code/src/bw_ip_format.cc | 4 ++--
 code/src/swoc_ip.cc  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/code/src/bw_ip_format.cc b/code/src/bw_ip_format.cc
index 5bd86d8..1c96b53 100644
--- a/code/src/bw_ip_format.cc
+++ b/code/src/bw_ip_format.cc
@@ -82,7 +82,7 @@ bwformat(BufferWriter , Spec const , in6_addr const 
) {
 
 BufferWriter &
 bwformat(BufferWriter , Spec const , sockaddr const *addr) {
-  Spec local_spec{spec}; // Format for address elements and host_order_port.
+  Spec local_spec{spec}; // Format for address elements and port.
   bool port_p{true};
   bool addr_p{true};
   bool family_p{false};
@@ -209,7 +209,7 @@ bwformat(BufferWriter , Spec const , IP6Addr const 
) {
 
 BufferWriter &
 bwformat(BufferWriter , Spec const , IPAddr const ) {
-  Spec local_spec{spec}; // Format for address elements and host_order_port.
+  Spec local_spec{spec}; // Format for address elements and port.
   bool addr_p{true};
   bool family_p{false};
 
diff --git a/code/src/swoc_ip.cc b/code/src/swoc_ip.cc
index 9dd7db6..bb4c394 100644
--- a/code/src/swoc_ip.cc
+++ b/code/src/swoc_ip.cc
@@ -124,7 +124,7 @@ IPEndpoint::tokenize(std::string_view str, std::string_view 
*addr, std::string_v
 // Exactly one colon - leave post colon stuff in @a src.
 *addr   = src.take_prefix(last);
 colon_p = true;
-  } else { // presume no host_order_port, use everything.
+  } else { // presume no port, use everything.
 *addr = src;
 src.clear();
   }



(trafficserver-libswoc) 02/03: Update to 1.0.10

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-10
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit bd4a0543614fd5549ad6d1bfe17f4259a1234ef4
Author: Alan M. Carroll 
AuthorDate: Thu Jan 30 12:46:55 2020 -0600

Update to 1.0.10
---
 doc/Doxyfile   | 2 +-
 doc/conf.py| 2 +-
 swoc++/CMakeLists.txt  | 2 +-
 swoc++/include/swoc/swoc_version.h | 2 +-
 swoc++/swoc++.part | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/doc/Doxyfile b/doc/Doxyfile
index f0e766d..53db8ab 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.0.9"
+PROJECT_NUMBER = "1.0.10"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/conf.py b/doc/conf.py
index 72bdcf6..f92efbe 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -80,7 +80,7 @@ project = u'Solid Wall Of C++'
 copyright = u'{}, a...@apache.org'.format(date.today().year)
 
 # The full version, including alpha/beta/rc tags.
-release = "1.0.9"
+release = "1.0.10"
 # The short X.Y version.
 version = '.'.join(release.split('.', 2)[:2])
 
diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index 81a2c9f..f8a86b3 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(lib-swoc++ CXX)
-set(LIBSWOC_VERSION "1.0.9")
+set(LIBSWOC_VERSION "1.0.10")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/swoc++/include/swoc/swoc_version.h 
b/swoc++/include/swoc/swoc_version.h
index b3f9963..62b5fef 100644
--- a/swoc++/include/swoc/swoc_version.h
+++ b/swoc++/include/swoc/swoc_version.h
@@ -39,5 +39,5 @@ namespace swoc
 {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 0;
-static constexpr unsigned POINT_VERSION = 9;
+static constexpr unsigned POINT_VERSION = 10;
 } // namespace swoc
diff --git a/swoc++/swoc++.part b/swoc++/swoc++.part
index 8d34df8..14818d2 100644
--- a/swoc++/swoc++.part
+++ b/swoc++/swoc++.part
@@ -1,5 +1,5 @@
 Import("*")
-PartVersion("1.0.9")
+PartVersion("1.0.10")
 PartName("swoc++")
 
 files = [



(trafficserver-libswoc) 03/03: Fix BWF conflict between unsigned and in_addr_t. Be thorough about IP4 address stored in host order.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-10
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 9d62d2210a0919edfe7580d6439d470334dbe161
Author: Alan M. Carroll 
AuthorDate: Thu Jan 30 16:01:13 2020 -0600

Fix BWF conflict between unsigned and in_addr_t.
Be thorough about IP4 address stored in host order.
---
 swoc++/include/swoc/bwf_ip.h  |  6 +-
 swoc++/include/swoc/swoc_ip.h | 15 ---
 swoc++/src/bw_ip_format.cc|  6 +++---
 unit_tests/test_ip.cc | 27 +++
 4 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/swoc++/include/swoc/bwf_ip.h b/swoc++/include/swoc/bwf_ip.h
index be1fa46..2b19d7f 100644
--- a/swoc++/include/swoc/bwf_ip.h
+++ b/swoc++/include/swoc/bwf_ip.h
@@ -28,8 +28,8 @@ namespace swoc
 {
 // All of these expect the address to be in network order.
 BufferWriter (BufferWriter , bwf::Spec const , sockaddr const 
*addr);
-BufferWriter (BufferWriter , bwf::Spec const , in_addr_t addr);
 BufferWriter (BufferWriter , bwf::Spec const , in6_addr const 
);
+BufferWriter (BufferWriter , bwf::Spec const , IP4Addr const 
);
 BufferWriter (BufferWriter , bwf::Spec const , IPAddr const 
);
 BufferWriter (BufferWriter , bwf::Spec const , sockaddr const 
*addr);
 
@@ -38,8 +38,4 @@ bwformat(BufferWriter , bwf::Spec const , IPEndpoint 
const ) {
   return bwformat(w, spec, );
 }
 
-inline BufferWriter (BufferWriter , bwf::Spec const , IP4Addr 
const& addr) {
-  return bwformat(w, spec, addr.network_order());
-}
-
 } // namespace swoc
diff --git a/swoc++/include/swoc/swoc_ip.h b/swoc++/include/swoc/swoc_ip.h
index f440caa..66213cb 100644
--- a/swoc++/include/swoc/swoc_ip.h
+++ b/swoc++/include/swoc/swoc_ip.h
@@ -149,7 +149,7 @@ union IPEndpoint {
 };
 
 /** Storage for an IPv4 address.
-Stored in network order.
+Stored in host order.
  */
 class IP4Addr {
   using self_type = IP4Addr; ///< Self reference type.
@@ -185,6 +185,7 @@ public:
   sockaddr *fill(sockaddr_in *sa, in_port_t port = 0) const;
 
   in_addr_t network_order() const;
+  in_addr_t host_order() const;
 
   /** Parse @a text as IPv4 address.
   The address resulting from the parse is copied to this object if the 
conversion is successful,
@@ -210,13 +211,17 @@ public:
   /// Test for loopback
   bool is_loopback() const;
 
+  constexpr static in_addr_t reorder(in_addr_t src) {
+return ((src & 0xFF) << 24) | (((src >> 8) & 0xFF) << 16) | (((src >> 16) 
& 0xFF) << 8) | ((src >> 24) & 0xFF);
+  }
+
 protected:
   friend bool operator==(self_type const &, self_type const &);
   friend bool operator!=(self_type const &, self_type const &);
   friend bool operator<(self_type const &, self_type const &);
   friend bool operator<=(self_type const &, self_type const &);
 
-  in_addr_t _addr = INADDR_ANY;
+  in_addr_t _addr = INADDR_ANY; ///< Address in host order.
 };
 
 /** Storage for an IPv6 address.
@@ -1002,7 +1007,7 @@ IPEndpoint::host_order_port(sockaddr const *addr) {
 
 // --- IPAddr variants ---
 
-inline constexpr IP4Addr::IP4Addr(in_addr_t addr) : _addr(addr) {}
+inline constexpr IP4Addr::IP4Addr(in_addr_t addr) : _addr(reorder(addr)) {}
 
 inline IP4Addr::IP4Addr(std::string_view const& text) {
   if (! this->load(text)) {
@@ -1026,6 +1031,10 @@ inline in_addr_t IP4Addr::network_order() const {
   return htonl(_addr);
 }
 
+inline in_addr_t IP4Addr::host_order() const {
+  return _addr;
+}
+
 inline IP4Addr::operator in_addr_t() const {
   return this->network_order();
 }
diff --git a/swoc++/src/bw_ip_format.cc b/swoc++/src/bw_ip_format.cc
index 0cf041e..14f5c27 100644
--- a/swoc++/src/bw_ip_format.cc
+++ b/swoc++/src/bw_ip_format.cc
@@ -49,9 +49,9 @@ namespace swoc
 using bwf::Spec;
 
 BufferWriter &
-bwformat(BufferWriter , Spec const , in_addr_t addr)
+bwformat(BufferWriter , Spec const , IP4Addr const& addr)
 {
-  in_addr_t host { ntohl(addr) };
+  in_addr_t host = addr.host_order();
   Spec local_spec{spec}; // Format for address elements.
   bool align_p = false;
 
@@ -253,7 +253,7 @@ bwformat(BufferWriter , Spec const , sockaddr const 
*addr)
 bool bracket_p = false;
 switch (addr->sa_family) {
 case AF_INET:
-  bwformat(w, spec, reinterpret_cast(addr)->sin_addr.s_addr);
+  bwformat(w, spec, IP4Addr{reinterpret_cast(addr)->sin_addr.s_addr});
   break;
 case AF_INET6:
   if (port_p) {
diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc
index 7ad662a..285e13f 100644
--- a/unit_tests/test_ip.cc
+++ b/unit_tests/test_ip.cc
@@ -62,7 +62,6 @@ TEST_CASE("ink_inet", "[libswoc][ip]") {
   IP6Addr a6_1{"fe80:88b5:4a:20c:29ff:feae:5587:1c33"};
   IP6Addr a6_2{"fe80:88b5:4a:20c:29ff:feae:5587:1c34"};
   IP6Addr a6_3{"de80:88b5:4a:20c:29ff:feae:5587:1c35"};
-  IP6Addr a6_4{"fe80:88b5:4a:20c:29ff:feae:5587:1c34"};
 
   REQUIRE(a6_1 != a6_null);
   REQUIRE(a6_1 != a6_2);
@@ -73,9 +72,29 @@ TEST_CASE("ink_inet", 

(trafficserver-libswoc) 01/03: Fix unit test problems.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-10
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 73955d81f6d7a04a9cadda1958fb796254e0b4b0
Author: Alan M. Carroll 
AuthorDate: Thu Jan 30 12:45:03 2020 -0600

Fix unit test problems.
---
 swoc++/include/swoc/DiscreteRange.h | 2 +-
 unit_tests/ex_TextView.cc   | 4 ++--
 unit_tests/test_swoc_file.cc| 2 +-
 unit_tests/unit_tests.part  | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/swoc++/include/swoc/DiscreteRange.h 
b/swoc++/include/swoc/DiscreteRange.h
index 21d177e..6838b14 100644
--- a/swoc++/include/swoc/DiscreteRange.h
+++ b/swoc++/include/swoc/DiscreteRange.h
@@ -101,7 +101,7 @@ public:
   using metric_type = T;
   using Relation = DiscreteRangeRelation;
 
-  static constexpr self_type ALL{detail::minimum(), 
detail::maximum()};
+//  static constexpr self_type ALL{detail::minimum(), 
detail::maximum()};
 
   /** Default constructor.
   An empty range is constructed.
diff --git a/unit_tests/ex_TextView.cc b/unit_tests/ex_TextView.cc
index 0894a1e..b6b3b25 100644
--- a/unit_tests/ex_TextView.cc
+++ b/unit_tests/ex_TextView.cc
@@ -202,7 +202,7 @@ TEST_CASE("TextView Tokens", 
"[libswoc][example][textview][tokens]")
 
 TEST_CASE("TextView Lines", "[libswoc][example][textview][lines]")
 {
-  swoc::file::path path{"../doc/conf.py"};
+  swoc::file::path path{"doc/conf.py"};
   std::error_code ec;
 
   auto content   = swoc::file::load(path, ec);
@@ -240,7 +240,7 @@ TEST_CASE("TextView parsing", 
"[libswoc][example][text][parsing]") {
   swoc::IP4Addr addr;
 
   std::error_code ec;
-  auto data { swoc::file::load("../unit_tests/examples/resolver.txt"_tv, ec) };
+  auto data { swoc::file::load("unit_tests/examples/resolver.txt"_tv, ec) };
   REQUIRE(data.size() > 2); // if this fails, there's something wrong with the 
path or current directory.
 
   TextView content { data };
diff --git a/unit_tests/test_swoc_file.cc b/unit_tests/test_swoc_file.cc
index b60a616..a3f403c 100644
--- a/unit_tests/test_swoc_file.cc
+++ b/unit_tests/test_swoc_file.cc
@@ -47,7 +47,7 @@ TEST_CASE("swoc_file", "[libts][swoc_file]")
 
 TEST_CASE("swoc_file_io", "[libts][swoc_file_io]")
 {
-  path file("../unit_tests/test_swoc_file.cc");
+  path file("unit_tests/test_swoc_file.cc");
   std::error_code ec;
   std::string content = swoc::file::load(file, ec);
   REQUIRE(ec.value() == 0);
diff --git a/unit_tests/unit_tests.part b/unit_tests/unit_tests.part
index 8f9b304..fd2115e 100644
--- a/unit_tests/unit_tests.part
+++ b/unit_tests/unit_tests.part
@@ -7,7 +7,7 @@ DependsOn([
 ])
 
 env.AppendUnique(
-CCFLAGS=['-std=c++17'],
+CCFLAGS=['-std=c++17'],
 )
 
 files = [
@@ -35,6 +35,6 @@ env.UnitTest(
 "tests",
 files,
 # data file we need for the test to pass
-
data_src=[Pattern(src_dir="#",includes=['doc/conf.py','unit_tests/test_swoc_file.cc'])]
+
data_src=[Pattern(src_dir="#",includes=['doc/conf.py','unit_tests/examples/resolver.txt',
 'unit_tests/test_swoc_file.cc'])]
 )
 



(trafficserver-libswoc) branch dev-1-0-10 created (now 9d62d22)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-0-10
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 9d62d22  Fix BWF conflict between unsigned and in_addr_t. Be thorough 
about IP4 address stored in host order.

This branch includes the following new commits:

 new 73955d8  Fix unit test problems.
 new bd4a054  Update to 1.0.10
 new 9d62d22  Fix BWF conflict between unsigned and in_addr_t. Be thorough 
about IP4 address stored in host order.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 04/04: Lexicon: Documentation and examples. Doxygen: Fixed problem with inline namespace.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch doc-lexicon
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit ce6fe32d7b2011be69fc07553e3f10c086a05417
Author: Alan M. Carroll 
AuthorDate: Mon May 25 09:47:56 2020 -0500

Lexicon: Documentation and examples.
Doxygen: Fixed problem with inline namespace.
---
 doc/Doxyfile   |  2 +-
 doc/code/Lexicon.en.rst| 54 
 doc/code/TextView.en.rst   |  9 --
 doc/namespace-filter.sh|  3 ++
 tools/update-version.sh|  2 +-
 unit_tests/ex_Lexicon.cc   | 68 --
 unit_tests/test_Lexicon.cc |  2 +-
 7 files changed, 126 insertions(+), 14 deletions(-)

diff --git a/doc/Doxyfile b/doc/Doxyfile
index 0ad9afb..6e3048d 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -912,7 +912,7 @@ IMAGE_PATH =
 # need to set EXTENSION_MAPPING for the extension otherwise the files are not
 # properly processed by doxygen.
 
-INPUT_FILTER   =
+INPUT_FILTER   = ./namespace-filter.sh
 
 # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
 # basis. Doxygen will compare the file name with each pattern and apply the
diff --git a/doc/code/Lexicon.en.rst b/doc/code/Lexicon.en.rst
index b960d04..64468b5 100644
--- a/doc/code/Lexicon.en.rst
+++ b/doc/code/Lexicon.en.rst
@@ -106,6 +106,12 @@ The file loading and parsing is then:
:start-after: doc.load.begin
:end-before: doc.load.end
 
+with the simulated file contents
+
+.. literalinclude:: ../../unit_tests/ex_Lexicon.cc
+   :start-after: doc.file.begin
+   :end-before: doc.file.end
+
 This uses the Lexicon to convert the strings in the file to the enumeration 
values, which are the
 bitset indices. The defalt is set to ``INVALID`` so that any string that 
doesn't match a string
 in the Lexicon is mapped to ``INVALID``.
@@ -121,6 +127,54 @@ can be accessed like ::
 
if (flags[NetType::PROD]) { ... }
 
+Constructing
+
+
+To make the class more flexible it can be constructed in a variety of ways. 
For static the entire
+class can be initialized in the constructor. For dynamic use any subset can be 
initialized. In
+the previous example, the instance was initialized with all of the defined 
values and a default
+for missing names. Because this fully constructs it, it can be marked 
``const`` to prevent
+accidental changes. It could also have been constructed with a default name:
+
+.. literalinclude:: ../../unit_tests/ex_Lexicon.cc
+   :start-after: doc.ctor.1.begin
+   :end-before: doc.ctor.1.end
+
+Note the default name was put before the default value. Because they are 
distinct types, the
+defaults can be added in either order, but must always follow the field 
defintions. The defaults can
+also be omitted entirely, which is common if the Lexicon is used for output 
and not parsing, where
+the enumeration is always valid because all enumeration values are in the 
Lexicon.
+
+.. literalinclude:: ../../unit_tests/ex_Lexicon.cc
+   :start-after: doc.ctor.2.begin
+   :end-before: doc.ctor.2.end
+
+For dynamic use, it is common to have just the defaults, and not any of the 
fields, although of course
+if some "built in" names and values are needed those can be added as in the 
previous examples.
+
+.. literalinclude:: ../../unit_tests/ex_Lexicon.cc
+   :start-after: doc.ctor.3.begin
+   :end-before: doc.ctor.3.end
+
+As before both, either, or none of the defaults are required.
+
+Finally, here is a example of using Lexicon to translate a boolean value, 
allowing for various alternative
+forms for the true and false names.
+
+.. literalinclude:: ../../unit_tests/ex_Lexicon.cc
+   :start-after: doc.ctor.4.begin
+   :end-before: doc.ctor.4.end
+
+The set of value names is easily changed. The ``BoolTag`` type is used to be 
able to indicate when a
+name doesn't match anything in the Lexicon. Each field is a value and then a 
list of names, instead
+of just the pair of a value and name as in the previous examples. If a 
``BoolTag`` was passed in to
+the Lexicon, it would return "true", "false", or throw an exception for 
``BoolTag::INVALID`` because
+that value is missing and there is no default name. The strings returned are 
returned because they
+are the first elements in the list of names. This is fine for any debugging or 
diagnostic messages
+because only the ``true`` and ``false`` values would be stored, ``INVALID`` 
indicates a parsing
+error. The enumeration values were chosen so casting from ``bool`` to 
``BoolTag`` yields the
+appropriate string.
+
 Design Notes
 
 
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 63cd632..4b9963e 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -240,9 +240,12 @@ similar suffixes with the same meaning as the affix 
methods. This can be done fo
 character, one of a set of characters, or a 

(trafficserver-libswoc) 03/04: Lexicon: Doc updates and example.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch doc-lexicon
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 4f8e916f3200252d6a50e7c399d6097b798bfcf4
Author: Alan M. Carroll 
AuthorDate: Fri May 22 10:22:46 2020 -0500

Lexicon: Doc updates and example.
---
 doc/Doxyfile  |  17 +---
 doc/code/BW_Format.en.rst |   2 +-
 doc/code/IPSpace.en.rst   |   2 +
 doc/code/Lexicon.en.rst   |  78 +++
 unit_tests/ex_Lexicon.cc  | 250 +-
 5 files changed, 150 insertions(+), 199 deletions(-)

diff --git a/doc/Doxyfile b/doc/Doxyfile
index f17a3e9..0ad9afb 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -790,7 +790,7 @@ WARN_LOGFILE   =
 # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
 # Note: If this tag is empty the current directory is searched.
 
-INPUT  = "../swoc++/src" "../swoc++/include/swoc"
+INPUT  = "../code/src" "../code/include/swoc"
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
@@ -2109,12 +2109,6 @@ EXTERNAL_GROUPS= YES
 
 EXTERNAL_PAGES = YES
 
-# The PERL_PATH should be the absolute path and name of the perl script
-# interpreter (i.e. the result of 'which perl').
-# The default file (with absolute path) is: /usr/bin/perl.
-
-PERL_PATH  = /usr/bin/perl
-
 #---
 # Configuration options related to the dot tool
 #---
@@ -2128,15 +2122,6 @@ PERL_PATH  = /usr/bin/perl
 
 CLASS_DIAGRAMS = YES
 
-# You can define message sequence charts within doxygen comments using the \msc
-# command. Doxygen will then run the mscgen tool (see:
-# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the
-# documentation. The MSCGEN_PATH tag allows you to specify the directory where
-# the mscgen tool resides. If left empty the tool is assumed to be found in the
-# default search path.
-
-MSCGEN_PATH=
-
 # You can include diagrams made with dia in doxygen documentation. Doxygen will
 # then run dia to produce the diagram and insert it in the documentation. The
 # DIA_PATH tag allows you to specify the directory where the dia binary 
resides.
diff --git a/doc/code/BW_Format.en.rst b/doc/code/BW_Format.en.rst
index 1f7bbf0..67218ed 100644
--- a/doc/code/BW_Format.en.rst
+++ b/doc/code/BW_Format.en.rst
@@ -347,7 +347,7 @@ width ` in order to disable any framework 
alignment operation.
 It is important to note a formatter can call another formatter. For example, 
the formatter for
 :code:`std::string` looks like
 
-.. literalinclude:: ../../swoc++/include/swoc/bwf_base.h
+.. literalinclude:: ../../code/include/swoc/bwf_base.h
:lines: 811-833
 
 The code first copies the format specification and forces a leading radix. 
Next it does special
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index 9d3e318..ae301a5 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -83,6 +83,8 @@ properly formatted, otherwise the range will be default 
constructed to an invali
 also the :libswoc:`swoc::IPRange::load` method which returns a :code:`bool` to 
indicate if the
 parsing was successful.
 
+.. _ip-space:
+
 IPSpace
 ===
 
diff --git a/doc/code/Lexicon.en.rst b/doc/code/Lexicon.en.rst
index a554a2d..b960d04 100644
--- a/doc/code/Lexicon.en.rst
+++ b/doc/code/Lexicon.en.rst
@@ -44,11 +44,89 @@ Usage
 Lexicons can be used in a dynamic or static fashion. The basic use is as a 
static translation object
 that converts between an enumeration and names. The constructors allow setting 
up the entire Lexicon.
 
+The primary things to set up for a Lexicon are
+
+*  The equivalence of names and values.
+*  The default (if any) for a name.
+*  The default (if any) for a value.
+
+Values and names can be associated either using pairs of values and names, or 
a pair of a value
+and a list of names, the first of which is the primary name. This must be 
consistent for all of
+the defined values, so if one value has multiple names, all names must use the 
value, name list form.
+
+In addition, defaults can be specified. Because all possible defaults have 
distinct signatures
+there is no need to order them - the constructor can deduce what is meant. 
Defaults are very handy
+when using a Lexicon for parsing - the default value can be an invalid value, 
in which case checking
+an input token for being a valid name is very simple ::
+
+   extern swoc::Lexicon lex; // Initialized elsewhere.
+   auto value = lex[token];
+   if (value != INVALID) { // handle successful parse }
+
+Lexicon can also be used dynamically where the contents are built up over time 
or due to run time
+inputs. 

(trafficserver-libswoc) 02/04: CMake: load on Win32.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch doc-lexicon
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 0472985c417790f4e3aa903d2b4396a0cedbeccb
Author: Alan M. Carroll 
AuthorDate: Tue May 19 12:28:06 2020 -0500

CMake: load on Win32.
---
 code/CMakeLists.txt   |   4 +-
 example/CMakeLists.txt|   9 ++-
 unit_tests/CMakeLists.txt |   4 +-
 unit_tests/ex_Lexicon.cc  | 200 ++
 4 files changed, 213 insertions(+), 4 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index 60a3916..2220c81 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -45,7 +45,9 @@ set(CC_FILES
 )
 
 add_library(libswoc STATIC ${CC_FILES})
-target_compile_options(libswoc PRIVATE -Wall -Wextra -Werror 
-Wnon-virtual-dtor -Wpedantic)
+if (CMAKE_COMPILER_IS_GNUCXX)
+target_compile_options(libswoc PRIVATE -Wall -Wextra -Werror 
-Wnon-virtual-dtor -Wpedantic)
+endif()
 
 # Not quite sure how this works, but I think it generates one of two paths 
depending on the context.
 # That is, the generator functions return non-empty stri ngs only in the 
corresponding context.
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 4150aa5..c29ac05 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -5,8 +5,13 @@ set(CMAKE_CXX_STANDARD 17)
 add_executable(ex_netdb ex_netdb.cc)
 target_link_libraries(ex_netdb PUBLIC libswoc)
 set_target_properties(ex_netdb PROPERTIES CLANG_FORMAT_DIRS 
${CMAKE_CURRENT_SOURCE_DIR})
-target_compile_options(ex_netdb PRIVATE -Wall -Wextra -Werror)
+
+if (CMAKE_COMPILER_IS_GNUCXX)
+target_compile_options(ex_netdb PRIVATE -Wall -Wextra -Werror)
+endif()
 
 add_executable(ex_netcompact ex_netcompact.cc)
 target_link_libraries(ex_netcompact PUBLIC libswoc)
-target_compile_options(ex_netcompact PRIVATE -Wall -Wextra -Werror)
+if (CMAKE_COMPILER_IS_GNUCXX)
+target_compile_options(ex_netcompact PRIVATE -Wall -Wextra -Werror)
+endif()
diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt
index a4295be..56d6fed 100644
--- a/unit_tests/CMakeLists.txt
+++ b/unit_tests/CMakeLists.txt
@@ -29,5 +29,7 @@ add_executable(test_libswoc
 
 target_link_libraries(test_libswoc PUBLIC libswoc)
 set_target_properties(test_libswoc PROPERTIES CLANG_FORMAT_DIRS 
${CMAKE_CURRENT_SOURCE_DIR})
-target_compile_options(test_libswoc PRIVATE -Wall -Wextra -Werror 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
+if (CMAKE_COMPILER_IS_GNUCXX)
+target_compile_options(test_libswoc PRIVATE -Wall -Wextra -Werror 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
+endif()
 #add_definitions(-DVERBOSE_EXAMPLE_OUTPUT=1)
diff --git a/unit_tests/ex_Lexicon.cc b/unit_tests/ex_Lexicon.cc
new file mode 100644
index 000..e2df5cc
--- /dev/null
+++ b/unit_tests/ex_Lexicon.cc
@@ -0,0 +1,200 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright Verizon Media 2020
+/** @file
+
+Lexicon unit tests.
+*/
+
+#include "swoc/Lexicon.h"
+#include "catch.hpp"
+
+// Example code for documentatoin
+// ---
+
+enum class Example { INVALID, Value_0, Value_1, Value_2, Value_3 };
+
+using ExampleNames = swoc::Lexicon;
+
+namespace
+{
+[[maybe_unused]] ExampleNames Static_Names {
+  {Example::Value_0, {"zero", "0"}}, {Example::Value_1, {"one", "1"}}, 
{Example::Value_2, {"two", "2"}},
+{Example::Value_3, {"three", "3"}},
+  {
+Example::INVALID, { "INVALID" }
+  }
+};
+}
+
+TEST_CASE("Lexicon Example", "[libts][Lexicon]")
+{
+  ExampleNames exnames{{Example::Value_0, {"zero", "0"}},
+   {Example::Value_1, {"one", "1"}},
+   {Example::Value_2, {"two", "2"}},
+   {Example::Value_3, {"three", "3"}},
+   {Example::INVALID, {"INVALID"}}};
+
+  ExampleNames exnames2{{Example::Value_0, "zero"},
+{Example::Value_1, "one"},
+{Example::Value_2, "two"},
+{Example::Value_3, "three"},
+{Example::INVALID, "INVALID"}};
+
+  // Check constructing with just defaults.
+  ExampleNames def_names_1 { Example::INVALID };
+  ExampleNames def_names_2 { "INVALID" };
+  ExampleNames def_names_3 { Example::INVALID, "INVALID" };
+
+  exnames.set_default(Example::INVALID).set_default("INVALID");
+
+  REQUIRE(exnames[Example::INVALID] == "INVALID");
+  REQUIRE(exnames[Example::Value_0] == "zero");
+  REQUIRE(exnames["zero"] == Example::Value_0);
+  REQUIRE(exnames["Zero"] == Example::Value_0);
+  REQUIRE(exnames["ZERO"] == Example::Value_0);
+  REQUIRE(exnames["one"] == Example::Value_1);
+  REQUIRE(exnames["1"] == Example::Value_1);
+  REQUIRE(exnames["Evil Dave"] == Example::INVALID);
+  REQUIRE(exnames[static_cast(0xBADD00D)] == "INVALID");
+  REQUIRE(exnames[exnames[static_cast(0xBADD00D)]] == 

(trafficserver-libswoc) 01/04: Initial pass.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch doc-lexicon
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit b69ecd7506ce95845b1de91d2d29d59380475e8d
Author: Alan M. Carroll 
AuthorDate: Tue May 19 10:42:15 2020 -0500

Initial pass.
---
 code/CMakeLists.txt   |  2 +-
 doc/code/Lexicon.en.rst   | 12 +++-
 unit_tests/CMakeLists.txt |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index e4608df..60a3916 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -48,7 +48,7 @@ add_library(libswoc STATIC ${CC_FILES})
 target_compile_options(libswoc PRIVATE -Wall -Wextra -Werror 
-Wnon-virtual-dtor -Wpedantic)
 
 # Not quite sure how this works, but I think it generates one of two paths 
depending on the context.
-# That is, the generator functions return non-empty strings only in the 
corresponding context.
+# That is, the generator functions return non-empty stri ngs only in the 
corresponding context.
 target_include_directories(libswoc
 PUBLIC
 $
diff --git a/doc/code/Lexicon.en.rst b/doc/code/Lexicon.en.rst
index 6fcea5b..a554a2d 100644
--- a/doc/code/Lexicon.en.rst
+++ b/doc/code/Lexicon.en.rst
@@ -23,7 +23,13 @@ Lexicon
 
 
 |Lexicon| is a bidirectional mapping between strings and a numeric / 
enumeration type. It is intended
-to support parsing and diagnostics for enumerations.
+to support parsing and diagnostics for enumerations. It has some significant 
advantages over a simple
+array of strings.
+
+*  The integer can be looked up by string. This makes parsing much easier and 
more robust.
+*  The integers do not have to be contiguous or zero based.
+*  Multiple names can map to the same integer.
+*  Defaults for missing names or integers.
 
 Definition
 **
@@ -35,10 +41,14 @@ Definition
 Usage
 *
 
+Lexicons can be used in a dynamic or static fashion. The basic use is as a 
static translation object
+that converts between an enumeration and names. The constructors allow setting 
up the entire Lexicon.
 
 Examples
 
 
+
+
 Design Notes
 
 
diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt
index e71c71e..a4295be 100644
--- a/unit_tests/CMakeLists.txt
+++ b/unit_tests/CMakeLists.txt
@@ -22,6 +22,7 @@ add_executable(test_libswoc
 ex_bw_format.cc
 ex_IntrusiveDList.cc
 ex_ipspace_properties.cc
+ex_Lexicon.cc
 ex_MemArena.cc
 ex_TextView.cc
 )



(trafficserver-libswoc) 06/09: Fix return value from IP6Addr::operator=().

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 668e55ab470a569cc0501877e0bf6b876b3b4979
Author: Alan M. Carroll 
AuthorDate: Mon Jun 22 14:47:51 2020 -0500

Fix return value from IP6Addr::operator=().
---
 code/include/swoc/swoc_ip.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/code/include/swoc/swoc_ip.h b/code/include/swoc/swoc_ip.h
index 4398dd6..5affe96 100644
--- a/code/include/swoc/swoc_ip.h
+++ b/code/include/swoc/swoc_ip.h
@@ -2211,9 +2211,11 @@ inline auto IP6Addr::operator=(in6_addr const& addr) -> 
self_type& {
 
 inline auto IP6Addr::operator=(sockaddr_in6 const *addr) -> self_type& {
   if (addr) {
-return *this = addr->sin6_addr;
+*this = addr->sin6_addr;
+  } else {
+this->clear();
   }
-  this->clear();
+  return *this;
 }
 
 inline IP6Addr&



(trafficserver-libswoc) branch doc-lexicon created (now ce6fe32)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch doc-lexicon
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at ce6fe32  Lexicon: Documentation and examples. Doxygen: Fixed problem 
with inline namespace.

This branch includes the following new commits:

 new b69ecd7  Initial pass.
 new 0472985  CMake: load on Win32.
 new 4f8e916  Lexicon: Doc updates and example.
 new ce6fe32  Lexicon: Documentation and examples. Doxygen: Fixed problem 
with inline namespace.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 05/09: Fix override of operator delete and constructor for MemArena::Block.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 9d8f6f5338544d7810648e1029c485c3bed4985a
Author: Alan M. Carroll 
AuthorDate: Fri Jun 19 12:32:39 2020 -0500

Fix override of operator delete and constructor for MemArena::Block.
---
 code/include/swoc/MemArena.h | 38 ++
 code/src/MemArena.cc |  5 -
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/code/include/swoc/MemArena.h b/code/include/swoc/MemArena.h
index 36cf131..2bdaf68 100644
--- a/code/include/swoc/MemArena.h
+++ b/code/include/swoc/MemArena.h
@@ -72,17 +72,36 @@ public:
 /// @return @c true if the block has at least @c MIN_FREE_SPACE bytes free.
 bool is_full() const;
 
-/** Override standard delete.
+
+  protected:
+friend MemArena;
+
+/** Override @c operator @c delete.
  *
- * This is required because the allocated memory size is larger than the 
class size which requires
- * calling @c free differently.
+ * This is required because the allocated memory size is larger than the 
class size which
+ * requires calling @c free directly, skipping the destructor and avoiding 
complaints about size
+ * mismatches.
  *
  * @param ptr Memory to be de-allocated.
  */
-static void operator delete(void *ptr);
+static void operator delete(void * ptr) noexcept;
 
-  protected:
-friend MemArena;
+/** Override placement (non-allocated) @c delete.
+ *
+ * @param ptr Pointer returned from @c new
+ * @param place Value passed to @c new.
+ *
+ * This is called only when the class constructor throws an exception 
during placement new.
+ *
+ * @note I think the parameters are described correctly, the documentation 
I can find is a bit
+ * vague on the source of these values. It is required even if the 
constructor is marked @c
+ * noexcept. Both are kept in order to be documented.
+ *
+ * @internal This is required by ICC, but not GCC. Annoying, but it 
appears this is a valid
+ * interpretation of the spec. In practice this is never called because 
the constructor does
+ * not throw.
+ */
+static void operator delete([[maybe_unused]] void * ptr, void * place) 
noexcept;
 
 /** Construct to have @a n bytes of available storage.
  *
@@ -90,7 +109,7 @@ public:
  * memory already allocated immediately after this instance.
  * @param n The amount of storage.
  */
-explicit Block(size_t n);
+explicit Block(size_t n) noexcept;
 
 size_t size; ///< Actual block size.
 size_t allocated{0}; ///< Current allocated (in use) bytes.
@@ -389,7 +408,7 @@ inline auto MemArena::Block::Linkage::prev_ptr(Block *b) -> 
Block *& {
   return b->_link._prev;
 }
 
-inline MemArena::Block::Block(size_t n) : size(n) {}
+inline MemArena::Block::Block(size_t n) noexcept : size(n) {}
 
 inline char *MemArena::Block::data() {
   return reinterpret_cast(this + 1);
@@ -441,6 +460,9 @@ inline MemArena::Block& MemArena::Block::discard() {
   return *this;
 }
 
+inline void MemArena::Block::operator delete(void *ptr) noexcept { 
::free(ptr); }
+inline void MemArena::Block::operator delete([[maybe_unused]] void * ptr, void 
* place) noexcept { ::free(place); }
+
 inline size_t MemArena::size() const {
   return _active_allocated;
 }
diff --git a/code/src/MemArena.cc b/code/src/MemArena.cc
index f5a3e77..fe22823 100644
--- a/code/src/MemArena.cc
+++ b/code/src/MemArena.cc
@@ -10,11 +10,6 @@
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 
-void
-MemArena::Block::operator delete(void *ptr) {
-  ::free(ptr);
-}
-
 // Need to break these out because the default implementation doesn't clear the
 // integral values in @a that.
 



(trafficserver-libswoc) branch dev-1-2-7 created (now 4b4910c)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 4b4910c  IPSpace: add check to lower_bound to check if target is past 
the end and immediately return.

This branch includes the following new commits:

 new ba76283  Fix missing "std" for "nullptr_t".
 new 6014f24  Add MemArena::alloc_span.
 new eab3031  Update to version 1.2.7
 new 2cfa8fc  Fix ICC template default argument access bug for 
Errata::Annotation.
 new 9d8f6f5  Fix override of operator delete and constructor for 
MemArena::Block.
 new 668e55a  Fix return value from IP6Addr::operator=().
 new 7b97bcf  Change IPEndpoint::port to throw instead of returning a 
reference to nullptr.
 new 18bf42e  Fix sign change in shift for 
IP4Range::NetSource::search_narrower.
 new 4b4910c  IPSpace: add check to lower_bound to check if target is past 
the end and immediately return.

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 07/09: Change IPEndpoint::port to throw instead of returning a reference to nullptr.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 7b97bcf66f28a78dcac44eb1b6f63891db71b072
Author: Alan M. Carroll 
AuthorDate: Mon Jun 22 14:50:09 2020 -0500

Change IPEndpoint::port to throw instead of returning a reference to 
nullptr.
---
 code/include/swoc/swoc_ip.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/code/include/swoc/swoc_ip.h b/code/include/swoc/swoc_ip.h
index 5affe96..79dcd36 100644
--- a/code/include/swoc/swoc_ip.h
+++ b/code/include/swoc/swoc_ip.h
@@ -2069,7 +2069,7 @@ IPEndpoint::port(sockaddr *sa) {
 case AF_INET6:return reinterpret_cast(sa)->sin6_port;
   }
   // Force a failure upstream by returning a null reference.
-  return *static_cast(nullptr);
+  throw std::domain_error("sockaddr is not a valid IP address");
 }
 
 inline in_port_t



(trafficserver-libswoc) 04/09: Fix ICC template default argument access bug for Errata::Annotation.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 2cfa8fc48ce03cfb5aea9e7c16296c25676b128c
Author: Alan M. Carroll 
AuthorDate: Fri Jun 19 12:30:00 2020 -0500

Fix ICC template default argument access bug for Errata::Annotation.
---
 code/include/swoc/Errata.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/code/include/swoc/Errata.h b/code/include/swoc/Errata.h
index 8fd720a..c432cc7 100644
--- a/code/include/swoc/Errata.h
+++ b/code/include/swoc/Errata.h
@@ -114,7 +114,10 @@ public:
 self_type *_prev{nullptr};
 /// @}}
 /// Intrusive list link descriptor.
-using Linkage = IntrusiveLinkage;
+/// @note Must explicitly use defaults because ICC and clang consider them 
inaccessible
+/// otherwise. I consider it a bug in the compiler that a default 
identical to an explicit
+/// value has different behavior.
+using Linkage = swoc::IntrusiveLinkage;
 
 friend class Errata;
   };



(trafficserver-libswoc) 09/09: IPSpace: add check to lower_bound to check if target is past the end and immediately return.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 4b4910c463edf29d1b03a3600036b0468a46ae17
Author: Alan M. Carroll 
AuthorDate: Tue Jun 23 06:54:57 2020 -0500

IPSpace: add check to lower_bound to check if target is past the end and 
immediately return.
---
 code/include/swoc/DiscreteRange.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/code/include/swoc/DiscreteRange.h 
b/code/include/swoc/DiscreteRange.h
index 280e836..eba8bed 100644
--- a/code/include/swoc/DiscreteRange.h
+++ b/code/include/swoc/DiscreteRange.h
@@ -912,6 +912,12 @@ template
 auto DiscreteSpace::lower_bound(METRIC const& target) -> Node 
* {
   Node *n = _root;   // current node to test.
   Node *zret = nullptr; // best node so far.
+
+  // Fast check for sequential insertion
+  if (auto ln = _list.tail() ; ln != nullptr && ln->max() < target) {
+return ln;
+  }
+
   while (n) {
 if (target < n->min()) {
   n = left(n);



(trafficserver-libswoc) 08/09: Fix sign change in shift for IP4Range::NetSource::search_narrower.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 18bf42e9d8cbe1f602db8a2670addac49dd17ffb
Author: Alan M. Carroll 
AuthorDate: Mon Jun 22 14:53:05 2020 -0500

Fix sign change in shift for IP4Range::NetSource::search_narrower.
---
 code/src/swoc_ip.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/code/src/swoc_ip.cc b/code/src/swoc_ip.cc
index e708ff5..e9d0dc5 100644
--- a/code/src/swoc_ip.cc
+++ b/code/src/swoc_ip.cc
@@ -810,7 +810,7 @@ void IP4Range::NetSource::search_wider() {
 void IP4Range::NetSource::search_narrower() {
   while (!this->is_valid(_mask)) {
 _mask._addr >>= 1;
-_mask._addr |= 1 << (IP4Addr::WIDTH - 1); // put top bit back.
+_mask._addr |= 1U << (IP4Addr::WIDTH - 1); // put top bit back.
 ++_cidr;
   }
 }



(trafficserver-libswoc) 01/09: Fix missing "std" for "nullptr_t".

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit ba762836f902bee8c4bfb8ccc59bc8fd6fef5f6f
Author: Alan M. Carroll 
AuthorDate: Fri Jun 19 11:19:15 2020 -0500

Fix missing "std" for "nullptr_t".
---
 code/include/swoc/IntrusiveDList.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/code/include/swoc/IntrusiveDList.h 
b/code/include/swoc/IntrusiveDList.h
index 1204f67..fa0bb10 100644
--- a/code/include/swoc/IntrusiveDList.h
+++ b/code/include/swoc/IntrusiveDList.h
@@ -77,8 +77,10 @@ public:
   // Get the result of calling the pointer access function, then strip off 
reference and pointer
   // qualifiers. @c nullptr is used instead of the pointer type because this 
is done precisely
   // to find that type.
-  using value_type = typename std::remove_pointer<
-  typename std::remove_reference::type>::type>::type;
+  using value_type =
+  typename std::remove_pointer<
+typename std::remove_reference<
+  typename std::invoke_result::type>::type>::type;
 
   /// Const iterator.
   class const_iterator {



(trafficserver-libswoc) 03/09: Update to version 1.2.7

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit eab30313cc6d42bd93bb054f2afab371d4aa9fe1
Author: Alan M. Carroll 
AuthorDate: Fri Jun 19 12:24:52 2020 -0500

Update to version 1.2.7
---
 code/CMakeLists.txt  | 2 +-
 code/include/swoc/swoc_version.h | 4 ++--
 code/libswoc.part| 2 +-
 doc/Doxyfile | 2 +-
 doc/code/IPSpace.en.rst  | 2 +-
 doc/code/TextView.en.rst | 6 +++---
 doc/conf.py  | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index bcea319..9db9fb3 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(Lib-SWOC CXX)
-set(LIBSWOC_VERSION "1.2.6")
+set(LIBSWOC_VERSION "1.2.7")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/code/include/swoc/swoc_version.h b/code/include/swoc/swoc_version.h
index b403f08..4958554 100644
--- a/code/include/swoc/swoc_version.h
+++ b/code/include/swoc/swoc_version.h
@@ -22,11 +22,11 @@
 #pragma once
 
 #if !defined(SWOC_VERSION_NS)
-#  define SWOC_VERSION_NS _1_2_6
+#  define SWOC_VERSION_NS _1_2_7
 #endif
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 2;
-static constexpr unsigned POINT_VERSION = 6;
+static constexpr unsigned POINT_VERSION = 7;
 }} // namespace SWOC_VERSION_NS
diff --git a/code/libswoc.part b/code/libswoc.part
index 1556dee..db48ec8 100644
--- a/code/libswoc.part
+++ b/code/libswoc.part
@@ -1,6 +1,6 @@
 Import("*")
 PartName("libswoc")
-PartVersion("1.2.6")
+PartVersion("1.2.7")
 
 src_files = [
 "src/ArenaWriter.cc",
diff --git a/doc/Doxyfile b/doc/Doxyfile
index b6e1918..1cb4bfc 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.2.6"
+PROJECT_NUMBER = "1.2.7"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index ddd8855..9f0d7a9 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -172,7 +172,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 604e7e6..7bbce4c 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -278,7 +278,7 @@ separated by commas.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 If :arg:`value` was :literal:`bob  ,dave, sam` then :arg:`token` would be 
successively
 :literal:`bob`, :literal:`dave`, :literal:`sam`. After :literal:`sam` was 
extracted :arg:`value`
@@ -300,7 +300,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, with each 
element being treated as
 a "list" with ``=`` as the separator. Note if there is no ``=`` character then 
all of the list
@@ -351,7 +351,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/conf.py b/doc/conf.py
index e35b053..5bd7eb7 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -80,7 +80,7 

(trafficserver-libswoc) 02/09: Add MemArena::alloc_span.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 6014f24c407ef19e729e652e93fd045730f862f9
Author: Alan M. Carroll 
AuthorDate: Fri Jun 19 11:19:37 2020 -0500

Add MemArena::alloc_span.
---
 code/include/swoc/MemArena.h | 23 +--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/code/include/swoc/MemArena.h b/code/include/swoc/MemArena.h
index 289d2fe..36cf131 100644
--- a/code/include/swoc/MemArena.h
+++ b/code/include/swoc/MemArena.h
@@ -169,14 +169,28 @@ public:
*/
   MemSpan alloc(size_t n);
 
-  /** Allocate and initialize a block of memory.
+  /** ALlocate a span of memory sufficient for @a n instance of @a T.
+   *
+   * @tparam T Element type.
+   * @param n Number of instances.
+   * @return A span large enough to hold @a n instances of @a T.
+   *
+   * The instances are @b not initialized / constructed. This only allocates 
the memory.
+   * This is handy for types that don't need initialization, such as built in 
types like @c int.
+   * @code
+   *   auto vec = arena.alloc_span(20); // allocate space for 20 ints
+   * @endcode
+   */
+  template  MemSpan alloc_span(size_t n);
+
+  /** Allocate and initialize a block of memory as an instance of @a T
 
   The template type specifies the type to create and any arguments are 
forwarded to the
   constructor. Example:
 
   @code
   struct Thing { ... };
-  Thing* thing = arena.make(...constructor args...);
+  auto thing = arena.make(...constructor args...);
   @endcode
 
   Do @b not call @c delete an object created this way - that will attempt 
to free the memory and
@@ -407,6 +421,11 @@ inline MemSpan MemArena::Block::alloc(size_t n) {
   return zret;
 }
 
+template
+MemSpan MemArena::alloc_span(size_t n) {
+  return this->alloc(sizeof(T) * n).rebind();
+}
+
 template T *MemArena::make(Args&& ... args) {
   return new(this->alloc(sizeof(T)).data()) T(std::forward(args)...);
 }



(trafficserver-libswoc) branch mem-align created (now 1412f29)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch mem-align
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 1412f29  Add alignment support to MemSpan, MemArena.

This branch includes the following new commits:

 new 1412f29  Add alignment support to MemSpan, MemArena.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 01/01: Add alignment support to MemSpan, MemArena.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch mem-align
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 1412f2992af1dc462164343de5d4ea0569e79079
Author: Alan M. Carroll 
AuthorDate: Tue Jun 21 13:53:51 2022 -0500

Add alignment support to MemSpan, MemArena.
---
 code/include/swoc/MemArena.h | 84 +++-
 code/include/swoc/MemSpan.h  | 40 ++---
 code/include/swoc/Vectray.h  |  2 +-
 unit_tests/test_MemSpan.cc   | 15 
 4 files changed, 119 insertions(+), 22 deletions(-)

diff --git a/code/include/swoc/MemArena.h b/code/include/swoc/MemArena.h
index 0800d3e..ab7a39e 100644
--- a/code/include/swoc/MemArena.h
+++ b/code/include/swoc/MemArena.h
@@ -310,9 +310,44 @@ public:
   /// @return The amount of free space.
   size_t remaining() const;
 
+  /** Get aligned and sized remnant.
+   *
+   * @tparam T Element type.
+   * @param n Number of instances of @a T
+   * @return A span that is in the remnant, correctly aligned with minimal 
padding.
+   *
+   * This is guaranteed to be the same bytes as if @c alloc was called. The 
returned span will
+   * always be the specified size, the remnant will be expanded as needed.
+   */
+  template  MemSpan remnant_span(size_t n);
+
+  /** Get remnant memory.
+   *
+   * @param n Memory size in bytes.
+   * @return The remnant memory.
+   *
+   * This differs from  similar methods in that
+   * - the memory is not aligned
+   * - the remnant is forced to be sufficiently large
+   *
+   * Generally not the best choice, but useful when writing other templated 
methods on top of
+   * @c MemArena by handling the edge case of @c void.
+   */
+  template <> MemSpan remnant_span(size_t n);
+
   /// @return Contiguous free space in the current internal block.
   MemSpan remnant();
 
+  /** Get an aligned remnant.
+   *
+   * @param n Remnant size.
+   * @param align Memory alignment (default 1, must be power of 2).
+   * @return Space in the remnant with minimal alignment padding.
+   *
+   * @note This will always return a span of @a n bytes, the remnant will be 
expanded as needed.
+   */
+  MemSpan remnant(size_t n, size_t align = DEFAULT_ALIGNMENT);
+
   /** Require @a n bytes of contiguous memory to be available for allocation.
*
* @param n Number of bytes.
@@ -351,7 +386,6 @@ public:
   const_iterator frozen_begin() const;
 
   const_iterator frozen_end() const;
-
 protected:
   /** Internally allocates a new block of memory of size @a n bytes.
*
@@ -509,20 +543,6 @@ MemArena::Block::alloc(size_t n, size_t align) {
   return zret;
 }
 
-template 
-MemSpan
-MemArena::alloc_span(size_t n) {
-  return this->alloc(sizeof(T) * n, size_t{alignof(T)}).rebind();
-}
-
-template 
-T *
-MemArena::make(Args &&... args) {
-  return new (this->alloc(sizeof(T)).data()) T(std::forward(args)...);
-}
-
-inline MemArena::MemArena(size_t n) : _reserve_hint(n) {}
-
 inline MemSpan
 MemArena::Block::remnant() {
   return {this->data() + allocated, this->remaining()};
@@ -545,10 +565,40 @@ MemArena::Block::operator delete([[maybe_unused]] void 
*ptr, void *place) noexce
 
 inline size_t
 MemArena::Block::align_padding(void const *ptr, size_t align) {
-  auto delta = uintptr_t(ptr) & (size_t(align) - 1);
-  return delta ? size_t(align) - delta : delta;
+  if (auto delta = uintptr_t(ptr) & (align - 1) ; delta > 0) {
+return align - delta;
+  }
+  return 0;
+}
+
+inline MemArena::MemArena(size_t n) : _reserve_hint(n) {}
+
+template 
+MemSpan
+MemArena::alloc_span(size_t n) {
+  return this->alloc(sizeof(T) * n, alignof(T)).rebind();
+}
+
+template 
+T *
+MemArena::make(Args &&... args) {
+  return new (this->alloc(sizeof(T), alignof(T)).data()) 
T(std::forward(args)...);
+}
+
+template 
+MemSpan
+MemArena::remnant_span(size_t n) {
+  auto span = this->require(sizeof(T) * n, alignof(T)).remnant();
+  return span.remove_prefix(Block::align_padding(span.data(), 
alignof(T))).rebind();
 }
 
+template <>
+inline MemSpan
+MemArena::remnant_span(size_t n) { return 
this->require(n).remnant().prefix(n); }
+
+inline MemSpan
+MemArena::remnant(size_t n, size_t align) { return this->require(n, 
align).remnant().prefix(n); }
+
 inline size_t
 MemArena::size() const {
   return _active_allocated;
diff --git a/code/include/swoc/MemSpan.h b/code/include/swoc/MemSpan.h
index b51528a..d6f107a 100644
--- a/code/include/swoc/MemSpan.h
+++ b/code/include/swoc/MemSpan.h
@@ -21,6 +21,7 @@
 #include 
 
 #include "swoc/swoc_version.h"
+#include "swoc/Scalar.h"
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 /** A span of contiguous piece of memory.
@@ -442,7 +443,7 @@ public:
 
   @return An instance that contains the leading @a n bytes of @a this.
   */
-  self_type prefix(size_t n) const;
+  constexpr self_type prefix(size_t n);
 
   /** Shrink the span by removing @a n leading bytes.
*
@@ -457,7 +458,7 @@ public:
* @param n 

(trafficserver-libswoc) 03/04: Update to version 1.1.5

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-1-4
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 6dee1535924723c1c031221e568481469dc35db4
Author: Alan M. Carroll 
AuthorDate: Thu Apr 2 12:24:48 2020 -0500

Update to version 1.1.5
---
 doc/Doxyfile   | 2 +-
 doc/code/IPSpace.en.rst| 2 +-
 doc/code/TextView.en.rst   | 6 +++---
 doc/conf.py| 2 +-
 swoc++/CMakeLists.txt  | 2 +-
 swoc++/include/swoc/swoc_version.h | 2 +-
 swoc++/swoc++.part | 2 +-
 7 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/doc/Doxyfile b/doc/Doxyfile
index 182e569..87eab21 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.1.4"
+PROJECT_NUMBER = "1.1.5"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index ce19ea4..c19d0f9 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -170,7 +170,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index b7d99a0..b4ca9e5 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -275,7 +275,7 @@ separated by commas.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 If :arg:`value` was :literal:`bob  ,dave, sam` then :arg:`token` would be 
successively
 :literal:`bob`, :literal:`dave`, :literal:`sam`. After :literal:`sam` was 
extracted :arg:`value`
@@ -297,7 +297,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, with each 
element being treated as
 a "list" with ``=`` as the separator. Note if there is no ``=`` character then 
all of the list
@@ -348,7 +348,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/conf.py b/doc/conf.py
index 6c8b467..0939355 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -80,7 +80,7 @@ project = u'Solid Wall Of C++'
 copyright = u'{}, a...@apache.org'.format(date.today().year)
 
 # The full version, including alpha/beta/rc tags.
-release = "1.1.4"
+release = "1.1.5"
 # The short X.Y version.
 version = '.'.join(release.split('.', 2)[:2])
 
diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index 5b48cca..acce6d7 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(lib-swoc++ CXX)
-set(LIBSWOC_VERSION "1.1.4")
+set(LIBSWOC_VERSION "1.1.5")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/swoc++/include/swoc/swoc_version.h 
b/swoc++/include/swoc/swoc_version.h
index e345466..005371e 100644
--- a/swoc++/include/swoc/swoc_version.h
+++ b/swoc++/include/swoc/swoc_version.h
@@ -39,5 +39,5 @@ namespace swoc
 {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 1;
-static constexpr unsigned POINT_VERSION = 4;
+static constexpr unsigned POINT_VERSION = 5;
 } // namespace swoc
diff --git a/swoc++/swoc++.part b/swoc++/swoc++.part
index 3f67fa7..5ef8982 100644
--- a/swoc++/swoc++.part
+++ b/swoc++/swoc++.part
@@ -1,6 +1,6 @@
 

(trafficserver-libswoc) 02/04: Fix for blending bug introduced in 1.1.2.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-1-4
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 5b543a2c8c5af7d44c2e1fad7936bf3e12cea1ab
Author: Alan M. Carroll 
AuthorDate: Tue Mar 31 17:57:59 2020 -0500

Fix for blending bug introduced in 1.1.2.
---
 swoc++/include/swoc/DiscreteRange.h | 53 +
 unit_tests/test_ip.cc   | 26 ++
 2 files changed, 50 insertions(+), 29 deletions(-)

diff --git a/swoc++/include/swoc/DiscreteRange.h 
b/swoc++/include/swoc/DiscreteRange.h
index d6f933e..4ab78fb 100644
--- a/swoc++/include/swoc/DiscreteRange.h
+++ b/swoc++/include/swoc/DiscreteRange.h
@@ -472,12 +472,7 @@ 
DiscreteRange::is_left_adjacent_to(DiscreteRange::self_type const ) cons
* T has a modulus and not depend on ++t > t always being true. However, we 
know that if t1 >
* t0 then ++t0 > t0.
*/
-
-  if (_max < that._min) {
-T x(_max);
-return ++x == that._min;
-  }
-  return false;
+  return _max < that._min && ++metric_type(_max) == that._min;
 }
 
 template 
@@ -836,16 +831,16 @@ DiscreteSpace::Node::assign(PAYLOAD 
const ) -> self_typ
 
 template
 void DiscreteSpace::Node::structure_fixup() {
-  if (_left) {
-if (_right) {
-  _hull = this->left()->_hull.hull(this->right()->_hull);
-} else {
-  _hull = this->left()->_hull;
-}
+  // Invariant: The hulls of all children are correct.
+  if (_left && _right) {
+// If both children, local range must be inside the hull of the children 
and irrelevant.
+_hull.assign(this->left()->_hull.min(), this->right()->_hull.max());
+  } else if (_left) {
+_hull.assign(this->left()->_hull.min(), _range.max());
   } else if (_right) {
-_hull = this->right()->_hull;
+_hull.assign(_range.min(), this->right()->_hull.max());
   } else {
-_hull = _range; // always contain at least self in the hull.
+_hull = _range;
   }
 }
 
@@ -951,8 +946,7 @@ DiscreteSpace::insert_before(DiscreteSpace::Node *spot, Discret
 template 
 void
 DiscreteSpace::insert_after(DiscreteSpace::Node *spot, 
DiscreteSpace::Node *node) {
-  Node *c = right(spot);
-  if (!c) {
+  if (right(spot) == nullptr) {
 spot->set_child(node, Direction::RIGHT);
   } else {
 // If there's a right child, there's a successor node, and therefore @a 
_next is valid.
@@ -1259,25 +1253,25 @@ DiscreteSpace::blend(DiscreteSpace::range_type const, U c
 if (same_color_p && n->max() >= remaining.max()) {
   return *this; // incoming range is completely covered by @a n in the 
same color, done.
 }
-remaining.assign_min(++METRIC(n->max())); // going to fill up 
n->max(), clip target.
+remaining.assign_min(++metric_type(n->max())); // going to fill up 
n->max(), clip target.
 if (! same_color_p) {
-  n->assign_max(--METRIC(remaining.min())); // clip @a n down.
+  n->assign_max(--metric_type(remaining.min())); // clip @a n down.
   this->insert_after(n, fill.get()); // add intersection node in 
different color.
-  n = fill.release();
+  n = fill.release(); // skip to use new node as current node.
 }
   } else { // clear, don't fill.
-auto max = n->max(); // cache this before reassigning.
-if (max > remaining.max()) { // overhang on the right, must split.
-  fill.release();
-  this->insert_before(n, _fa.make(n->min(), --METRIC(remaining.min()), 
n->payload()));
-  n->assign_min(++METRIC(remaining.max()));
+auto n_r = n->range(); // cache to avoid ordering requirements.
+if (n_r.max() > remaining.max()) { // overhang on the right, must 
split.
+  fill.release(); // not going to use it,
+  n->assign_min(++metric_type(remaining.max()));
+  this->insert_before(n, _fa.make(n_r.min(), 
--metric_type(remaining.min()), n->payload()));
   return *this;
 }
-n->assign_max(--METRIC(remaining.min())); // clip @a n down.
-if (max == remaining.max()) {
+n->assign_max(--metric_type(remaining.min())); // clip @a n down.
+if (n_r.max() == remaining.max()) {
   return *this;
 }
-remaining.assign_min(++METRIC(max));
+remaining.assign_min(++metric_type(n_r.max()));
   }
   continue;
 }
@@ -1308,8 +1302,9 @@ DiscreteSpace::blend(DiscreteSpace::range_type const, U c
   if (right_adj_p && n_plain_colored_p) { // can pull @a n left to cover
 n->assign_min(remaining.min());
 if (pred_plain_colored_p) { // if that touches @a pred with same 
color, collapse.
-  n->assign_min(pred->min());
+  auto pred_min = pred->min();
   this->remove(pred);
+  n->assign_min(pred_min);
 }
   } else if (pred_plain_colored_p) { // can pull @a pred right to cover.
 pred->assign_max(remaining.max());
@@ -1389,7 

(trafficserver-libswoc) 04/04: Fix missing virtual destructors.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-1-4
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 9e0793583cc1e5a6cef958cd79ff70511dd76402
Author: Alan M. Carroll 
AuthorDate: Thu Apr 2 12:25:00 2020 -0500

Fix missing virtual destructors.
---
 swoc++/CMakeLists.txt  | 2 +-
 swoc++/include/swoc/bwf_base.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index acce6d7..ec2b447 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -46,7 +46,7 @@ set(CC_FILES
 
 add_library(swoc++ STATIC ${CC_FILES})
 #add_compile_options(-Wall -Wextra -Werror -Wno-unused-parameter 
-Wno-format-truncation -Wno-stringop-overflow -Wno-invalid-offsetof)
-target_compile_options(swoc++ PRIVATE -Wall -Wextra -Werror 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
+target_compile_options(swoc++ PRIVATE -Wall -Wextra -Werror -Wnon-virtual-dtor 
-Wno-unused-parameter -Wno-stringop-overflow)
 
 # Not quite sure how this works, but I think it generates one of two paths 
depending on the context.
 # That is, the generator functions return non-empty strings only in the 
corresponding context.
diff --git a/swoc++/include/swoc/bwf_base.h b/swoc++/include/swoc/bwf_base.h
index af894af..ad732fe 100644
--- a/swoc++/include/swoc/bwf_base.h
+++ b/swoc++/include/swoc/bwf_base.h
@@ -766,6 +766,8 @@ namespace bwf
   class ArgPack
   {
   public:
+virtual ~ArgPack() = default; /// Force virtual destructor for subclasses.
+
 /** Get argument at index @a idx.
  *
  * @param idx Argument index.



(trafficserver-libswoc) branch dev-1-1-4 created (now 9e07935)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-1-4
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 9e07935  Fix missing virtual destructors.

This branch includes the following new commits:

 new 291c745  Update to version 1.1.4
 new 5b543a2  Fix for blending bug introduced in 1.1.2.
 new 6dee153  Update to version 1.1.5
 new 9e07935  Fix missing virtual destructors.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 01/04: Update to version 1.1.4

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-1-4
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 291c745dbc9d8003a9645261ffd94d9058d876df
Author: Alan M. Carroll 
AuthorDate: Tue Mar 31 15:53:03 2020 -0500

Update to version 1.1.4
---
 doc/Doxyfile   | 2 +-
 doc/code/IPSpace.en.rst| 2 +-
 doc/code/TextView.en.rst   | 6 +++---
 doc/conf.py| 2 +-
 swoc++/CMakeLists.txt  | 2 +-
 swoc++/include/swoc/swoc_version.h | 2 +-
 swoc++/swoc++.part | 2 +-
 7 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/doc/Doxyfile b/doc/Doxyfile
index 8496a10..182e569 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.1.3"
+PROJECT_NUMBER = "1.1.4"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index eb2aff1..ce19ea4 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -170,7 +170,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 1935d7b..b7d99a0 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -275,7 +275,7 @@ separated by commas.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 If :arg:`value` was :literal:`bob  ,dave, sam` then :arg:`token` would be 
successively
 :literal:`bob`, :literal:`dave`, :literal:`sam`. After :literal:`sam` was 
extracted :arg:`value`
@@ -297,7 +297,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, with each 
element being treated as
 a "list" with ``=`` as the separator. Note if there is no ``=`` character then 
all of the list
@@ -348,7 +348,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/conf.py b/doc/conf.py
index 038d963..6c8b467 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -80,7 +80,7 @@ project = u'Solid Wall Of C++'
 copyright = u'{}, a...@apache.org'.format(date.today().year)
 
 # The full version, including alpha/beta/rc tags.
-release = "1.1.3"
+release = "1.1.4"
 # The short X.Y version.
 version = '.'.join(release.split('.', 2)[:2])
 
diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index 1718c27..5b48cca 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(lib-swoc++ CXX)
-set(LIBSWOC_VERSION "1.1.3")
+set(LIBSWOC_VERSION "1.1.4")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/swoc++/include/swoc/swoc_version.h 
b/swoc++/include/swoc/swoc_version.h
index 8252afd..e345466 100644
--- a/swoc++/include/swoc/swoc_version.h
+++ b/swoc++/include/swoc/swoc_version.h
@@ -39,5 +39,5 @@ namespace swoc
 {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 1;
-static constexpr unsigned POINT_VERSION = 3;
+static constexpr unsigned POINT_VERSION = 4;
 } // namespace swoc
diff --git a/swoc++/swoc++.part b/swoc++/swoc++.part
index 90aeeda..3f67fa7 100644
--- a/swoc++/swoc++.part
+++ b/swoc++/swoc++.part
@@ -1,6 +1,6 @@
 

(trafficserver-libswoc) 01/02: Update clang-format to ATS 10.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch clang-format
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit f11c6c717dc4aa4ddd5850edf36744b99d652593
Author: Alan M. Carroll 
AuthorDate: Wed Nov 8 14:02:13 2023 -0600

Update clang-format to ATS 10.
---
 .clang-format | 152 +-
 tools/clang-format.sh |  68 +++---
 2 files changed, 175 insertions(+), 45 deletions(-)

diff --git a/.clang-format b/.clang-format
index 68a4641..b04bf05 100644
--- a/.clang-format
+++ b/.clang-format
@@ -2,62 +2,99 @@
 Language:Cpp
 AccessModifierOffset: -2
 AlignAfterOpenBracket: Align
-AlignConsecutiveMacros: false
-AlignConsecutiveAssignments: true
-AlignConsecutiveDeclarations: false
+AlignArrayOfStructures: Left
+AlignConsecutiveAssignments:
+  Enabled: true
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   true
+  PadOperators:true
+AlignConsecutiveBitFields:
+  Enabled: true
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:false
+AlignConsecutiveDeclarations:
+  Enabled: false
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:true
+AlignConsecutiveMacros:
+  Enabled: true
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:true
+AlignConsecutiveShortCaseStatements:
+  Enabled: false
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCaseColons: false
 AlignEscapedNewlines: Left
-AlignOperands:   true
-AlignTrailingComments: true
-AllowAllArgumentsOnNextLine: true
-AllowAllConstructorInitializersOnNextLine: true
+AlignOperands:   Align
+AlignTrailingComments:
+  Kind:Always
+  OverEmptyLines:  0
+AllowAllArgumentsOnNextLine: false
 AllowAllParametersOfDeclarationOnNextLine: false
 AllowShortBlocksOnASingleLine: Never
 AllowShortCaseLabelsOnASingleLine: false
+AllowShortEnumsOnASingleLine: true
 AllowShortFunctionsOnASingleLine: Inline
-AllowShortLambdasOnASingleLine: All
 AllowShortIfStatementsOnASingleLine: Never
+AllowShortLambdasOnASingleLine: All
 AllowShortLoopsOnASingleLine: false
 AlwaysBreakAfterDefinitionReturnType: All
 AlwaysBreakAfterReturnType: AllDefinitions
 AlwaysBreakBeforeMultilineStrings: false
 AlwaysBreakTemplateDeclarations: MultiLine
+AttributeMacros:
+  - __capability
 BinPackArguments: true
 BinPackParameters: true
+BitFieldColonSpacing: Both
 BraceWrapping:
   AfterCaseLabel:  false
   AfterClass:  true
-  AfterControlStatement: false
+  AfterControlStatement: Never
   AfterEnum:   false
+  AfterExternBlock: false
   AfterFunction:   true
-  AfterNamespace:  true
+  AfterNamespace:  false
   AfterObjCDeclaration: false
   AfterStruct: false
   AfterUnion:  false
-  AfterExternBlock: false
   BeforeCatch: false
   BeforeElse:  false
+  BeforeLambdaBody: false
+  BeforeWhile: false
   IndentBraces:false
   SplitEmptyFunction: true
   SplitEmptyRecord: true
   SplitEmptyNamespace: true
+BreakAfterAttributes: Never
+BreakAfterJavaFieldAnnotations: false
+BreakArrays: true
 BreakBeforeBinaryOperators: None
-BreakBeforeInheritanceComma: false
-BreakInheritanceList: BeforeColon
+BreakBeforeConceptDeclarations: Always
+#BreakBeforeBraces: Linux
+BreakBeforeInlineASMColon: OnlyMultiline
 BreakBeforeTernaryOperators: false
-BreakConstructorInitializersBeforeComma: false
 BreakConstructorInitializers: BeforeColon
-BreakAfterJavaFieldAnnotations: false
+BreakInheritanceList: BeforeColon
 BreakStringLiterals: true
 ColumnLimit: 132
 CommentPragmas:  '^ IWYU pragma:'
 CompactNamespaces: true
-ConstructorInitializerAllOnOneLineOrOnePerLine: true
 ConstructorInitializerIndentWidth: 2
 ContinuationIndentWidth: 2
 Cpp11BracedListStyle: true
-DeriveLineEnding: true
 DerivePointerAlignment: false
 DisableFormat:   false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
 ExperimentalAutoDetectBinPacking: false
 FixNamespaceComments: true
 ForEachMacros:
@@ -67,72 +104,135 @@ ForEachMacros:
   - foreach
   - Q_FOREACH
   - BOOST_FOREACH
+IfMacros:
+  - KJ_IF_MAYBE
 IncludeBlocks:   Preserve
 IncludeCategories:
   - Regex:   '^"(llvm|llvm-c|clang|clang-c)/'
 Priority:2
 SortPriority:0
+CaseSensitive:   false
   - Regex:   '^(<|"(gtest|isl|json)/)'
 Priority:3
 SortPriority:0
+CaseSensitive:   false
   - Regex:   '.*'
 Priority:1
 SortPriority:0
+CaseSensitive:   false
 IncludeIsMainRegex: '$'
 IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseBlocks: false
 IndentCaseLabels: false
+IndentExternBlock: AfterExternBlock
 IndentGotoLabels: true
 IndentPPDirectives: None
+IndentRequiresClause: true
 IndentWidth: 2
 

(trafficserver-libswoc) branch clang-format created (now ae25197)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch clang-format
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at ae25197  Run clang format.

This branch includes the following new commits:

 new f11c6c7  Update clang-format to ATS 10.
 new ae25197  Run clang format.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 01/08: Lexicon: Change default handlers to make them available for constant instances.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-9
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 968de363c1697a521772d550f97664690758f264
Author: Alan M. Carroll 
AuthorDate: Fri Oct 18 18:40:14 2019 -0500

Lexicon: Change default handlers to make them available for constant 
instances.
---
 swoc++/include/swoc/Lexicon.h | 436 +-
 unit_tests/test_Lexicon.cc|  37 +++-
 2 files changed, 204 insertions(+), 269 deletions(-)

diff --git a/swoc++/include/swoc/Lexicon.h b/swoc++/include/swoc/Lexicon.h
index 96351d0..b66360e 100644
--- a/swoc++/include/swoc/Lexicon.h
+++ b/swoc++/include/swoc/Lexicon.h
@@ -23,6 +23,8 @@
 #include 
 #include 
 #include 
+#include 
+
 #include "swoc/IntrusiveHashMap.h"
 #include "swoc/MemArena.h"
 #include "swoc/bwf_base.h"
@@ -38,6 +40,8 @@ namespace detail
* @param fmt Format string.
* @param args Arguments to format string.
* @return r-value reference to a @c std::string containing the formatted 
string.
+   *
+   * This is used when throwing exceptions.
*/
   template 
   std::string
@@ -62,6 +66,12 @@ namespace detail
 @c TRUE would always be "true", while converting any of "true", "1", 
"yes", or "enable" would
 yield @c TRUE. This is convenient for parsing configurations to be more 
tolerant of input.
 
+The constructors are a bit baroque, but this is necessary in order to be 
able to declare
+constant instances of the @c Lexicon. If this isn't necessary, everything 
that can be done via
+the constructor can be done with other methods. The implementation of the 
constructors consists
+entirely of calls to @c define and @c set_default, the only difference is 
these methods can
+be called on a @c const instance from there.
+
 @note All names and value must be unique across the Lexicon. All name 
comparisons are case
 insensitive.
  */
@@ -73,34 +83,76 @@ protected:
   struct Item;
 
 public:
-  /// Used for initializer lists that have just a primary value.
-  using Pair = std::tuple;
-  /// A function to be called if a value is not found.
+  /** A function to be called if a value is not found to provide a default 
name.
+   * @param value The value.
+   * @return A name for the value.
+   *
+   * The name is return by view and therefore managing the lifetime of the 
name is problematic.
+   * Generally it should be process lifetime, unless some other shorter 
lifetime can be managed
+   * without a destructor being called. Unfortunately this can't be done any 
better without
+   * imposing memory management costs on normal use.
+   */
   using UnknownValueHandler = std::function;
-  /// A function to be called if a name is not found.
+
+  /** A function to be called if a name is not found, to provide a default 
value.
+   * @param name The name
+   * @return An enumeration value.
+   *
+   * The @a name is provided and a value in the enumeration type is expected.
+   */
   using UnknownNameHandler = std::function;
 
+  /** A default handler.
+   *
+   * This handles providing a default value or name for a missing name or 
value.
+   */
+  using DefaultHandler = std::variant;
+
+  /// Used for initializer lists that have just a primary value.
+  using Pair = std::tuple;
+
   /// Element of an initializer list that contains secondary names.
   struct Definition {
 const E///< Value for 
definition.
 const std::initializer_list  ///< Primary then 
secondary names.
   };
 
-  /// Template argument carrying struct.
-  /// @note Needed to pass a compile time constant to a constructor as compile 
time constant.
-  template  struct Require {
-  };
-
   /// Construct empty instance.
   Lexicon();
-  /// Construct with secondary names.
-  explicit Lexicon(const std::initializer_list );
-  /// Construct with primary names only.
-  explicit Lexicon(const std::initializer_list );
-  /// Construct and verify the number of definitions.
-  template  Lexicon(const Require &, const std::array(e)> );
-  /// Construct and verify the number of pairs.
-  template  Lexicon(const Require &, const std::array(e)> );
+
+  /** Construct with names, possible secondary values, and optional default 
handlers.
+   *
+   * @param items A list of initializers, each of which is a name and a list 
of values.
+   * @param handler_1 A default handler.
+   * @param handler_2 A default hander.
+   *
+   * Each item in the intializers must be a @c Definition, that is a name and 
a list of values.
+   * The first value is the primary value and is required. Subsequent values 
are optional
+   * and become secondary values.
+   *
+   * The default handlers are optional can be be omitted. If so, exceptions 
are thrown when values
+   * or names not in the @c Lexicon are used. See @c set_default for more 
details.
+   *
+   * @see set_default.
+   */
+  explicit Lexicon(const 

(trafficserver-libswoc) 07/08: Change IPSpace::blend to take an arbitrary type for the blending color.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-9
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit eb5adefa80147baf145eca78286667badfb3f020
Author: Alan M. Carroll 
AuthorDate: Wed Dec 4 15:23:05 2019 -0600

Change IPSpace::blend to take an arbitrary type for the blending color.
---
 doc/building.en.rst | 38 
 doc/code/IPSpace.en.rst | 22 +++---
 swoc++/include/swoc/DiscreteRange.h | 58 +
 swoc++/include/swoc/swoc_ip.h   | 43 +--
 unit_tests/test_ip.cc   |  2 +-
 5 files changed, 106 insertions(+), 57 deletions(-)

diff --git a/doc/building.en.rst b/doc/building.en.rst
new file mode 100644
index 000..ee0b744
--- /dev/null
+++ b/doc/building.en.rst
@@ -0,0 +1,38 @@
+.. Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+   agreements. See the NOTICE file distributed with this work for
+   additional information regarding copyright ownership. The ASF licenses this 
file to you under the
+   Apache License, Version 2.0 (the "License"); you may not use this file 
except in compliance with
+   the License. You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software 
distributed under the License
+   is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+   or implied. See the License for the specific language governing permissions 
and limitations under
+   the License.
+
+.. include:: common-defs.rst
+
+.. _building:
+
+Building
+
+
+The library is usually built using CMake, but is also intended to be buildable 
as a part for
+`SCons `__ using the `Parts 
` extensions.
+For this reason the overall codebase is split into the library code and the 
test code. As a library
+only the library code needs to be built, which is the part 
"swoc++/swoc++.part". For example, to
+get the 1.0.8 release as a library in a larger project, the top level 
"Sconstruct" would have ::
+
+   Part("swoc++/swoc++.part"
+ , vcs_type=VcsGit(server="github.com"
+   , repository="SolidWallOfCode/libswoc"
+   , tag="1.0.8"))
+
+The object that depends on this library would then have ::
+
+   DependsOn([
+  # ... other dependencies
+  , Component("swoc++")
+  , # ... more dependencies
+   ])
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index 832d799..fa2ef35 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -120,15 +120,19 @@ Blend
 +
 
 The :libswoc:`swoc::IPSpace::blend` method requires a range and a "blender", 
which is a functor
-that combines two :code:`PAYLOAD` instances. The signature is ::
+that blends a :arg:`color` into a :code:`PAYLOAD` instances. The signature is 
::
 
-  bool blender(PAYLOAD & lhs, PAYLOAD const& rhs)
+  bool blender(PAYLOAD & payload, U const& color)
+
+The type :code:`U` is that same as the template argument :code:`U` to the 
method, which must be
+compatible with the second argument to the :code:`blend` method. The argument 
passed to
+:code:`blender` is the second argument to :code:`blend`.
 
 The method is modeled on C++ `compound assignment operators
 
`__.
 If
 the blend operation is thought of as the "@" operator, then the blend functor 
performs :code:`lhs @=
 rhs`. That is, :arg:`lhs` is modified to be the combination of :arg:`lhs` and 
:arg`rhs`. :arg:`lhs`
-is always the previous payload already in the space, and :arg:`rhs` is the 
:arg:`payload` argument
+is always the previous payload already in the space, and :arg:`rhs` is the 
:arg:`color` argument
 to the :code:`blend` method. The internal logic handles copying the payload 
instances as needed.
 
 The return value indicates whether the combined result in :arg:`lhs` is a 
valid payload or not. If
@@ -138,19 +142,17 @@ payload are removed from the container. This allows 
payloads to be "unblended",
 cancel out another, or to do selective erasing of ranges.
 
 As an example, consider the case where the payload is a bitmask. It might be 
reasonable to keep
-empty bitmasks in the container, but it would be reasonble to decide the empty 
bitmask and any
+empty bitmasks in the container, but it would also be reasonble to decide the 
empty bitmask and any
 address mapped to it should removed entirely from the container. In such a 
case, a blender that
 clears bits in the payloads should return :code:`false` when the result is the 
empty bitmask.
 
 Similarly, if the goal is to remove ranges that have a specific payload, then 
a blender that returns
 :code:`false` if :arg:`lhs` matches that specific payload and 

(trafficserver-libswoc) 08/08: Fix version, version update script.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-9
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 6c3a3b894a39f39f3a75fe2e0ef4af800ef0689a
Author: Alan M. Carroll 
AuthorDate: Tue Jan 21 17:23:44 2020 -0600

Fix version, version update script.
---
 swoc++/include/swoc/swoc_version.h | 5 +++--
 swoc++/swoc++.part | 2 +-
 tools/update-version.sh| 7 ---
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/swoc++/include/swoc/swoc_version.h 
b/swoc++/include/swoc/swoc_version.h
index 1800d03..b3f9963 100644
--- a/swoc++/include/swoc/swoc_version.h
+++ b/swoc++/include/swoc/swoc_version.h
@@ -37,6 +37,7 @@
 
 namespace swoc
 {
-static constexpr unsigned MAJOR_VERSION = 1 static constexpr unsigned 
MINOR_VERSION = 0 static constexpr unsigned POINT_VERSION = 9
-
+static constexpr unsigned MAJOR_VERSION = 1;
+static constexpr unsigned MINOR_VERSION = 0;
+static constexpr unsigned POINT_VERSION = 9;
 } // namespace swoc
diff --git a/swoc++/swoc++.part b/swoc++/swoc++.part
index 9b3bb5d..8d34df8 100644
--- a/swoc++/swoc++.part
+++ b/swoc++/swoc++.part
@@ -1,5 +1,5 @@
 Import("*")
-PartVersion("1.0.8")
+PartVersion("1.0.9")
 PartName("swoc++")
 
 files = [
diff --git a/tools/update-version.sh b/tools/update-version.sh
index 2413f8d..c12569b 100644
--- a/tools/update-version.sh
+++ b/tools/update-version.sh
@@ -6,11 +6,12 @@ if [ -z "$3" ] ; then
 fi
 
 # Header
-sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(MAJOR_VERSION *= 
*\).*\$/\\1$1/"
-sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(MINOR_VERSION *= 
*\).*\$/\\1$2/"
-sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(POINT_VERSION *= 
*\).*\$/\\1$3/"
+sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(MAJOR_VERSION *= 
*\).*\$/\\1$1;/"
+sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(MINOR_VERSION *= 
*\).*\$/\\1$2;/"
+sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(POINT_VERSION *= 
*\).*\$/\\1$3;/"
 
 sed -i doc/conf.py --expr "s/release = .*\$/release = \"$1.$2.$3\"/"
 sed -i doc/Doxyfile --expr "s/\(PROJECT_NUMBER *= *\).*\$/\\1\"$1.$2.$3\"/"
 
 sed -i swoc++/CMakeLists.txt --expr "s/\(LIBSWOC_VERSION 
*\)\"[^\"]*\"/\\1\"$1.$2.$3\"/"
+sed -i swoc++/swoc++.part --expr 
"s/PartVersion(\"[0-9.]*\")/PartVersion(\"$1.$2.$3\")/"



(trafficserver-libswoc) 02/08: Upgrade to 1.0.9.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-9
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit cc3e3146bdba8f6cb673e8e661317c89eb58803f
Author: Alan M. Carroll 
AuthorDate: Sat Oct 19 12:22:48 2019 -0500

Upgrade to 1.0.9.
---
 CMakeLists.txt |  1 +
 doc/Doxyfile   |  2 +-
 doc/conf.py|  4 ++--
 swoc++/CMakeLists.txt  |  2 +-
 swoc++/include/swoc/swoc_version.h |  6 +++---
 tools/update-version.sh| 16 
 6 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b615fdb..d0aecab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,6 @@
 cmake_minimum_required(VERSION 3.12)
 
+project("Solid Wall Of C++ Library")
 set(INSTALL_DIR ${CMAKE_HOME_DIRECTORY})
 
 # Fortunately this has no external dependencies so the set up can be simple.
diff --git a/doc/Doxyfile b/doc/Doxyfile
index 69b1637..155a1e5 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.0.8"
+PROJECT_NUMBER = "1.0.9"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/conf.py b/doc/conf.py
index f5b0c42..72bdcf6 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -80,7 +80,7 @@ project = u'Solid Wall Of C++'
 copyright = u'{}, a...@apache.org'.format(date.today().year)
 
 # The full version, including alpha/beta/rc tags.
-release = "1.0.8"
+release = "1.0.9"
 # The short X.Y version.
 version = '.'.join(release.split('.', 2)[:2])
 
@@ -326,7 +326,7 @@ texinfo_documents = [
 epub_title = u'Solid Wall of C++'
 epub_author = u'a...@apache.org'
 epub_publisher = u'a...@apache.org'
-epub_copyright = u'2018, a...@apache.org'
+epub_copyright = u'2019, a...@apache.org'
 
 # The language of the text. It defaults to the language option
 # or en if the language is not set.
diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index 898279e..bbf358e 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(lib-swoc++ CXX)
-set(LIBSWOC_VERSION "1.0.8")
+set(LIBSWOC_VERSION "1.0.9")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/swoc++/include/swoc/swoc_version.h 
b/swoc++/include/swoc/swoc_version.h
index 4eb8d6c..36dea4b 100644
--- a/swoc++/include/swoc/swoc_version.h
+++ b/swoc++/include/swoc/swoc_version.h
@@ -37,8 +37,8 @@
 
 namespace swoc
 {
-static constexpr unsigned MAJOR_VERION  = 1;
-static constexpr unsigned MINOR_VERSION = 0;
-static constexpr unsigned POINT_VERSION = 8;
+static constexpr unsigned MAJOR_VERSION = 1
+static constexpr unsigned MINOR_VERSION = 0
+static constexpr unsigned POINT_VERSION = 9
 
 } // namespace swoc
diff --git a/tools/update-version.sh b/tools/update-version.sh
new file mode 100644
index 000..2413f8d
--- /dev/null
+++ b/tools/update-version.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+if [ -z "$3" ] ; then
+  echo "Usage: $0 major minor point"
+  exit 1
+fi
+
+# Header
+sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(MAJOR_VERSION *= 
*\).*\$/\\1$1/"
+sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(MINOR_VERSION *= 
*\).*\$/\\1$2/"
+sed -i swoc++/include/swoc/swoc_version.h --expr "s/\(POINT_VERSION *= 
*\).*\$/\\1$3/"
+
+sed -i doc/conf.py --expr "s/release = .*\$/release = \"$1.$2.$3\"/"
+sed -i doc/Doxyfile --expr "s/\(PROJECT_NUMBER *= *\).*\$/\\1\"$1.$2.$3\"/"
+
+sed -i swoc++/CMakeLists.txt --expr "s/\(LIBSWOC_VERSION 
*\)\"[^\"]*\"/\\1\"$1.$2.$3\"/"



(trafficserver-libswoc) 03/08: Update clang format config.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-9
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 36b66e5cd504e009cfb5e80d5670f9b50a09329e
Author: Alan M. Carroll 
AuthorDate: Sun Nov 10 15:14:04 2019 -0600

Update clang format config.
---
 .clang-format | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/.clang-format b/.clang-format
index 7c2364a..7f2631c 100644
--- a/.clang-format
+++ b/.clang-format
@@ -13,8 +13,8 @@ AllowShortCaseLabelsOnASingleLine: false
 AllowShortFunctionsOnASingleLine: Inline
 AllowShortIfStatementsOnASingleLine: false
 AllowShortLoopsOnASingleLine: false
-AlwaysBreakAfterDefinitionReturnType: All
-AlwaysBreakAfterReturnType: AllDefinitions
+#AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
 AlwaysBreakBeforeMultilineStrings: false
 AlwaysBreakTemplateDeclarations: false
 BinPackArguments: true
@@ -23,7 +23,7 @@ BraceWrapping:
   AfterClass:  true
   AfterControlStatement: true
   AfterEnum:   true
-  AfterFunction:   true
+  AfterFunction:   false
   AfterNamespace:  true
   AfterObjCDeclaration: false
   AfterStruct: true
@@ -92,10 +92,10 @@ PenaltyBreakString: 1000
 PenaltyExcessCharacter: 100
 PenaltyReturnTypeOnItsOwnLine: 200
 PointerAlignment: Right
-RawStringFormats: 
-  - Delimiter:   pb
-Language:TextProto
-BasedOnStyle:Mozilla
+#RawStringFormats: 
+#  - Delimiter:   'pb'
+#Language:TextProto
+#BasedOnStyle:Mozilla
 ReflowComments:  true
 SortIncludes:false
 SortUsingDeclarations: false



(trafficserver-libswoc) 04/08: Add FixedArena.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-9
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit d6fbf554738960766c0861baf2da962abb2ab80d
Author: Alan M. Carroll 
AuthorDate: Sun Nov 10 15:14:22 2019 -0600

Add FixedArena.
---
 swoc++/include/swoc/MemArena.h | 128 -
 unit_tests/test_MemArena.cc|  31 ++
 2 files changed, 118 insertions(+), 41 deletions(-)

diff --git a/swoc++/include/swoc/MemArena.h b/swoc++/include/swoc/MemArena.h
index 7e35a1f..2b2e3b0 100644
--- a/swoc++/include/swoc/MemArena.h
+++ b/swoc++/include/swoc/MemArena.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "swoc/MemSpan.h"
 #include "swoc/Scalar.h"
@@ -329,55 +330,89 @@ protected:
   // marks the last block to check. This keeps the set of blocks to check 
short.
 };
 
+/** Arena of a specific type on top of a @c MemArena.
+ *
+ * @tparam T Type in the arena.
+ *
+ * A pool of unused / free instances of @a T is kept for reuse. If none are 
available then a new
+ * instance is allocated from the arena.
+ */
+template  class FixedArena
+{
+  using self_type = FixedArena; ///< Self reference type.
+protected:
+  /// Rebinding type for instances on the free list.
+  struct Item {
+Item *_next; ///< Next item in the free list.
+  };
+
+  Item _list { nullptr }; ///< List of dead instances.
+  MemArena &_arena; ///< Memory source.
+
+public:
+  /** Construct a pool.
+   *
+   * @param arena The arena for memory.
+   */
+  explicit FixedArena(MemArena );
+
+  /** Create a new instance.
+   *
+   * @tparam Args Constructor argument types.
+   * @param args Constructor arguments.
+   * @return A new instance of @a T.
+   */
+  template  T *make(Args... args);
+
+  /** Destroy an instance.
+   *
+   * @param t The instance to destroy.
+   *
+   * The instance is destructed and then put on the free list for re-use.
+   */
+  void destroy(T *t);
+};
 // Implementation
 
-inline auto
-MemArena::Block::Linkage::next_ptr(Block *b) -> Block *&
+inline auto MemArena::Block::Linkage::next_ptr(Block *b) -> Block *&
 {
   return b->_link._next;
 }
 
-inline auto
-MemArena::Block::Linkage::prev_ptr(Block *b) -> Block *&
+inline auto MemArena::Block::Linkage::prev_ptr(Block *b) -> Block *&
 {
   return b->_link._prev;
 }
 
 inline MemArena::Block::Block(size_t n) : size(n) {}
 
-inline char *
-MemArena::Block::data()
+inline char *MemArena::Block::data()
 {
   return reinterpret_cast(this + 1);
 }
 
-inline const char *
-MemArena::Block::data() const
+inline const char *MemArena::Block::data() const
 {
   return reinterpret_cast(this + 1);
 }
 
-inline bool
-MemArena::Block::contains(const void *ptr) const
+inline bool MemArena::Block::contains(const void *ptr) const
 {
   const char *base = this->data();
   return base <= ptr && ptr < base + size;
 }
 
-inline size_t
-MemArena::Block::remaining() const
+inline size_t MemArena::Block::remaining() const
 {
   return size - allocated;
 }
 
-inline bool
-MemArena::Block::is_full() const
+inline bool MemArena::Block::is_full() const
 {
   return this->remaining() < MIN_FREE_SPACE;
 }
 
-inline MemSpan
-MemArena::Block::alloc(size_t n)
+inline MemSpan MemArena::Block::alloc(size_t n)
 {
   if (n > this->remaining()) {
 throw(std::invalid_argument{"MemArena::Block::alloc size is more than 
remaining."});
@@ -387,80 +422,91 @@ MemArena::Block::alloc(size_t n)
   return zret;
 }
 
-template 
-T *
-MemArena::make(Args &&... args)
+template  T *MemArena::make(Args &&... args)
 {
   return new (this->alloc(sizeof(T)).data()) T(std::forward(args)...);
 }
 
 inline MemArena::MemArena(size_t n) : _reserve_hint(n) {}
 
-inline MemSpan
-MemArena::Block::remnant()
+inline MemSpan MemArena::Block::remnant()
 {
   return {this->data() + allocated, this->remaining()};
 }
 
-inline MemArena::Block &
-MemArena::Block::discard()
+inline MemArena::Block ::Block::discard()
 {
   allocated = 0;
   return *this;
 }
 
-inline size_t
-MemArena::size() const
+inline size_t MemArena::size() const
 {
   return _active_allocated;
 }
 
-inline size_t
-MemArena::allocated_size() const
+inline size_t MemArena::allocated_size() const
 {
   return _frozen_allocated + _active_allocated;
 }
 
-inline size_t
-MemArena::remaining() const
+inline size_t MemArena::remaining() const
 {
   return _active.empty() ? 0 : _active.head()->remaining();
 }
 
-inline MemSpan
-MemArena::remnant()
+inline MemSpan MemArena::remnant()
 {
   return _active.empty() ? MemSpan() : _active.head()->remnant();
 }
 
-inline size_t
-MemArena::reserved_size() const
+inline size_t MemArena::reserved_size() const
 {
   return _active_reserved + _frozen_reserved;
 }
 
-inline auto
-MemArena::begin() const -> const_iterator
+inline auto MemArena::begin() const -> const_iterator
 {
   return _active.begin();
 }
 
-inline auto
-MemArena::end() const -> const_iterator
+inline auto 

(trafficserver-libswoc) 06/08: Documentation update for IP Networking.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-9
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 3f35e4b8be14306d4e858b720aeed075e79c92d0
Author: Alan M. Carroll 
AuthorDate: Wed Dec 4 13:20:08 2019 -0600

Documentation update for IP Networking.
---
 doc/Makefile  |   4 +-
 doc/code/BW_Format.en.rst |   4 +-
 doc/code/IPSpace.en.rst   | 127 --
 doc/index.rst |   1 +
 swoc++/include/swoc/swoc_ip.h |  36 ++--
 5 files changed, 160 insertions(+), 12 deletions(-)

diff --git a/doc/Makefile b/doc/Makefile
index cde5d25..047a4dc 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -22,7 +22,8 @@ $(IMAGEDIR)/%.svg : $(UMLDIR)/%.uml
 
 help:
@echo "Please use \`make ' where  is one of"
-   @echo "  html   to make standalone HTML files"
+   @echo "  html   to make standalone HTML files."
+   @echo "  publishto build the documentation clean, ready to publish."
 
 uml:
@if [ ! -d uml ] ; then mkdir uml; fi
@@ -38,6 +39,7 @@ html: static uml ext/local-config.py reference
 clean:
-rm -rf html warn.log
-rm -rf $(BUILDDIR)/doctrees $(BUILDDIR)/html $(BUILDDIR)/dirhtml 
$(BUILDDIR)/singlehtml
+   -rm -rf doxygen
 
 publish: clean doxygen html
 
diff --git a/doc/code/BW_Format.en.rst b/doc/code/BW_Format.en.rst
index 1d8ec08..712da59 100644
--- a/doc/code/BW_Format.en.rst
+++ b/doc/code/BW_Format.en.rst
@@ -489,8 +489,8 @@ Specific types
:code:`#include `
 
The IP address is printed. Fill is used to fill in address segments if 
provided, not to the
-   minimum width if specified. :class:`IpEndpoint` and :class:`IpAddr` are 
supported with the same
-   formatting. The formatting support in this case is extensive because of the 
commonality and
+   minimum width if specified. :libswoc:`IPEndpoint` and :libswoc:`IPAddr` are 
supported with the
+   same formatting. The formatting support in this case is extensive because 
of the commonality and
importance of IP address data.
 
Type overrides
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index 353a171..832d799 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -16,15 +16,18 @@
 .. default-domain:: cpp
 .. highlight:: cpp
 
-
-IP Space
-
+*
+IP Networking
+*
 
 Synopsis
 
 
 :code:`#include `
 
+Usage
+*
+
 .. class:: IPEndpoint
 
:libswoc:`Reference documentation `.
@@ -32,8 +35,122 @@ Synopsis
 This library is for storing and manipulating IP addresses as data. It has no 
support for actual
 network operations.
 
-Usage
-*
+IPAddr
+==
+
+The classes :libswoc:`swoc::IPAddr`, :libswoc:`swoc::IP4Addr`, and 
:libswoc:`swoc::IP6Addr` are used
+to hold IP addresses. :code:`IP4Addr` and :code:`IP6Addr` are family specific 
and hold
+(respectively) IPv4 and IPv6 addresses. :code:`IPAddr` acts as a union of 
these two types along with
+an IP family specifier that indicates the type of address contained. The type 
specific classes
+provide performance and storage benefits when the type of the address is known 
or forced, while
+:code:`IPAddr` provides a generic type useful for interfaces.
+
+These classes provide support for parsing and formatting IP addresses. The 
constructor can take
+a string and, if a valid address, will initialize the instance to that 
address. The downside is
+there is no indication of failure other than the instance initializing to the 
zero or "any"
+address. This can be reasonable in situations where those addresses are not 
valid either. However
+in general the :libswoc:`swoc::IPAddr::load` method should be used, which both 
initializes the
+instance and provides an indication of whether the input was valid.
+
+IPRange
+===
+
+The classes :libswoc:`swoc::IPRange`, :libswoc:`swoc::IP4Range`, and 
:libswoc:`swoc::IP6Range` are
+used to hold ranges of IP addresses. :code:`IP4Range` and :code:`IP6Range` are 
family specific and
+hold (respectively) IPv4 and IPv6 addresses. :code:`IPAddr` acts as a union of 
these two types along
+with an IP family specifier that indicates the type of address contained. The 
type specific classes
+provide performance and storage benefits when the type of the address is known 
or forced, while
+:code:`IPRange` provides a generic type useful for interfaces. Note that an 
:code:`IPRange` holds a
+range of addresses of a single family, it can never hold a range that is of 
mixed families.
+
+These classes provide support for parsing and formatting ranges of IP 
adddresses. The parsing logic
+accepts three forms of a range. In all cases the lower and upper limits of the 
range must be the
+same IP address family.
+
+Range
+   Two addresses, separated by a dash ("-") character. E.g.
+
+  172.26.13.4-172.27.12.9
+
+Network
+   An address and a CIDR based mask, separated by 

(trafficserver-libswoc) branch dev-1-0-9 created (now 6c3a3b8)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-0-9
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 6c3a3b8  Fix version, version update script.

This branch includes the following new commits:

 new 968de36  Lexicon: Change default handlers to make them available for 
constant instances.
 new cc3e314  Upgrade to 1.0.9.
 new 36b66e5  Update clang format config.
 new d6fbf55  Add FixedArena.
 new e651aec  First successful unit test of IPSpace. (#15)
 new 3f35e4b  Documentation update for IP Networking.
 new eb5adef  Change IPSpace::blend to take an arbitrary type for the 
blending color.
 new 6c3a3b8  Fix version, version update script.

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 04/04: IP: add compact range output support.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-12
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit e525832f22bd2721bb7321090117d3dadc454592
Author: Alan M. Carroll 
AuthorDate: Tue Oct 20 09:04:42 2020 -0500

IP: add compact range output support.
---
 code/include/swoc/swoc_ip.h | 38 ++
 code/src/bw_ip_format.cc| 26 ++
 code/src/swoc_ip.cc | 25 +
 doc/code/IPSpace.en.rst | 14 ++
 unit_tests/test_ip.cc   | 33 -
 5 files changed, 135 insertions(+), 1 deletion(-)

diff --git a/code/include/swoc/swoc_ip.h b/code/include/swoc/swoc_ip.h
index de9627d..44152c0 100644
--- a/code/include/swoc/swoc_ip.h
+++ b/code/include/swoc/swoc_ip.h
@@ -831,6 +831,14 @@ public:
*/
   bool load(string_view text);
 
+  /** Compute the mask for @a this as a network.
+   *
+   * @return If @a this is a network, the mask for that network. Otherwise an 
invalid mask.
+   *
+   * @see IPMask::is_valid
+   */
+  IPMask network_mask() const;
+
   class NetSource;
 
   /** Generate a list of networks covering @a this range.
@@ -874,6 +882,9 @@ public:
   iterator begin() const; ///< First network.
   iterator end() const; ///< Past last network.
 
+  /// Return @c true if there are valid networks, @c false if not.
+  bool empty() const;
+
   /// @return The current network.
   IP4Net operator*() const;
 
@@ -955,6 +966,14 @@ public:
*/
   bool load(string_view text);
 
+  /** Compute the mask for @a this as a network.
+   *
+   * @return If @a this is a network, the mask for that network. Otherwise an 
invalid mask.
+   *
+   * @see IPMask::is_valid
+   */
+  IPMask network_mask() const;
+
   class NetSource;
 
   /** Generate a list of networks covering @a this range.
@@ -998,6 +1017,9 @@ public:
   iterator begin() const; ///< First network.
   iterator end() const; ///< Past last network.
 
+  /// Return @c true if there are valid networks, @c false if not.
+  bool empty() const;
+
   /// @return The current network.
   IP6Net operator*() const;
 
@@ -1106,6 +1128,14 @@ public:
 
   IP6Range const& ip6() const { return _range._ip6; }
 
+  /** Compute the mask for @a this as a network.
+   *
+   * @return If @a this is a network, the mask for that network. Otherwise an 
invalid mask.
+   *
+   * @see IPMask::is_valid
+   */
+  IPMask network_mask() const;
+
   class NetSource;
 
   /** Generate a list of networks covering @a this range.
@@ -2627,6 +2657,10 @@ inline IP4Range::NetSource::iterator 
IP4Range::NetSource::end() const {
   return self_type{range_type{}};
 }
 
+inline bool IP4Range::NetSource::empty() const {
+  return _range.empty();
+}
+
 inline IPMask IP4Range::NetSource::mask() const { return IPMask{_cidr}; }
 
 inline auto IP4Range::NetSource::operator->() -> self_type * { return this; }
@@ -2650,6 +2684,10 @@ inline auto IP6Range::NetSource::end() const -> iterator 
{
   return self_type{range_type{}};
 }
 
+inline bool IP6Range::NetSource::empty() const {
+  return _range.empty();
+}
+
 inline IP6Net IP6Range::NetSource::operator*() const {
   return IP6Net{_range.min(), _mask};
 }
diff --git a/code/src/bw_ip_format.cc b/code/src/bw_ip_format.cc
index f45c46e..2efa30d 100644
--- a/code/src/bw_ip_format.cc
+++ b/code/src/bw_ip_format.cc
@@ -262,6 +262,19 @@ bwformat(BufferWriter& w, Spec const& spec, IP4Range 
const& range) {
   if (range.empty()) {
 w.write("*-*"_tv);
   } else {
+// Compact means output as singleton or CIDR if that's possible.
+if (spec._ext.find('c') != spec._ext.npos) {
+  if (range.is_singleton()) {
+return bwformat(w, spec, range.min());
+  }
+  auto mask { range.network_mask() };
+  if (mask.is_valid()) {
+bwformat(w, spec, range.min());
+w.write('/');
+bwformat(w, bwf::Spec::DEFAULT, mask);
+return w;
+  }
+}
 bwformat(w, spec, range.min());
 w.write('-');
 bwformat(w, spec, range.max());
@@ -274,6 +287,19 @@ bwformat(BufferWriter& w, Spec const& spec, IP6Range 
const& range) {
   if (range.empty()) {
 w.write("*-*"_tv);
   } else {
+// Compact means output as singleton or CIDR if that's possible.
+if (spec._ext.find('c') != spec._ext.npos) {
+  if (range.is_singleton()) {
+return bwformat(w, spec, range.min());
+  }
+  auto mask { range.network_mask() };
+  if (mask.is_valid()) {
+bwformat(w, spec, range.min());
+w.write('/');
+bwformat(w, bwf::Spec::DEFAULT, mask);
+return w;
+  }
+}
 bwformat(w, spec, range.min());
 w.write('-');
 bwformat(w, spec, range.max());
diff --git a/code/src/swoc_ip.cc b/code/src/swoc_ip.cc
index 10f1d3c..c971088 100644
--- a/code/src/swoc_ip.cc
+++ b/code/src/swoc_ip.cc
@@ -771,6 +771,14 @@ bool IP4Range::load(string_view text) {
   return 

(trafficserver-libswoc) 01/04: Update to 1.2.12.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-12
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 43294ea5626faf11be1a21f8cda23df0002c3c3b
Author: Alan M. Carroll 
AuthorDate: Mon Oct 19 18:56:01 2020 -0500

Update to 1.2.12.
---
 code/CMakeLists.txt  | 2 +-
 code/include/swoc/swoc_version.h | 4 ++--
 code/libswoc.part| 2 +-
 doc/Doxyfile | 2 +-
 doc/code/IPSpace.en.rst  | 2 +-
 doc/code/TextView.en.rst | 6 +++---
 doc/conf.py  | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index 74340f6..12cd5be 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(Lib-SWOC CXX)
-set(LIBSWOC_VERSION "1.2.11")
+set(LIBSWOC_VERSION "1.2.12")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/code/include/swoc/swoc_version.h b/code/include/swoc/swoc_version.h
index 4523e33..d59a222 100644
--- a/code/include/swoc/swoc_version.h
+++ b/code/include/swoc/swoc_version.h
@@ -22,11 +22,11 @@
 #pragma once
 
 #if !defined(SWOC_VERSION_NS)
-#  define SWOC_VERSION_NS _1_2_11
+#  define SWOC_VERSION_NS _1_2_12
 #endif
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 2;
-static constexpr unsigned POINT_VERSION = 11;
+static constexpr unsigned POINT_VERSION = 12;
 }} // namespace SWOC_VERSION_NS
diff --git a/code/libswoc.part b/code/libswoc.part
index b6af1d0..cef4283 100644
--- a/code/libswoc.part
+++ b/code/libswoc.part
@@ -1,6 +1,6 @@
 Import("*")
 PartName("libswoc")
-PartVersion("1.2.11")
+PartVersion("1.2.12")
 
 src_files = [
 "src/ArenaWriter.cc",
diff --git a/doc/Doxyfile b/doc/Doxyfile
index c0e44c7..858c6cf 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.2.11"
+PROJECT_NUMBER = "1.2.12"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index 3211c0f..a2dfed9 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -172,7 +172,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 71f4060..7681f1d 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -278,7 +278,7 @@ separated by commas.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 If :arg:`value` was :literal:`bob  ,dave, sam` then :arg:`token` would be 
successively
 :literal:`bob`, :literal:`dave`, :literal:`sam`. After :literal:`sam` was 
extracted :arg:`value`
@@ -300,7 +300,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, with each 
element being treated as
 a "list" with ``=`` as the separator. Note if there is no ``=`` character then 
all of the list
@@ -351,7 +351,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/conf.py b/doc/conf.py
index cf2ab10..666ab41 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ 

(trafficserver-libswoc) 02/04: Minor comment cleanup.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-12
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 213edee7310f298c993548a329e09f9e3606a7a3
Author: Alan M. Carroll 
AuthorDate: Mon Oct 19 18:56:23 2020 -0500

Minor comment cleanup.
---
 code/include/swoc/Scalar.h | 40 
 code/include/swoc/bwf_ex.h |  2 +-
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/code/include/swoc/Scalar.h b/code/include/swoc/Scalar.h
index d79e054..163aa34 100644
--- a/code/include/swoc/Scalar.h
+++ b/code/include/swoc/Scalar.h
@@ -100,7 +100,6 @@ scale_conversion_round_down(C c) {
 template struct scalar_unit_round_up_t {
   C _n;
 
-  //template  constexpr operator scalar_unit_round_up_t() { 
return {static_cast(_count)}; }
   template
   constexpr I
   scale() const {
@@ -112,7 +111,6 @@ template struct scalar_unit_round_up_t {
 template struct scalar_unit_round_down_t {
   C _n;
 
-  //template  operator scalar_unit_round_down_t() { return 
{static_cast(_count)}; }
   template
   constexpr I
   scale() const {
@@ -137,6 +135,7 @@ template struct 
scalar_round_down_t {
 return Scalar(scale_conversion_round_down(_n));
   }
 };
+
 /// @endcond
 } // namespace detail
 
@@ -192,27 +191,38 @@ public:
   /// @note Requires that @c S be an integer multiple of @c SCALE.
   template constexpr Scalar(Scalar const& 
that);
 
-  /// Conversion constructor.
+  /// @cond INTERNAL_DETAIL
+  // Assignment from internal rounding structures.
+  // Conversion constructor.
   constexpr Scalar(detail::scalar_round_up_t const& that);
 
-  /// Conversion constructor.
+  // Conversion constructor.
   constexpr Scalar(detail::scalar_round_down_t const& that);
 
-  /// Conversion constructor.
+  // Conversion constructor.
   template constexpr Scalar(detail::scalar_unit_round_up_t v);
 
-  /// Conversion constructor.
+  // Conversion constructor.
   template constexpr Scalar(detail::scalar_unit_round_down_t v);
+  /// @endcond
 
-  /// Assignment operator.
-  /// The value @a that is scaled appropriately.
-  /// @note Requires the scale of @a that be an integer multiple of the scale 
of @a this. If this isn't the case then
-  /// the @c round_up or @c round_down must be used to indicate the rounding 
direction.
+  /** Assign value from @a that.
+   *
+   * @tparam S Scale.
+   * @tparam I Integral type.
+   * @param that Source value.
+   * @return @a this.
+   *
+   * @note Requires the scale of @a that be an integer multiple of the scale 
of @a this. If this
+   * isn't the case then the @c round_up or @c round_down must be used to 
indicate the rounding
+   * direction.
+   */
   template self_type& operator=(Scalar const& 
that);
 
-  /// Assignment from same scale.
+  /// Self type assignment.
   self_type& operator=(self_type const& that);
 
+  /// @cond INTERNAL_DETAIL
   /** Internal method to assign a unit value to be rounded up to the internal 
@c SCALE.
*
* @tparam I The underlying scale type.
@@ -248,6 +258,7 @@ public:
* it to the local scale.
*/
   self_type& operator=(detail::scalar_round_down_t v);
+  /// @endcond
 
   /** Set the scaled count to @a n.
*
@@ -266,7 +277,7 @@ public:
   /// direction.
   template self_type& assign(Scalar const& 
that);
 
-  // Conversion assignments.
+  /// @cond INTERNAL_DETAIL
   template self_type& assign(detail::scalar_unit_round_up_t n);
 
   template self_type& assign(detail::scalar_unit_round_down_t 
n);
@@ -274,6 +285,7 @@ public:
   self_type& assign(detail::scalar_round_up_t v);
 
   self_type& assign(detail::scalar_round_down_t v);
+  /// @endcond
 
   /// The number of scale units.
   constexpr Counter count() const;
@@ -292,6 +304,7 @@ public:
 
   template self_type& operator+=(Scalar 
const& that);
 
+  /// @cond INTERNAL_DETAIL
   template self_type& operator+=(detail::scalar_unit_round_up_t 
n);
 
   template self_type& 
operator+=(detail::scalar_unit_round_down_t n);
@@ -299,6 +312,7 @@ public:
   self_type& operator+=(detail::scalar_round_up_t v);
 
   self_type& operator+=(detail::scalar_round_down_t v);
+  /// @endcond
 
   /// Increment - increase count by 1.
   self_type& operator++();
@@ -326,6 +340,7 @@ public:
 
   template self_type& operator-=(Scalar 
const& that);
 
+  /// @cond INTERNAL_DETAIL
   template self_type& operator-=(detail::scalar_unit_round_up_t 
n);
 
   template self_type& 
operator-=(detail::scalar_unit_round_down_t n);
@@ -333,6 +348,7 @@ public:
   self_type& operator-=(detail::scalar_round_up_t v);
 
   self_type& operator-=(detail::scalar_round_down_t v);
+  /// @endcond
 
   /// Multiplication - multiple the count by @a n.
   self_type& operator*=(C n);
diff --git a/code/include/swoc/bwf_ex.h b/code/include/swoc/bwf_ex.h
index 31703d2..2f31374 100644
--- a/code/include/swoc/bwf_ex.h
+++ b/code/include/swoc/bwf_ex.h
@@ -94,7 +94,7 @@ template struct SubText {
   arg_pack 

(trafficserver-libswoc) 03/04: IPSpace: fix bug in blending where the blender returns false. Add tests to verify.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-12
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 7143b8d3aa180f00fbfd75919b82f9c1015b2d6c
Author: Alan M. Carroll 
AuthorDate: Mon Oct 19 18:56:42 2020 -0500

IPSpace: fix bug in blending where the blender returns false. Add tests to 
verify.
---
 code/include/swoc/DiscreteRange.h |  2 +-
 unit_tests/test_ip.cc | 24 
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/code/include/swoc/DiscreteRange.h 
b/code/include/swoc/DiscreteRange.h
index 6e2494d..58f2c5b 100644
--- a/code/include/swoc/DiscreteRange.h
+++ b/code/include/swoc/DiscreteRange.h
@@ -1376,7 +1376,7 @@ DiscreteSpace::blend(DiscreteSpace::range_type const& range, U
 }
   } else if (pred_plain_colored_p) { // can pull @a pred right to cover.
 pred->assign_max(remaining.max());
-  } else if (!remaining.empty()) { // Must add new range.
+  } else if (!remaining.empty() && plain_color_p) { // Must add new range 
if plain color valid.
 this->insert_before(n, _fa.make(remaining.min(), remaining.max(), 
plain_color));
   }
   return *this;
diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc
index ba81bc6..aed4618 100644
--- a/unit_tests/test_ip.cc
+++ b/unit_tests/test_ip.cc
@@ -816,10 +816,20 @@ TEST_CASE("IPSpace bitset", "[libswoc][ipspace][bitset]") 
{
 TEST_CASE("IPSpace docJJ", "[libswoc][ipspace][docJJ]") {
   using PAYLOAD = std::bitset<32>;
   using Space = swoc::IPSpace;
+  // Add the bits in @rhs to the range.
   auto blender = [](PAYLOAD, PAYLOAD const) -> bool {
 lhs |= rhs;
 return true;
   };
+  // Add bit @a idx iff bits are already set.
+  auto additive = [](PAYLOAD & lhs, unsigned idx) -> bool {
+if (! lhs.any()) {
+  return false;
+}
+lhs[idx] = true;
+return true;
+  };
+
   auto make_bits = [](std::initializer_list idx) -> PAYLOAD {
 PAYLOAD bits;
 for (auto bit : idx) {
@@ -889,6 +899,20 @@ TEST_CASE("IPSpace docJJ", "[libswoc][ipspace][docJJ]") {
 CHECK(bits == make_bits(results[idx]));
 ++idx;
   }
+
+  // This blend should change only existing ranges, not add range.
+  space.blend(IPRange{"99.128.0.0-100.0.1.255"}, 27, additive);
+  REQUIRE(space.count() == results.size()); // no more ranges.
+  // Verify first two ranges modified, but not the next.
+  REQUIRE(std::get<1>(*(space.find(IP4Addr{"100.0.0.37"}))) == 
make_bits({0,27,31}));
+  REQUIRE(std::get<1>(*(space.find(IP4Addr{"100.0.1.37"}))) == 
make_bits({1,27,30}));
+  REQUIRE(std::get<1>(*(space.find(IP4Addr{"100.0.2.37"}))) == make_bits({2}));
+
+  space.blend(IPRange{"100.10.1.1-100.10.2.2"}, make_bits({15}), blender);
+  REQUIRE(space.count() == results.size() + 1);
+  // Color in empty range - should not add range.
+  space.blend(IPRange{"100.8.10.25"}, 27, additive);
+  REQUIRE(space.count() == results.size() + 1);
 }
 
 TEST_CASE("IPSpace Uthira", "[libswoc][ipspace][uthira]") {



(trafficserver-libswoc) branch dev-1-2-12 created (now e525832)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-2-12
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at e525832  IP: add compact range output support.

This branch includes the following new commits:

 new 43294ea  Update to 1.2.12.
 new 213edee  Minor comment cleanup.
 new 7143b8d  IPSpace: fix bug in blending where the blender returns false. 
Add tests to verify.
 new e525832  IP: add compact range output support.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 02/02: Add svtod: convert TextView to double.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-5
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit d0bf7ef9da8ce4b10295df69b4d15a48274634a9
Author: Alan M. Carroll 
AuthorDate: Fri May 22 07:52:22 2020 -0500

Add svtod: convert TextView to double.
---
 code/include/swoc/TextView.h| 17 
 code/include/swoc/swoc_ip.h |  8 ++--
 code/src/TextView.cc| 80 +
 unit_tests/test_IntrusiveHashMap.cc |  3 ++
 unit_tests/test_TextView.cc | 22 ++
 5 files changed, 126 insertions(+), 4 deletions(-)

diff --git a/code/include/swoc/TextView.h b/code/include/swoc/TextView.h
index fec8962..740639a 100644
--- a/code/include/swoc/TextView.h
+++ b/code/include/swoc/TextView.h
@@ -822,11 +822,28 @@ svto_radix(swoc::TextView ) {
   return zret;
 }
 
+/// Convenience overload.
+/// @see @svto_radix(swoc::TextView )
 template 
 uintmax_t
 svto_radix(swoc::TextView &) {
   return svto_radix(src);
 }
+
+/** Parse @a text as a floating point number.
+ *
+ * @param text The input text.
+ * @param parsed Parsed text [out]
+ * @return The floating point value, or 0.0 if invalid input.
+ *
+ * If @a parsed is not @a nullptr then the span of characters parsed is put 
there. This can be
+ * used to check if the parse was scuccesful - on a failed parse, it will be 
empty.
+ *
+ * @note This should be within 1 epsilon of correct, although it doesn't 
guarantee picking
+ * the closest epsilon. It's more than sufficient for use in configurations, 
but possibly
+ * not for high precision work.
+ */
+double svtod(swoc::TextView text, swoc::TextView * parsed = nullptr);
 // --
 // Inline implementations.
 // Note: Why, you may ask, do I use @c TextView::self_type for return type 
instead of the
diff --git a/code/include/swoc/swoc_ip.h b/code/include/swoc/swoc_ip.h
index 30f7195..4398dd6 100644
--- a/code/include/swoc/swoc_ip.h
+++ b/code/include/swoc/swoc_ip.h
@@ -69,10 +69,10 @@ union IPEndpoint {
 
   /** Break a string in to IP address relevant tokens.
*
-   * @param [in] src Source tex.t
-   * @param [out] host The host / address.
-   * @param [out] port The port.
-   * @param [out] rest Any text past the end of the IP address.
+   * @param src Source text. [in]
+   * @param host The host / address. [out]
+   * @param port The port. [out]
+   * @param rest Any text past the end of the IP address. [out]
* @return @c true if an IP address was found, @c false otherwise.
*
* Any of the out parameters can be @c nullptr in which case they are not 
updated.
diff --git a/code/src/TextView.cc b/code/src/TextView.cc
index 7f1e5e7..5ae6863 100644
--- a/code/src/TextView.cc
+++ b/code/src/TextView.cc
@@ -13,6 +13,8 @@
 #include 
 #include 
 
+using namespace swoc::literals;
+
 int
 memcmp(std::string_view const , std::string_view const )
 {
@@ -162,6 +164,84 @@ svtou(TextView src, TextView *out, int base) {
   return zret;
 }
 
+double svtod(swoc::TextView text, swoc::TextView *parsed) {
+  // @return 10^e
+  auto pow10 = [](int e) -> double  {
+double zret = 1.0;
+double scale = 10.0;
+if (e < 0) { // flip the scale and make @a e positive.
+  e = -e;
+  scale = 0.1;
+}
+
+// Walk the bits in the exponent @a e and multiply the scale for set bits.
+while (e) {
+  if (e & 1) {
+zret *= scale;
+  }
+  scale *= scale;
+  e >>= 1;
+}
+return zret;
+  };
+
+  if (text.empty()) {
+return 0;
+  }
+
+  auto org_text = text; // save this to update @a parsed.
+  // Check just once and dump to a local copy if needed.
+  TextView local_parsed;
+  if (! parsed) {
+parsed = _parsed;
+  }
+
+  // Handle leading sign.
+  int sign = 1;
+  if (*text == '-') {
+++text;
+sign = -1;
+  } else if (*text == '+') {
+++text;
+  }
+  // Parse the leading whole part as an integer.
+  intmax_t whole = svto_radix<10>(text);
+  parsed->assign(org_text.data(), text.data());
+
+  if (text.empty()) {
+return whole;
+  }
+
+  double frac = 0.0;
+  if (*text == '.') { // fractional part.
+++text;
+double scale = 0.1;
+while (text && isdigit(*text)) {
+  frac += scale * (*text++ - '0');
+  scale /= 10.0;
+}
+  }
+
+  double exp = 1.0;
+  if (text.starts_with_nocase("e")) {
+int exp_sign = 1;
+++text;
+if (text) {
+  if (*text == '+') {
+++text;
+  } else if (*text == '-') {
+++text;
+exp_sign = -1;
+  }
+}
+auto exp_part = svto_radix<10>(text);
+exp = pow10(exp_part * exp_sign);
+  }
+
+  parsed->assign(org_text.data(), text.data());
+  return sign * (whole + frac) * exp;
+}
+
 // Do the template instantiations.
 template std::ostream& TextView::stream_write(std::ostream&, const TextView&) 
const;
 
diff --git a/unit_tests/test_IntrusiveHashMap.cc 

(trafficserver-libswoc) 01/02: Update to version 1.2.5.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-5
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 5e0c8cb3b9b7fd4ad0e69440d8b2fc59e67f8e89
Author: Alan M. Carroll 
AuthorDate: Fri May 15 09:04:09 2020 -0500

Update to version 1.2.5.
---
 code/CMakeLists.txt  | 2 +-
 code/include/swoc/swoc_version.h | 4 ++--
 code/libswoc.part| 2 +-
 doc/Doxyfile | 2 +-
 doc/code/IPSpace.en.rst  | 2 +-
 doc/code/TextView.en.rst | 6 +++---
 doc/conf.py  | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index b39f0fd..e4608df 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(Lib-SWOC CXX)
-set(LIBSWOC_VERSION "1.2.4")
+set(LIBSWOC_VERSION "1.2.5")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/code/include/swoc/swoc_version.h b/code/include/swoc/swoc_version.h
index 6e367d1..4287e7b 100644
--- a/code/include/swoc/swoc_version.h
+++ b/code/include/swoc/swoc_version.h
@@ -22,11 +22,11 @@
 #pragma once
 
 #if !defined(SWOC_VERSION_NS)
-#  define SWOC_VERSION_NS _1_2_4
+#  define SWOC_VERSION_NS _1_2_5
 #endif
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 2;
-static constexpr unsigned POINT_VERSION = 4;
+static constexpr unsigned POINT_VERSION = 5;
 }} // namespace SWOC_VERSION_NS
diff --git a/code/libswoc.part b/code/libswoc.part
index aa639d2..df1ac4a 100644
--- a/code/libswoc.part
+++ b/code/libswoc.part
@@ -1,6 +1,6 @@
 Import("*")
 PartName("libswoc")
-PartVersion("1.2.4")
+PartVersion("1.2.5")
 
 src_files = [
 "src/ArenaWriter.cc",
diff --git a/doc/Doxyfile b/doc/Doxyfile
index 096e3c3..f17a3e9 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.2.4"
+PROJECT_NUMBER = "1.2.5"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index ed5fde5..9d3e318 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -170,7 +170,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 8a4c0ba..63cd632 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -275,7 +275,7 @@ separated by commas.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 If :arg:`value` was :literal:`bob  ,dave, sam` then :arg:`token` would be 
successively
 :literal:`bob`, :literal:`dave`, :literal:`sam`. After :literal:`sam` was 
extracted :arg:`value`
@@ -297,7 +297,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, with each 
element being treated as
 a "list" with ``=`` as the separator. Note if there is no ``=`` character then 
all of the list
@@ -348,7 +348,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/conf.py b/doc/conf.py
index 087324b..b447458 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -80,7 +80,7 

(trafficserver-libswoc) branch dev-1-2-5 created (now d0bf7ef)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-2-5
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at d0bf7ef  Add svtod: convert TextView to double.

This branch includes the following new commits:

 new 5e0c8cb  Update to version 1.2.5.
 new d0bf7ef  Add svtod: convert TextView to double.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 01/01: Workaround nullptr reference problem.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch icc-update
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 7b83f2e73c36638e6b626fbb776b327927169ace
Author: Alan M. Carroll 
AuthorDate: Wed Jun 24 14:53:22 2020 -0500

Workaround nullptr reference problem.
---
 code/include/swoc/swoc_ip.h | 9 +
 code/src/swoc_ip.cc | 2 ++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/code/include/swoc/swoc_ip.h b/code/include/swoc/swoc_ip.h
index 79dcd36..59395a3 100644
--- a/code/include/swoc/swoc_ip.h
+++ b/code/include/swoc/swoc_ip.h
@@ -38,6 +38,7 @@ class IP6Net;
 class IPNet;
 
 using ::std::string_view;
+extern void * const fake_nullptr_for_intel_compiler ;
 
 /** A union to hold @c sockaddr compliant IP address structures.
 
@@ -1556,11 +1557,11 @@ public:
 typename IP4Space::iterator _iter_4; ///< IPv4 sub-space iterator.
 typename IP6Space::iterator _iter_6; ///< IPv6 sub-space iterator.
 /// Current value.
-value_type _value{IPRange{}, *null_payload};
+value_type _value{IPRange{}, 
*static_cast(fake_nullptr_for_intel_compiler)};
 
 /// Dummy payload.
 /// @internal Used to initialize @c value_type for invalid iterators.
-static constexpr PAYLOAD *null_payload = nullptr;
+//static constexpr PAYLOAD * const null_payload = nullptr;
 
 /** Internal constructor.
  *
@@ -1731,7 +1732,7 @@ auto IPSpace::const_iterator::operator++() -> 
self_type& {
   return *this;
 }
   }
-  new(&_value) value_type{IPRange{}, *null_payload};
+  new(&_value) value_type{IPRange{}, 
*static_cast(fake_nullptr_for_intel_compiler)};
   return *this;
 }
 
@@ -1754,7 +1755,7 @@ auto IPSpace::const_iterator::operator--() -> 
self_type& {
 new(&_value) value_type{_iter_4->range(), _iter_4->payload()};
 return *this;
   }
-  new(&_value) value_type{IPRange{}, *null_payload};
+  new(&_value) value_type{IPRange{}, 
*static_cast(fake_nullptr_for_intel_compiler)};
   return *this;
 }
 
diff --git a/code/src/swoc_ip.cc b/code/src/swoc_ip.cc
index e9d0dc5..38a2dfb 100644
--- a/code/src/swoc_ip.cc
+++ b/code/src/swoc_ip.cc
@@ -44,6 +44,8 @@ IP6Addr const IP6Addr::MIN{0, 0};
 IP6Addr const IP6Addr::MAX{std::numeric_limits::max()
, std::numeric_limits::max()};
 
+void * const fake_nullptr_for_intel_compiler = 0;
+
 bool
 IPEndpoint::assign(sockaddr *dst, sockaddr const *src) {
   size_t n = 0;



(trafficserver-libswoc) branch icc-update created (now 7b83f2e)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch icc-update
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 7b83f2e  Workaround nullptr reference problem.

This branch includes the following new commits:

 new 7b83f2e  Workaround nullptr reference problem.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 01/01: Fixes for MS compatibility.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch win-compat
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 8f0d4cfdcfb5e9218da060112bef7611af546ea6
Author: Alan M. Carroll 
AuthorDate: Tue Apr 21 07:49:18 2020 -0500

Fixes for MS compatibility.
---
 .idea/codeStyles/codeStyleConfig.xml|  2 +-
 CMakeLists.txt  |  2 +-
 example/CMakeLists.txt  |  4 +++-
 swoc++/CMakeLists.txt   | 30 +
 swoc++/{libswoc++.pc.cmake => libswoc.pc.cmake} |  0
 unit_tests/CMakeLists.txt   |  5 -
 6 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/.idea/codeStyles/codeStyleConfig.xml 
b/.idea/codeStyles/codeStyleConfig.xml
index a55e7a1..79ee123 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,5 @@
 
   
-
+
   
 
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 518ba09..e9b8cae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ add_subdirectory(doc EXCLUDE_FROM_ALL)
 
 # Find all of the directories subject to clang formatting and make a target to 
do the format.
 set(_CLANG_DIRS "")
-get_target_property(_TMP swoc++ CLANG_FORMAT_DIRS)
+get_target_property(_TMP libswoc CLANG_FORMAT_DIRS)
 list(APPEND _CLANG_DIRS ${_TMP})
 get_target_property(_TMP test_libswoc CLANG_FORMAT_DIRS)
 list(APPEND _CLANG_DIRS ${_TMP})
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 07394ab..37e987a 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -8,4 +8,6 @@ add_executable(ex_netdb
 
 target_link_libraries(ex_netdb PUBLIC swoc++)
 set_target_properties(ex_netdb PROPERTIES CLANG_FORMAT_DIRS 
${CMAKE_CURRENT_SOURCE_DIR})
-target_compile_options(ex_netdb PRIVATE -Wall -Wextra -Werror 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
+if(UNIX)
+target_compile_options(ex_netdb PRIVATE -Wall -Wextra -Werror 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
+endif()
diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index 6c9982f..f91a7ea 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
-project(lib-swoc++ CXX)
-set(LIBSWOC_VERSION "1.2.0")
+project(lib-SWOC CXX)
+set(LIBSWOC_VERSION "1.2.1")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
@@ -44,38 +44,40 @@ set(CC_FILES
 src/TextView.cc
 )
 
-add_library(swoc++ STATIC ${CC_FILES})
+add_library(libswoc STATIC ${CC_FILES})
 #add_compile_options(-Wall -Wextra -Werror -Wno-unused-parameter 
-Wno-format-truncation -Wno-stringop-overflow -Wno-invalid-offsetof)
-target_compile_options(swoc++ PRIVATE -Wall -Wextra -Werror -Wnon-virtual-dtor 
-Wno-unused-parameter -Wno-stringop-overflow)
+if(UNIX)
+target_compile_options(libswoc PRIVATE -Wall -Wextra -Werror 
-Wnon-virtual-dtor)
+endif()
 
 # Not quite sure how this works, but I think it generates one of two paths 
depending on the context.
 # That is, the generator functions return non-empty strings only in the 
corresponding context.
-target_include_directories(swoc++
+target_include_directories(libswoc
 PUBLIC
 $
 $
 )
 
 # These install target variables are created by GNUInstallDirs.
-install(TARGETS swoc++
-EXPORT swoc++-config
+install(TARGETS libswoc
+EXPORT libswoc-config
 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
 )
 install(DIRECTORY include/swoc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
 
-install(EXPORT swoc++-config
-NAMESPACE swoc++::
-DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/swoc++
+install(EXPORT libswoc-config
+NAMESPACE libswoc::
+DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libswoc
 )
 
-set(PKG_CONFIG_FILE ${CMAKE_BINARY_DIR}/libswoc++.pc)
-configure_file("libswoc++.pc.cmake" ${PKG_CONFIG_FILE} @ONLY)
+set(PKG_CONFIG_FILE ${CMAKE_BINARY_DIR}/libswoc.pc)
+configure_file("libswoc.pc.cmake" ${PKG_CONFIG_FILE} @ONLY)
 install(FILES ${PKG_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
 # Alledgedly this makes the targets "importable from the build directory" but 
I see no evidence of that.
 # AFAICT the file isn't created at all even with this enabled.
-#export(TARGETS swoc++ FILE libswoc++-config.cmake)
+#export(TARGETS libswoc FILE libswoc-config.cmake)
 
 set(CLANG_DIRS )
 
-set_target_properties(swoc++ PROPERTIES CLANG_FORMAT_DIRS 
"${PROJECT_SOURCE_DIR}/src;${PROJECT_SOURCE_DIR}/include")
+set_target_properties(libswoc PROPERTIES CLANG_FORMAT_DIRS 
"${PROJECT_SOURCE_DIR}/src;${PROJECT_SOURCE_DIR}/include")
diff --git a/swoc++/libswoc++.pc.cmake b/swoc++/libswoc.pc.cmake
similarity index 100%
rename from swoc++/libswoc++.pc.cmake
rename to swoc++/libswoc.pc.cmake
diff --git a/unit_tests/CMakeLists.txt 

(trafficserver-libswoc) branch win-compat created (now 8f0d4cf)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch win-compat
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 8f0d4cf  Fixes for MS compatibility.

This branch includes the following new commits:

 new 8f0d4cf  Fixes for MS compatibility.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 03/05: Autotools: Add LRU cache example.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch lru-cache
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit bc823b1ff51928c9c0902a7df97d9637aed7a0e3
Author: Alan M. Carroll 
AuthorDate: Mon Oct 11 13:06:50 2021 -0500

Autotools: Add LRU cache example.
---
 .gitignore   |  14 +
 Makefile | 756 ++-
 Makefile.am  |   1 +
 code/src/Makefile.am |  16 ++
 configure.ac |   8 +
 example/Makefile.am  |  10 +
 6 files changed, 797 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore
index 335780f..edc81a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@
 example/ex_flat_space
 example/ex_netcompact
 example/ex_netdb
+example/ex_lru_cache
 unit_tests/test_libswoc
 
 # CMake cruft
@@ -28,9 +29,22 @@ CMakeFiles/
 CMakeCache.txt
 cmake-build-debug/
 cmake-build-release/
+cmake-build-clang-debug/
 Makefile
 .idea/
 
+# Autotools cruft
+Makefile.in
+.deps
+config.log
+config.status
+configure
+install-sh
+depcomp
+aclocal.m4
+autom4te.cache
+ar-lib
+
 # Documentation.
 doc/_build
 doc/doxygen
diff --git a/Makefile b/Makefile
index 5039f03..31a379c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,751 @@
+# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.  Generated from Makefile.in by configure.
 
-Pipfile.lock:
-   - pipenv --rm
-   pipenv install
+# Copyright (C) 1994-2018 Free Software Foundation, Inc.
 
-# should pass value of -j to scons
-test: Pipfile.lock
-   pipenv run scons run_utest::
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
 
-all: Pipfile.lock
-   pipenv run scons all
\ No newline at end of file
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+
+am__is_gnu_make = { \
+  if test -z '$(MAKELEVEL)'; then \
+false; \
+  elif test -n '$(MAKE_HOST)'; then \
+true; \
+  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+true; \
+  else \
+false; \
+  fi; \
+}
+am__make_running_with_option = \
+  case $${target_option-} in \
+  ?) ;; \
+  *) echo "am__make_running_with_option: internal error: invalid" \
+  "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+sane_makeflags=$$MFLAGS; \
+  else \
+case $$MAKEFLAGS in \
+  *\\[\ \  ]*) \
+bs=\\; \
+sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+  | sed "s/$$bs$$bs[$$bs $$bs  ]*//g"`;; \
+esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+test $$skip_next = yes && { skip_next=no; continue; }; \
+case $$flg in \
+  *=*|--*) continue;; \
+-*I) strip_trailopt 'I'; skip_next=yes;; \
+  -*I?*) strip_trailopt 'I';; \
+-*O) strip_trailopt 'O'; skip_next=yes;; \
+  -*O?*) strip_trailopt 'O';; \
+-*l) strip_trailopt 'l'; skip_next=yes;; \
+  -*l?*) strip_trailopt 'l';; \
+  -[dEDm]) skip_next=yes;; \
+  -[JT]) skip_next=yes;; \
+esac; \
+case $$flg in \
+  *$$target_option*) has_opt=yes; break;; \
+esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/libswoc
+pkgincludedir = $(includedir)/libswoc
+pkglibdir = $(libdir)/libswoc
+pkglibexecdir = $(libexecdir)/libswoc
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+subdir = .
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+   $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
+   $(am__configure_deps) $(am__DIST_COMMON)
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
+ configure.lineno config.status.lineno
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_$(V))
+am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY))
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_$(V))
+am__v_GEN_ = 

(trafficserver-libswoc) 01/05: LRU Cache - checkpoint.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch lru-cache
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit c22b27453c856c96ce8e11e63ab3c4a586e816d7
Author: Alan M. Carroll 
AuthorDate: Fri Oct 1 10:14:02 2021 -0500

LRU Cache - checkpoint.
---
 code/include/swoc/MemSpan.h |  14 ++---
 code/include/swoc/swoc_ip.h |  31 +-
 example/CMakeLists.txt  |   6 ++
 example/ex_lru_cache.cc | 137 
 unit_tests/test_MemArena.cc |   6 +-
 5 files changed, 183 insertions(+), 11 deletions(-)

diff --git a/code/include/swoc/MemSpan.h b/code/include/swoc/MemSpan.h
index 326a59d..03f26de 100644
--- a/code/include/swoc/MemSpan.h
+++ b/code/include/swoc/MemSpan.h
@@ -49,21 +49,21 @@ public:
   constexpr MemSpan() = default;
 
   /// Copy constructor.
-  constexpr MemSpan(self_type const ) = default;
+  constexpr MemSpan(self_type const &) = default;
 
-  /** Construct from a first element @a start and a @a count of elements.
+  /** Construct from a first element @a ptr and a @a count of elements.
*
-   * @param start First element.
+   * @param ptr First element.
* @param count Total number of elements.
*/
-  constexpr MemSpan(value_type *start, size_t count);
+  constexpr MemSpan(value_type *ptr, size_t count);
 
   /** Construct from a half open range [start, last).
*
* @param start Start of range.
* @param last Past end of range.
*/
-  constexpr MemSpan(value_type *start, value_type *last);
+  constexpr MemSpan(value_type *first, value_type *last);
 
   /** Construct to cover an array.
*
@@ -100,7 +100,7 @@ public:
   bool operator!=(self_type const ) const;
 
   /// Assignment - the span is copied, not the content.
-  self_type =(self_type const ) = default;
+  self_type =(self_type const &) = default;
 
   /// Access element at index @a idx.
   T [](size_t idx) const;
@@ -292,7 +292,7 @@ public:
* @param start Start of the span.
* @param n # of bytes in the span.
*/
-  constexpr MemSpan(value_type *start, size_t n);
+  constexpr MemSpan(value_type *ptr, size_t n);
 
   /** Construct from a half open range of [start, last).
*
diff --git a/code/include/swoc/swoc_ip.h b/code/include/swoc/swoc_ip.h
index df40557..ee87f99 100644
--- a/code/include/swoc/swoc_ip.h
+++ b/code/include/swoc/swoc_ip.h
@@ -459,6 +459,10 @@ public:
   /// Return the address in network order.
   in6_addr network_order() const;
 
+  /// Return the address as words.
+  word_type * words()  { return _addr._store.data(); }
+  word_type const * words() const  { return _addr._store.data(); }
+
   /** Parse a string for an IP address.
 
   The address resuling from the parse is copied to this object if the 
conversion is successful,
@@ -546,7 +550,7 @@ class IPAddr {
   using self_type = IPAddr; ///< Self reference type.
 public:
   IPAddr() = default; ///< Default constructor - invalid result.
-  IPAddr(self_type const& that) = default; ///< Copy constructor.
+  IPAddr(self_type const&) = default; ///< Copy constructor.
 
   /// Construct using IPv4 @a addr.
   explicit IPAddr(in_addr_t addr);
@@ -2946,6 +2950,31 @@ public:
   using type = swoc::IPMask;
 };
 
+template <> struct hash {
+  uint32_t operator() (swoc::IP4Addr const& addr) const { return 
addr.network_order(); }
+};
+
+template <> struct hash {
+  uint32_t operator() (swoc::IP6Addr const& addr) const {
+static_assert(sizeof(swoc::IP6Addr::word_type) == 2 * sizeof(uint32_t));
+// XOR the 64 chunks then XOR that down to 32 bits.
+auto words = addr.words();
+union {
+  swoc::IP6Addr::word_type w;
+  uint32_t n[2];
+} x{words[0] ^ words[1]};
+return x.n[0] ^ x.n[1];
+  }
+};
+
+template <> struct hash {
+  uint32_t operator() (swoc::IPAddr const& addr) const {
+return addr.is_ip4() ? hash()(addr.ip4())
+  : addr.is_ip6() ? hash()(addr.ip6())
+: 0;
+  }
+};
+
 } // namespace std
 /// @endcond
 
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 8d072e0..e1e0563 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -21,3 +21,9 @@ target_link_libraries(ex_flat_space PUBLIC libswoc)
 if (CMAKE_COMPILER_IS_GNUCXX)
 target_compile_options(ex_flat_space PRIVATE -Wall -Wextra -Werror)
 endif()
+
+add_executable(ex_lru_cache ex_lru_cache.cc)
+target_link_libraries(ex_lru_cache PUBLIC libswoc)
+if (CMAKE_COMPILER_IS_GNUCXX)
+target_compile_options(ex_lru_cache PRIVATE -Wall -Wextra -Werror)
+endif()
diff --git a/example/ex_lru_cache.cc b/example/ex_lru_cache.cc
new file mode 100644
index 000..777a150
--- /dev/null
+++ b/example/ex_lru_cache.cc
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright 2020 Verizon Media
+
+/** @file
+
+Example of building a thread safe LRU cache using intrusive containers.
+*/
+
+#include 
+#include 
+#include 
+
+#include "swoc/TextView.h"
+#include "swoc/swoc_ip.h"

(trafficserver-libswoc) 04/05: Testing tweaks.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch lru-cache
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit b110c2b5fe8bf6a72e3dd8148994e2bbe08cd670
Author: Alan M. Carroll 
AuthorDate: Thu Oct 14 13:37:36 2021 -0500

Testing tweaks.
---
 example/ex_lru_cache.cc | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/example/ex_lru_cache.cc b/example/ex_lru_cache.cc
index 10a205e..1fc3a67 100644
--- a/example/ex_lru_cache.cc
+++ b/example/ex_lru_cache.cc
@@ -140,8 +140,8 @@ template  auto LRU::retrieve(K const ) const -
 // --
 
 int main(int, char *[]) {
-  static constexpr size_t N_THREAD = 12; ///< Number of threads.
-  static constexpr size_t N_ITER = 10;
+  static constexpr size_t N_THREAD = 16; ///< Number of threads.
+  static constexpr size_t N_ITER = 2;
 
   std::array threads;
   std::mutex gate_m;
@@ -154,6 +154,7 @@ int main(int, char *[]) {
   };
 
   LRU lru;
+  lru.insert(swoc::IP4Addr{"172.17.56.93"}, Data{time_point(), 2});
 
   auto worker = [&] () -> void {
 unsigned dummy;
@@ -162,8 +163,9 @@ int main(int, char *[]) {
   gate_cv.wait(_, [&] () {return count >= 0; });
 }
 swoc::IP4Addr addr((reinterpret_cast() >> 16) & 
0x);
+auto tp = time_point();
 for ( unsigned i = 0 ; i < N_ITER ; ++i ) {
-  lru.insert(addr, Data{time_point(), 1});
+  lru.insert(addr, Data{tp, 1});
   addr = htonl(addr.host_order() + 1);
 }
 {



(trafficserver-libswoc) 02/05: LRU Cache - ready for testing.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch lru-cache
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 3fbf08c268d9c52fa00da1171a0678ea72d00580
Author: Alan M. Carroll 
AuthorDate: Thu Oct 7 20:57:55 2021 -0500

LRU Cache - ready for testing.
---
 code/include/swoc/IntrusiveDList.h |  4 +-
 example/CMakeLists.txt |  3 +-
 example/ex_lru_cache.cc| 76 +++---
 3 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/code/include/swoc/IntrusiveDList.h 
b/code/include/swoc/IntrusiveDList.h
index fa0bb10..a3070bb 100644
--- a/code/include/swoc/IntrusiveDList.h
+++ b/code/include/swoc/IntrusiveDList.h
@@ -649,7 +649,9 @@ IntrusiveDList::take_head() -> value_type * {
   if (_head) {
 if (nullptr == (_head = L::next_ptr(_head))) {
   _tail = nullptr; // transition non-empty -> empty
-} else { L::prev_ptr(_head) = nullptr; }
+} else {
+  L::prev_ptr(_head) = nullptr;
+}
 L::next_ptr(zret) = L::prev_ptr(zret) = nullptr;
 --_count;
   }
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index e1e0563..af57fc2 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -25,5 +25,6 @@ endif()
 add_executable(ex_lru_cache ex_lru_cache.cc)
 target_link_libraries(ex_lru_cache PUBLIC libswoc)
 if (CMAKE_COMPILER_IS_GNUCXX)
-target_compile_options(ex_lru_cache PRIVATE -Wall -Wextra -Werror)
+target_compile_options(ex_lru_cache PRIVATE -Wall -Wextra -Werror -ggdb3)
+target_link_options(ex_lru_cache PRIVATE -lpthread)
 endif()
diff --git a/example/ex_lru_cache.cc b/example/ex_lru_cache.cc
index 777a150..10a205e 100644
--- a/example/ex_lru_cache.cc
+++ b/example/ex_lru_cache.cc
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "swoc/TextView.h"
 #include "swoc/swoc_ip.h"
@@ -37,8 +38,10 @@ public:
   LRU() = default;
 
   self_type & insert(K const& key, V && value);
+
   self_type & erase(K const& key);
   V retrieve(K const& key) const;
+  size_t count() const { return _table.count(); }
 
 protected:
   struct Item {
@@ -53,17 +56,22 @@ protected:
 
 Links _list;
 Links _map;
+
+Item(self_type && that) : _key(that._key), _value(std::move(that._value)) 
{}
+Item(K const& key, V && value) : _key(key), _value(std::move(value)) {}
+
+self_type & operator = (self_type && that) { _key = that._key; _value = 
std::move(that._value); return *this; }
   };
 
   struct Linkage {
-static Item * next_ptr(Item * item) { return item->_list._next; }
-static Item * prev_ptr(Item * item) { return item->_list._prev; }
+static Item * & next_ptr(Item * item) { return item->_list._next; }
+static Item * & prev_ptr(Item * item) { return item->_list._prev; }
   };
   using List = swoc::IntrusiveDList;
 
   struct Hashing {
-static Item * next_ptr(Item * item) { return item->_map._next; }
-static Item * prev_ptr(Item * item) { return item->_map._prev; }
+static Item * & next_ptr(Item * item) { return item->_map._next; }
+static Item * & prev_ptr(Item * item) { return item->_map._prev; }
 static inline const std::hash Hasher;
 static K const& key_of(Item * item) { return item->_key; }
 static decltype(Hasher(std::declval())) hash_of(K const& key) { return 
Hasher(key); }
@@ -87,11 +95,17 @@ template  auto LRU::insert(K 
const , V &
 if (spot != _table.end()) {
   spot->_value = std::move(value);
 } else {
-  auto *item = _arena.make(key, std::move(value));
+  Item * item = _free.take_head();
+  if (item != nullptr) {
+new (item) Item(key, std::move(value));
+  } else {
+item = _arena.make(key, std::move(value));
+  }
   _table.insert(item);
   _list.append(item);
-  if (_list.size() > _max) {
+  if (_list.count() > _max) {
 target = _list.take_head();
+_table.erase(target);
   }
 }
   }
@@ -126,6 +140,14 @@ template  auto LRU::retrieve(K const ) const -
 // --
 
 int main(int, char *[]) {
+  static constexpr size_t N_THREAD = 12; ///< Number of threads.
+  static constexpr size_t N_ITER = 10;
+
+  std::array threads;
+  std::mutex gate_m;
+  std::condition_variable gate_cv;
+  std::atomic count = -1;
+
   struct Data {
 time_point _expire;
 int _code = 0;
@@ -133,5 +155,47 @@ int main(int, char *[]) {
 
   LRU lru;
 
+  auto worker = [&] () -> void {
+unsigned dummy;
+{
+  std::unique_lock _(gate_m);
+  gate_cv.wait(_, [&] () {return count >= 0; });
+}
+swoc::IP4Addr addr((reinterpret_cast() >> 16) & 
0x);
+for ( unsigned i = 0 ; i < N_ITER ; ++i ) {
+  lru.insert(addr, Data{time_point(), 1});
+  addr = htonl(addr.host_order() + 1);
+}
+{
+  std::unique_lock _(gate_m);
+  ++count;
+}
+gate_cv.notify_all();
+  };
+
+  for ( unsigned i = 

(trafficserver-libswoc) 05/05: Tweak.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch lru-cache
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 17d4eceb076ac5ff50165ce5aaf05c6ac4a807e3
Author: Alan M. Carroll 
AuthorDate: Wed Nov 3 14:55:25 2021 -0500

Tweak.
---
 example/ex_lru_cache.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/example/ex_lru_cache.cc b/example/ex_lru_cache.cc
index 1fc3a67..9f569b6 100644
--- a/example/ex_lru_cache.cc
+++ b/example/ex_lru_cache.cc
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: Apache-2.0
-// Copyright 2020 Verizon Media
+// Copyright 2021 LinkedIn
 
 /** @file
 



(trafficserver-libswoc) branch lru-cache created (now 17d4ece)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch lru-cache
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 17d4ece  Tweak.

This branch includes the following new commits:

 new c22b274  LRU Cache - checkpoint.
 new 3fbf08c  LRU Cache - ready for testing.
 new bc823b1  Autotools: Add LRU cache example.
 new b110c2b  Testing tweaks.
 new 17d4ece  Tweak.

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) branch memarena-static-block created (now 58f8a15)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch memarena-static-block
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 58f8a15  Add static block support to MemArena.

This branch includes the following new commits:

 new 58f8a15  Add static block support to MemArena.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 01/01: Add static block support to MemArena.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch memarena-static-block
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 58f8a15a2b6b7978655cab2b123ea2a0f4f90609
Author: Alan M. Carroll 
AuthorDate: Tue Mar 9 16:43:32 2021 -0600

Add static block support to MemArena.
---
 code/include/swoc/MemArena.h | 13 +
 code/include/swoc/Scalar.h   |  8 
 code/src/MemArena.cc | 34 +-
 doc/code/MemArena.en.rst | 38 +++---
 unit_tests/test_MemArena.cc  | 31 +++
 5 files changed, 112 insertions(+), 12 deletions(-)

diff --git a/code/include/swoc/MemArena.h b/code/include/swoc/MemArena.h
index 8ac8351..d63f2d5 100644
--- a/code/include/swoc/MemArena.h
+++ b/code/include/swoc/MemArena.h
@@ -167,6 +167,16 @@ public:
*/
   explicit MemArena(size_t n = DEFAULT_BLOCK_SIZE);
 
+  /** Construct using static block.
+   *
+   * @param static_block A block of memory that is non-deletable.
+   *
+   * @a static_block is used as the first block for allocation and is never 
deleted. This makes
+   * it possible to have an instance that allocates from stack memory and only 
allocates from the
+   * heap if the static block becomes full.
+   */
+  explicit MemArena(MemSpan static_block);
+
   /// no copying
   MemArena(self_type const& that) = delete;
 
@@ -379,6 +389,9 @@ protected:
   BlockList _frozen; ///< Previous generation, frozen memory.
   BlockList _active; ///< Current generation. Allocate here.
 
+  /// Static block, if any.
+  Block* _static_block = nullptr;
+
   // Note on _active block list - blocks that become full are moved to the end 
of the list.
   // This means that when searching for a block with space, the first full 
block encountered
   // marks the last block to check. This keeps the set of blocks to check 
short.
diff --git a/code/include/swoc/Scalar.h b/code/include/swoc/Scalar.h
index 276d013..25df940 100644
--- a/code/include/swoc/Scalar.h
+++ b/code/include/swoc/Scalar.h
@@ -293,10 +293,10 @@ public:
   constexpr Counter count() const;
 
   /// The scaled value.
-  constexpr intmax_t value() const;
+  constexpr Counter value() const;
 
   /// User conversion to scaled value.
-  constexpr operator intmax_t() const;
+  constexpr operator Counter() const;
 
   /// Addition operator.
   /// The value is scaled from @a that to @a this.
@@ -416,12 +416,12 @@ Scalar::count() const -> Counter {
 }
 
 template
-constexpr intmax_t
+constexpr C
 Scalar::value() const {
   return _n * SCALE;
 }
 
-template constexpr Scalar::operator intmax_t() const {
+template constexpr Scalar::operator C() const {
   return _n * SCALE;
 }
 
diff --git a/code/src/MemArena.cc b/code/src/MemArena.cc
index a46b1a8..8db4996 100644
--- a/code/src/MemArena.cc
+++ b/code/src/MemArena.cc
@@ -15,6 +15,19 @@ inline bool MemArena::Block::satisfies(size_t n, size_t 
align) const {
   return r >= (n + align_padding(this->data() + allocated, align));
 }
 
+MemArena::MemArena(MemSpan static_block) {
+  static constexpr Scalar<16, size_t> MIN_BLOCK_SIZE = round_up(sizeof(Block) 
+ Block::MIN_FREE_SPACE);
+  if (static_block.size() < MIN_BLOCK_SIZE) {
+throw std::domain_error("MemArena static block is too small.");
+  }
+  // Construct the block data in the block and put it on the list. Make a note 
this is the
+  // static block that shouldn't be deleted.
+  auto space = static_block.size() - sizeof(Block);
+  _static_block = new (static_block.data()) Block(space);
+  _active_reserved = space;
+  _active.prepend(_static_block);
+}
+
 // Need to break these out because the default implementation doesn't clear the
 // integral values in @a that.
 
@@ -22,10 +35,13 @@ MemArena::MemArena(swoc::MemArena::self_type&& that)
 : _active_allocated(that._active_allocated), 
_active_reserved(that._active_reserved)
   , _frozen_allocated(that._frozen_allocated), 
_frozen_reserved(that._frozen_reserved)
   , _reserve_hint(that._reserve_hint), _frozen(std::move(that._frozen))
-  , _active(std::move(that._active)) {
+  , _active(std::move(that._active))
+  , _static_block(that._static_block) {
+  // Clear data in @a that to indicate all of the memory has been moved.
   that._active_allocated = that._active_reserved = 0;
   that._frozen_allocated = that._frozen_reserved = 0;
   that._reserve_hint = 0;
+  that._static_block = nullptr;
 }
 
 MemArena *
@@ -110,6 +126,11 @@ MemArena&
 MemArena::thaw() {
   this->destroy_frozen();
   _frozen_reserved = _frozen_allocated = 0;
+  if (_static_block) {
+_static_block->discard();
+_active.prepend(_static_block);
+_active_reserved += _static_block->remaining();
+  }
   return *this;
 }
 
@@ -152,12 +173,12 @@ MemArena::require(size_t n, size_t align) {
 
 void
 MemArena::destroy_active() {
-  _active.apply([](Block *b) { delete b; }).clear();
+  _active.apply([=](Block 

(trafficserver-libswoc) 02/03: IPSpace: update to use struct instead of tuple.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch github-build
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 3b300250e02de64b2981e75a00aaf874366813b3
Author: Alan M. Carroll 
AuthorDate: Sun Jun 4 10:02:21 2023 -0500

IPSpace: update to use struct instead of tuple.
---
 code/include/swoc/IPRange.h | 335 ++--
 code/include/swoc/Lexicon.h |   2 +-
 unit_tests/ex_Lexicon.cc|   4 +-
 unit_tests/ex_ipspace_properties.cc |   4 +-
 unit_tests/test_ip.cc   | 110 ++--
 5 files changed, 301 insertions(+), 154 deletions(-)

diff --git a/code/include/swoc/IPRange.h b/code/include/swoc/IPRange.h
index aa93d17..cf9b66c 100644
--- a/code/include/swoc/IPRange.h
+++ b/code/include/swoc/IPRange.h
@@ -8,22 +8,19 @@
 
 #include 
 #include  // for std::monostate
+#include 
 
 #include 
 #include 
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 
-using ::std::string_view;
+using std::string_view;
 
 class IP4Net;
 class IP6Net;
 class IPNet;
 
-namespace detail {
-extern void *const pseudo_nullptr;
-}
-
 /** An inclusive range of IPv4 addresses.
  */
 class IP4Range : public DiscreteRange {
@@ -335,6 +332,7 @@ public:
* @param max Maximum range value.
*/
   IPRange(IP4Addr const , IP4Addr const );
+
   /** Construct an inclusive range.
*
* @param min Minimum range value.
@@ -346,8 +344,8 @@ public:
*
* @param addr Address of range.
*/
-
   IPRange(IPAddr const& addr) : IPRange(addr, addr) {}
+
   /** Construct a singleton range.
*
* @param addr Address of range.
@@ -366,7 +364,6 @@ public:
   /// Construct from an IPv6 @a range.
   IPRange(IP6Range const );
 
-
   /** Construct from a string format.
*
* @param text Text form of range.
@@ -384,16 +381,10 @@ public:
   bool operator!=(self_type const& that) const;
 
   /// @return @c true if this is an IPv4 range, @c false if not.
-  bool
-  is_ip4() const {
-return AF_INET == _family;
-  }
+  bool is_ip4() const;
 
   /// @return @c true if this is an IPv6 range, @c false if not.
-  bool
-  is_ip6() const {
-return AF_INET6 == _family;
-  }
+  bool is_ip6() const;
 
   /** Check if @a this range is the IP address @a family.
*
@@ -421,6 +412,9 @@ public:
   /// @return @c true if there are no addresses in the range.
   bool empty() const;
 
+  /// Make the range empty / invalid.
+  self_type & clear();
+
   /// @return The IPv4 range.
   IP4Range const & ip4() const { return _range._ip4; }
 
@@ -438,6 +432,7 @@ public:
*/
   IPMask network_mask() const;
 
+  /// Container for remaining range for network generation.
   class NetSource;
 
   /** Generate a list of networks covering @a this range.
@@ -473,6 +468,7 @@ protected:
 IP4Range _ip4;   ///< IPv4 range.
 IP6Range _ip6;   ///< IPv6 range.
   } _range{std::monostate{}};
+
   /// Family of @a _range.
   sa_family_t _family{AF_UNSPEC};
 };
@@ -533,6 +529,7 @@ protected:
 IP4Range::NetSource _ip4; ///< IPv4 addresses.
 IP6Range::NetSource _ip6; ///< IPv6 addresses.
   };
+
   sa_family_t _family = AF_UNSPEC; ///< Mark for union content.
 };
 
@@ -730,21 +727,20 @@ public:
   /// @return A range that exactly covers the network.
   IPRange as_range() const;
 
+  /// @return @c true if network is IPv4.
   bool is_ip4() const { return _addr.is_ip4(); }
 
+  /// @return @c true if network is IPv6.
   bool is_ip6() const { return _addr.is_ip6(); }
 
+  /// Address family of network.
   sa_family_t family() const { return _addr.family(); }
 
-  IP4Net
-  ip4() const {
-return IP4Net{_addr.ip4(), _mask};
-  }
+  /// @return The network as explicitly IPv4.
+  IP4Net ip4() const;
 
-  IP6Net
-  ip6() const {
-return IP6Net{_addr.ip6(), _mask};
-  }
+  /// @return The network as explicitly IPv6.
+  IP6Net ip6() const;
 
   /** Assign an @a addr and @a mask to @a this.
*
@@ -755,11 +751,7 @@ public:
   self_type (IPAddr const , IPMask const );
 
   /// Reset network to invalid state.
-  self_type &
-  clear() {
-_mask.clear();
-return *this;
-  }
+  self_type & clear();
 
   /// Equality.
   bool operator==(self_type const ) const;
@@ -773,6 +765,105 @@ protected:
 };
 
 // --
+namespace detail {
+/** Value type for @c IPSpace.
+ *
+ * @tparam PAYLOAD User data type to be stored.
+ *
+ * @internal Exported because inner classes in template classes cannot be used 
in partial
+ * specialization which is required for tuple support. This should be removed 
next API incompatible
+ * change release because tuple access is being deprecated.
+ *
+ * @note The @c assign methods are used to update iterators.
+ *
+ * @see IPSpace
+ */
+template < typename PAYLOAD > struct ip_space_value_type {
+  using self_type = ip_space_value_type;
+
+  swoc::IPRange _range; ///< Address range.
+  PAYLOAD * 

(trafficserver-libswoc) 01/03: Create cmake.yml

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch github-build
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit fc9bb9770027c10f78c41b802de0a9ee989526e7
Author: Alan M. Carroll 
AuthorDate: Fri Jun 2 12:48:26 2023 -0500

Create cmake.yml
---
 .github/workflows/cmake.yml | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml
new file mode 100644
index 000..a8fdb2a
--- /dev/null
+++ b/.github/workflows/cmake.yml
@@ -0,0 +1,38 @@
+name: CMake
+
+on:
+  push:
+branches: [ "master" ]
+  pull_request:
+branches: [ "master" ]
+
+env:
+  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
+  BUILD_TYPE: Release
+
+jobs:
+  build:
+# The CMake configure and build commands are platform agnostic and should 
work equally well on Windows or Mac.
+# You can convert this to a matrix build if you need cross-platform 
coverage.
+# See: 
https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
+runs-on: ubuntu-latest
+
+steps:
+- uses: actions/checkout@v3
+
+- name: Configure CMake
+  # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only 
required if you are using a single-configuration generator such as make.
+  # See 
https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
+  run: cmake -B ${{github.workspace}}/build 
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
+
+- name: Build
+  # Build your program with the given configuration
+  run: cmake --build ${{github.workspace}}/build --config 
${{env.BUILD_TYPE}}
+
+- name: Test
+  working-directory: ${{github.workspace}}
+  # Execute tests defined by the CMake configuration.
+  # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more 
detail
+  # run: ctest -C ${{env.BUILD_TYPE}}
+  run: ${{github.workspace}}/build/unit_tests/test_libswoc
+



(trafficserver-libswoc) 03/03: Update to 1.4.12.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch github-build
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 6c34a26929ac685e6d04df90fda3b38db1d273bb
Author: Alan M. Carroll 
AuthorDate: Mon Jun 5 12:06:37 2023 -0500

Update to 1.4.12.
---
 code/CMakeLists.txt  | 2 +-
 code/include/swoc/swoc_version.h | 4 ++--
 code/libswoc.part| 2 +-
 doc/Doxyfile | 2 +-
 doc/code/TextView.en.rst | 4 ++--
 doc/code/ip_networking.en.rst| 2 +-
 doc/conf.py  | 2 +-
 tools/ats-drop.sh| 2 +-
 8 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index e2ba2e0..5ead048 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.11)
 
 project(Lib-SWOC CXX)
-set(LIBSWOC_VERSION "1.4.11")
+set(LIBSWOC_VERSION "1.4.12")
 set(CMAKE_CXX_STANDARD 17)
 cmake_policy(SET CMP0087 NEW)
 # override "lib64" to be "lib" unless the user explicitly sets it.
diff --git a/code/include/swoc/swoc_version.h b/code/include/swoc/swoc_version.h
index 2b1cad0..b111e0d 100644
--- a/code/include/swoc/swoc_version.h
+++ b/code/include/swoc/swoc_version.h
@@ -23,11 +23,11 @@
 #pragma once
 
 #if !defined(SWOC_VERSION_NS)
-#define SWOC_VERSION_NS _1_4_11
+#define SWOC_VERSION_NS _1_4_12
 #endif
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 4;
-static constexpr unsigned POINT_VERSION = 11;
+static constexpr unsigned POINT_VERSION = 12;
 }} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/libswoc.part b/code/libswoc.part
index 2f48b9d..3a256dc 100644
--- a/code/libswoc.part
+++ b/code/libswoc.part
@@ -1,6 +1,6 @@
 Import("*")
 PartName("libswoc")
-PartVersion("1.4.11")
+PartVersion("1.4.12")
 
 src_files = [
 "src/ArenaWriter.cc",
diff --git a/doc/Doxyfile b/doc/Doxyfile
index e00dfdf..4cb958b 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.4.11"
+PROJECT_NUMBER = "1.4.12"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 7e34be2..dcfe705 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -343,7 +343,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, extracting each 
comma separated
 element. The resulting element is treated as a "list" with ``=`` as the 
separator. Note if there is
@@ -395,7 +395,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/code/ip_networking.en.rst b/doc/code/ip_networking.en.rst
index 491b6c6..39765c7 100644
--- a/doc/code/ip_networking.en.rst
+++ b/doc/code/ip_networking.en.rst
@@ -217,7 +217,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/conf.py b/doc/conf.py
index 8699e4d..a248dea 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -79,7 +79,7 @@ project = u'Solid Wall Of C++'
 copyright = u'{}, a...@apache.org'.format(date.today().year)
 
 # The full version, including alpha/beta/rc tags.
-release = "1.4.11"
+release = "1.4.12"
 # The short X.Y version.
 version = '.'.join(release.split('.', 2)[:2])
 
diff --git a/tools/ats-drop.sh b/tools/ats-drop.sh
index 61624d5..0cce59e 100644

(trafficserver-libswoc) branch github-build created (now 6c34a26)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch github-build
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 6c34a26  Update to 1.4.12.

This branch includes the following new commits:

 new fc9bb97  Create cmake.yml
 new 3b30025  IPSpace: update to use struct instead of tuple.
 new 6c34a26  Update to 1.4.12.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 07/08: Remove unused code from Unit Parser example.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 4499a8d31b0535ab1593bdc30ad5c174149957a8
Author: Alan M. Carroll 
AuthorDate: Fri Nov 13 15:01:12 2020 -0600

Remove unused code from Unit Parser example.
---
 unit_tests/ex_UnitParser.cc | 20 
 1 file changed, 20 deletions(-)

diff --git a/unit_tests/ex_UnitParser.cc b/unit_tests/ex_UnitParser.cc
index 60ab3d1..a05cc12 100644
--- a/unit_tests/ex_UnitParser.cc
+++ b/unit_tests/ex_UnitParser.cc
@@ -24,26 +24,6 @@ template < typename ... Args > Errata Error(TextView const& 
fmt, Args && ... arg
   return Errata{}.note_v(swoc::Severity::ERROR, fmt, 
std::forward_as_tuple(args...));
 }
 
-# if 0
-/** Extract and remove the next token.
- *
- * @tparam PRED Predicate function type - @c bool(char)
- * @param src Input text.
- * @param pred Predicate function.
- * @return The token.
- *
- * The token is the prefix of @a src for which @a pred is true.
- */
-template < typename PRED > inline TextView take_token_if(TextView , PRED 
const& pred) {
-  size_t idx = 0;
-  for (auto spot = src.data(), limit = spot + src.size() ; spot < limit && 
pred(*spot); ++spot, ++idx )
-; // empty
-  TextView token = src.prefix(idx);
-  src.remove_prefix(idx);
-  return token;
-}
-# endif
-
 } // namespace
 
 /** Parse a string that consists of counts and units.



(trafficserver-libswoc) branch master created (now 3e635a1)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 3e635a1  Update to 1.5.10

This branch includes the following new commits:

 new 3e635a1  Update to 1.5.10

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 01/01: Update to 1.5.10

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

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

commit 3e635a1aba2847c062ec8fdfcae09b0a4e5a2523
Author: Alan M. Carroll 
AuthorDate: Mon Dec 18 12:12:47 2023 -0600

Update to 1.5.10
---
 code/CMakeLists.txt  | 2 +-
 code/include/swoc/swoc_version.h | 4 ++--
 code/libswoc.part| 2 +-
 doc/Doxyfile | 2 +-
 doc/code/TextView.en.rst | 4 ++--
 doc/code/ip_networking.en.rst| 2 +-
 doc/conf.py  | 2 +-
 7 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index 5ab70bd..f4361be 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.11)
 
 project(Lib-SWOC CXX)
-set(LIBSWOC_VERSION "1.5.9")
+set(LIBSWOC_VERSION "1.5.10")
 set(CMAKE_CXX_STANDARD 17)
 cmake_policy(SET CMP0087 NEW)
 # override "lib64" to be "lib" unless the user explicitly sets it.
diff --git a/code/include/swoc/swoc_version.h b/code/include/swoc/swoc_version.h
index c51c2a4..744ea0d 100644
--- a/code/include/swoc/swoc_version.h
+++ b/code/include/swoc/swoc_version.h
@@ -23,11 +23,11 @@
 #pragma once
 
 #if !defined(SWOC_VERSION_NS)
-#define SWOC_VERSION_NS _1_5_9
+#define SWOC_VERSION_NS _1_5_10
 #endif
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 5;
-static constexpr unsigned POINT_VERSION = 9;
+static constexpr unsigned POINT_VERSION = 10;
 }} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/libswoc.part b/code/libswoc.part
index 37d384e..b9ea9e6 100644
--- a/code/libswoc.part
+++ b/code/libswoc.part
@@ -1,6 +1,6 @@
 Import("*")
 PartName("libswoc")
-PartVersion("1.5.9")
+PartVersion("1.5.10")
 
 src_files = [
 "src/ArenaWriter.cc",
diff --git a/doc/Doxyfile b/doc/Doxyfile
index d90bc00..258e0bf 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.5.9"
+PROJECT_NUMBER = "1.5.10"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 6596282..8a4ad9a 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -366,7 +366,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, extracting each 
comma separated
 element. The resulting element is treated as a "list" with ``=`` as the 
separator. Note if there is
@@ -418,7 +418,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/code/ip_networking.en.rst b/doc/code/ip_networking.en.rst
index c8869d9..13a02b5 100644
--- a/doc/code/ip_networking.en.rst
+++ b/doc/code/ip_networking.en.rst
@@ -265,7 +265,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/conf.py b/doc/conf.py
index 01ce34b..d937c48 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -79,7 +79,7 @@ project = u'Solid Wall Of C++'
 copyright = u'{}, a...@apache.org'.format(date.today().year)
 
 # The full version, including alpha/beta/rc tags.
-release = "1.5.9"
+release = "1.5.10"
 # The short X.Y version.
 version = '.'.join(release.split('.', 2)[:2])
 



(trafficserver-libswoc) 06/08: Fix typos.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 3513d8e0e0050b16dfe304661d63b1e3ef723f52
Author: Alan M. Carroll 
AuthorDate: Fri Nov 13 15:00:11 2020 -0600

Fix typos.
---
 code/include/swoc/bwf_base.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/code/include/swoc/bwf_base.h b/code/include/swoc/bwf_base.h
index 43b7d70..6674dc8 100644
--- a/code/include/swoc/bwf_base.h
+++ b/code/include/swoc/bwf_base.h
@@ -593,7 +593,7 @@ Arg_Formatter(BufferWriter& w, Spec const& spec, TUPLE 
const& args) {
 }
 
 /// This exists only to expand the index sequence into an array of formatters 
for the tuple type
-/// @a TUPLE.  Due to langauge limitations it cannot be done directly. The 
formatters can be
+/// @a TUPLE.  Due to language limitations it cannot be done directly. The 
formatters can be
 /// accessed via standard array access in contrast to templated tuple access. 
The actual array is
 /// static and therefore at run time the only operation is loading the address 
of the array.
 template



(trafficserver-libswoc) 01/08: Update to 1.2.13.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 5987ae03ba2cb2c45fe1def8a7e4a95dfba5712f
Author: Alan M. Carroll 
AuthorDate: Mon Oct 26 12:21:51 2020 -0500

Update to 1.2.13.
---
 code/CMakeLists.txt  | 2 +-
 code/include/swoc/swoc_version.h | 4 ++--
 code/libswoc.part| 2 +-
 doc/Doxyfile | 2 +-
 doc/code/IPSpace.en.rst  | 2 +-
 doc/code/TextView.en.rst | 6 +++---
 doc/conf.py  | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index 12cd5be..b57ad86 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(Lib-SWOC CXX)
-set(LIBSWOC_VERSION "1.2.12")
+set(LIBSWOC_VERSION "1.2.13")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/code/include/swoc/swoc_version.h b/code/include/swoc/swoc_version.h
index d59a222..8650a70 100644
--- a/code/include/swoc/swoc_version.h
+++ b/code/include/swoc/swoc_version.h
@@ -22,11 +22,11 @@
 #pragma once
 
 #if !defined(SWOC_VERSION_NS)
-#  define SWOC_VERSION_NS _1_2_12
+#  define SWOC_VERSION_NS _1_2_13
 #endif
 
 namespace swoc { inline namespace SWOC_VERSION_NS {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 2;
-static constexpr unsigned POINT_VERSION = 12;
+static constexpr unsigned POINT_VERSION = 13;
 }} // namespace SWOC_VERSION_NS
diff --git a/code/libswoc.part b/code/libswoc.part
index cef4283..2eded9e 100644
--- a/code/libswoc.part
+++ b/code/libswoc.part
@@ -1,6 +1,6 @@
 Import("*")
 PartName("libswoc")
-PartVersion("1.2.12")
+PartVersion("1.2.13")
 
 src_files = [
 "src/ArenaWriter.cc",
diff --git a/doc/Doxyfile b/doc/Doxyfile
index 858c6cf..e007e30 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME   = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER = "1.2.12"
+PROJECT_NUMBER = "1.2.13"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/code/IPSpace.en.rst b/doc/code/IPSpace.en.rst
index bd4db81..63147dc 100644
--- a/doc/code/IPSpace.en.rst
+++ b/doc/code/IPSpace.en.rst
@@ -186,7 +186,7 @@ Blending Bitsets
 
Some details are omitted for brevity and because they aren't directly 
relevant. The full
implementation, which is run as a unit test to verify its correctness,
-   `is available here 
`__.
+   `is available here 
`__.
You can compile and step through the code to see how it works in more 
detail, or experiment
with changing some of the example data.
 
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 7681f1d..2030aff 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -278,7 +278,7 @@ separated by commas.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 If :arg:`value` was :literal:`bob  ,dave, sam` then :arg:`token` would be 
successively
 :literal:`bob`, :literal:`dave`, :literal:`sam`. After :literal:`sam` was 
extracted :arg:`value`
@@ -300,7 +300,7 @@ for values that are boolean.
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 The basic list processing is the same as the previous example, with each 
element being treated as
 a "list" with ``=`` as the separator. Note if there is no ``=`` character then 
all of the list
@@ -351,7 +351,7 @@ do not, so a flag to strip quotes from the resulting 
elements is needed. The fin
 
 .. sidebar:: Verification
 
-   `Test code for example 
`__.
+   `Test code for example 
`__.
 
 This takes a :code:`TextView&` which is the source view which will be updated 
as tokens are removed
 (therefore the caller must do the empty view check). The other arguments are 
the separator character
diff --git a/doc/conf.py b/doc/conf.py
index 666ab41..cda3820 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ 

(trafficserver-libswoc) 08/08: Fix bugs in MemSpan prefix, suffix methods.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 338f76174ef8c3a5d16445f1534aabf46cd83c2c
Author: Alan M. Carroll 
AuthorDate: Wed Nov 18 18:26:34 2020 -0600

Fix bugs in MemSpan prefix, suffix methods.
---
 code/include/swoc/MemSpan.h |  6 +++---
 unit_tests/test_MemSpan.cc  | 22 ++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/code/include/swoc/MemSpan.h b/code/include/swoc/MemSpan.h
index 4bc63d2..97bb523 100644
--- a/code/include/swoc/MemSpan.h
+++ b/code/include/swoc/MemSpan.h
@@ -879,7 +879,7 @@ MemSpan::prefix(size_t n) const {
 
 inline MemSpan &
 MemSpan::remove_prefix(size_t n) {
-  n = std::max(_size, n);
+  n = std::min(_size, n);
   _size -= n;
   _ptr = static_cast(_ptr) + n;
   return *this;
@@ -887,13 +887,13 @@ MemSpan::remove_prefix(size_t n) {
 
 inline MemSpan
 MemSpan::suffix(size_t count) const {
-  count = std::max(count, _size);
+  count = std::min(count, _size);
   return {static_cast(this->data_end()) - count, count};
 }
 
 inline MemSpan &
 MemSpan::remove_suffix(size_t count) {
-  _size -= std::max(count, _size);
+  _size -= std::min(count, _size);
   return *this;
 }
 
diff --git a/unit_tests/test_MemSpan.cc b/unit_tests/test_MemSpan.cc
index 2808daa..64aaf72 100644
--- a/unit_tests/test_MemSpan.cc
+++ b/unit_tests/test_MemSpan.cc
@@ -39,6 +39,7 @@ TEST_CASE("MemSpan", "[libswoc][MemSpan]")
 
   left.assign(buff, sizeof(buff));
   span = left.suffix(768);
+  REQUIRE(span.size() == 768);
   left.remove_suffix(768);
   REQUIRE(left.end() == span.begin());
   REQUIRE(left.size() + span.size() == 1024);
@@ -90,3 +91,24 @@ TEST_CASE("MemSpan", "[libswoc][MemSpan]")
   REQUIRE(fspan.count() == f2span.count());
   REQUIRE(fspan.is_same(f2span));
 };
+
+TEST_CASE("MemSpan", "[libswoc][MemSpan]")
+{
+  char buff[1024];
+
+  MemSpan span(buff, sizeof(buff));
+  auto left = span.prefix(512);
+  REQUIRE(left.size() == 512);
+  REQUIRE(span.size() == 1024);
+  span.remove_prefix(512);
+  REQUIRE(span.size() == 512);
+  REQUIRE(left.data_end() == span.data());
+
+  left.assign(buff, sizeof(buff));
+  span = left.suffix(700);
+  REQUIRE(span.size() == 700);
+  left.remove_suffix(700);
+  REQUIRE(left.data_end() == span.data());
+  REQUIRE(left.size() + span.size() == 1024);
+
+};



(trafficserver-libswoc) 05/08: Add "0b" for binary prefix checking to svtoi.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 85b5f2d090d547d9126173945733db29da810ae4
Author: Alan M. Carroll 
AuthorDate: Thu Nov 5 14:49:53 2020 -0600

Add "0b" for binary prefix checking to svtoi.
---
 code/src/TextView.cc| 28 ++--
 unit_tests/test_TextView.cc |  1 +
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/code/src/TextView.cc b/code/src/TextView.cc
index 5ae6863..4759f2a 100644
--- a/code/src/TextView.cc
+++ b/code/src/TextView.cc
@@ -86,7 +86,7 @@ intmax_t
 svtoi(TextView src, TextView *out, int base) {
   intmax_t zret = 0;
 
-  if (src.ltrim_if() && src) {
+  if (src.ltrim_if()) {
 TextView parsed;
 const char *start = src.data();
 bool neg = false;
@@ -128,21 +128,29 @@ svtou(TextView src, TextView *out, int base) {
   if ('0' == *src) {
 ++src;
 base = 8;
-if (src && ('x' == *src || 'X' == *src)) {
-  ++src;
-  base = 16;
+if (src) {
+  switch (*src) {
+case 'x':
+case 'X':
+  ++src;
+  base = 16;
+  break;
+case 'b':
+case 'B':
+  ++src;
+  base = 2;
+  break;
+  }
 }
   }
 }
 
 // For performance in common cases, use the templated conversion.
 switch (base) {
-  case 8:zret = svto_radix<8>(src);
-break;
-  case 10:zret = svto_radix<10>(src);
-break;
-  case 16:zret = svto_radix<16>(src);
-break;
+  case 2: zret = svto_radix<2>(src); break;
+  case 8: zret = svto_radix<8>(src); break;
+  case 10: zret = svto_radix<10>(src); break;
+  case 16: zret = svto_radix<16>(src); break;
   default:
 while (src.size() && (0 <= (v = svtoi_convert[static_cast(*src)])) &&
v < base) {
diff --git a/unit_tests/test_TextView.cc b/unit_tests/test_TextView.cc
index 4b914f3..b8a29e5 100644
--- a/unit_tests/test_TextView.cc
+++ b/unit_tests/test_TextView.cc
@@ -385,6 +385,7 @@ TEST_CASE("TextView Conversions", "[libswoc][TextView]")
   REQUIRE(2345679 == svtoi(n8));
   REQUIRE(2345679 == svtoi(n8, ));
   REQUIRE(x == n8);
+  REQUIRE(0b10111 == svtoi("0b10111"_tv));
 
   x = n4;
   REQUIRE(13 == swoc::svto_radix<10>(x));



(trafficserver-libswoc) 03/08: TextView: add "clip_prefix_of" and "clip_suffix_of".

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit dc659e5d04fa9d79fccf0331fd949bdd669ce8b1
Author: Alan M. Carroll 
AuthorDate: Fri Oct 30 14:32:14 2020 -0500

TextView: add "clip_prefix_of" and "clip_suffix_of".
---
 code/include/swoc/TextView.h | 48 +---
 doc/code/TextView.en.rst |  8 
 unit_tests/ex_UnitParser.cc  |  6 --
 3 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/code/include/swoc/TextView.h b/code/include/swoc/TextView.h
index e40a9a8..78aded2 100644
--- a/code/include/swoc/TextView.h
+++ b/code/include/swoc/TextView.h
@@ -367,6 +367,8 @@ public:
* @tparam F Predicate function type.
* @param pred The predicate instance.
* @return @a this.
+   *
+   * Characters are removed until @a pred returns @c true. The matching 
character is also removed.
*/
   template  self_type _prefix_if(F const );
 
@@ -483,6 +485,17 @@ public:
*/
   template  self_type take_prefix_if(F const );
 
+  /** Remove and return a prefix of characters satisfying @a pred
+   *
+   * @tparam F Predicate functor type.
+   * @param pred A function taking @c char and returning @c bool.
+   * @return The prefix of characters that satisfy @a pred.
+   *
+   * The returned prefix is removed from @a this. That prefix may be empty if 
the first character
+   * does not satisfy @a pred.
+   */
+  template  self_type clip_prefix_of(F const );
+
   /** Get a view of the last @a n bytes.
*
* @param n Number of chars in the prefix.
@@ -646,14 +659,23 @@ public:
* @param pred A function taking @c char and returning @c bool.
* @return The suffix bounded by the first character satisfying @a pred if 
found, otherwise all of @a this.
*
-   * The returned suffix is removed the character satisfying @a pred if found.
-   *
-   * @note The matching character is discarded if @a this is modified.
+   * @note The matching character is discarded if found.
*
* @see @c split_suffix_if
*/
   template  self_type take_suffix_if(F const );
 
+  /** Remove and return a suffix of characters satisfying @a pred
+   *
+   * @tparam F Predicate functor type.
+   * @param pred A function taking @c char and returning @c bool.
+   * @return The suffix of characters that satisfy @a pred.
+   *
+   * The returned suffix is removed from @a this. That suffix may be empty if 
the last character
+   * does not satisfy @a pred.
+   */
+  template  self_type clip_suffix_of(F const );
+
   /** Get a view of part of this view.
*
* @param pos Offset of first byte in the new view.
@@ -1404,6 +1426,26 @@ TextView::stream_write(Stream , const TextView ) 
const {
   return os;
 }
 
+template
+TextView::self_type TextView::clip_prefix_of(F const& pred) {
+  size_t idx = 0;
+  for (auto spot = this->data(), limit = spot + this->size() ; spot < limit && 
pred(*spot); ++spot, ++idx )
+; // empty
+  TextView token = this->prefix(idx);
+  this->remove_prefix(idx);
+  return token;
+}
+
+template
+TextView::self_type TextView::clip_suffix_of(F const& pred) {
+  size_t idx = this->size() - 1;
+  for (auto spot = this->data() + idx, limit = this->data() ; spot >= limit && 
pred(*spot); --spot, --idx )
+; // empty
+  TextView token = this->suffix(idx);
+  this->remove_suffix(idx);
+  return token;
+}
+
 // Provide an instantiation for @c std::ostream as it's likely this is the 
only one ever used.
 extern template std::ostream ::stream_write(std::ostream &, const 
TextView &) const;
 
diff --git a/doc/code/TextView.en.rst b/doc/code/TextView.en.rst
index 2030aff..f3abaf3 100644
--- a/doc/code/TextView.en.rst
+++ b/doc/code/TextView.en.rst
@@ -167,6 +167,10 @@ A secondary distinction is what is done to the view by the 
methods.
is discarded and not left in either the returned view nor the source view. 
If the selected character
is not in the view, the entire view is returned and the source view is 
cleared.
 
+*  The "clip..." methods remove the corresponding part of the view and return 
it. Only those characters
+   are removed - in contrast to "split..." and "take...". If no characters 
match, the view is not modified
+   and an empty view is returned.
+
 .. _`std::string_view::remove_prefix`: 
https://en.cppreference.com/w/cpp/string/basic_string_view/remove_prefix
 .. _`std::string_view::remove_suffix`: 
https://en.cppreference.com/w/cpp/string/basic_string_view/remove_suffix
 
@@ -209,6 +213,8 @@ if the size specified is larger than the contents of the 
view.
 | || | :libswoc:`TextView::split_prefix_at`
 |
 | |+ 
+--+
 | || | :libswoc:`TextView::split_prefix_if`
 |
+| |+ 
+--+
+|   

(trafficserver-libswoc) 02/08: CMake cleanup for better build and install.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit dc9a061350c4d766cfccd0516fb79df695c5cfd5
Author: Alan M. Carroll 
AuthorDate: Wed Oct 28 16:30:39 2020 -0500

CMake cleanup for better build and install.
---
 .gitignore| 29 ++---
 CMakeLists.txt| 12 +---
 code/CMakeLists.txt   | 15 +--
 code/libswoc.pc.cmake |  2 +-
 doc/{Makefile => MakeDocFile} |  0
 5 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/.gitignore b/.gitignore
index feab391..12b4794 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1,8 @@
-# Prerequisites
-*.d
-*.cbp
-
 # Compiled Object files
-*.slo
-*.lo
 *.o
 *.obj
 *.swp
-
-# Precompiled Headers
-*.gch
-*.pch
+*.cbp
 
 # Compiled Dynamic libraries
 *.so
@@ -19,8 +10,6 @@
 *.dll
 
 # Compiled Static libraries
-*.lai
-*.la
 *.a
 *.lib
 
@@ -28,16 +17,26 @@
 *.exe
 *.out
 *.app
+example/ex_flat_space
+example/ex_netcompact
+example/ex_netdb
+unit_tests/test_libswoc
 
+# CMake cruft
+*.cmake
+CMakeFiles/
+CMakeCache.txt
+cmake-build-debug/
+cmake-build-release/
+Makefile
 .idea/
-cmake-build-debug
+
+# Documentation.
 doc/_build
 doc/doxygen
 doc/reference
 doc/ext/local-config.py
 doc/ext/__*
-CMakeFiles/
-cmake-build-release/
 venv/
 .parts.cache
 .sconsign.dblite
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0f6a02f..fa6f3a4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.12)
+cmake_minimum_required(VERSION 3.11)
 
 project("Solid Wall Of C++ Library")
 set(INSTALL_DIR ${CMAKE_HOME_DIRECTORY})
@@ -9,13 +9,3 @@ add_subdirectory(unit_tests)
 add_subdirectory(example)
 add_subdirectory(doc EXCLUDE_FROM_ALL)
 
-# Find all of the directories subject to clang formatting and make a target to 
do the format.
-set(_CLANG_DIRS "")
-get_target_property(_TMP libswoc CLANG_FORMAT_DIRS)
-list(APPEND _CLANG_DIRS ${_TMP})
-get_target_property(_TMP test_libswoc CLANG_FORMAT_DIRS)
-list(APPEND _CLANG_DIRS ${_TMP})
-list(JOIN _CLANG_DIRS " " _CLANG_DIRS)
-
-#add_custom_target(clang-format COMMAND 
${CMAKE_HOME_DIRECTORY}/tools/clang-format.sh ${_CLANG_DIRS})
-#add_custom_target(clang-format COMMAND clang-format ${_CLANG_DIRS})
diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt
index b57ad86..40e8695 100644
--- a/code/CMakeLists.txt
+++ b/code/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.12)
+cmake_minimum_required(VERSION 3.11)
 
 project(Lib-SWOC CXX)
 set(LIBSWOC_VERSION "1.2.13")
@@ -45,12 +45,13 @@ set(CC_FILES
 )
 
 add_library(libswoc STATIC ${CC_FILES})
+set_target_properties(libswoc PROPERTIES OUTPUT_NAME swoc-static)
 if (CMAKE_COMPILER_IS_GNUCXX)
-target_compile_options(libswoc PRIVATE -Wall -Wextra -Werror 
-Wnon-virtual-dtor -Wpedantic)
+target_compile_options(libswoc PRIVATE -fPIC -Wall -Wextra -Werror 
-Wnon-virtual-dtor -Wpedantic)
 endif()
 
 # Not quite sure how this works, but I think it generates one of two paths 
depending on the context.
-# That is, the generator functions return non-empty stri ngs only in the 
corresponding context.
+# That is, the generator functions return non-empty strings only in the 
corresponding context.
 target_include_directories(libswoc
 PUBLIC
 $
@@ -58,9 +59,10 @@ target_include_directories(libswoc
 )
 
 # These install target variables are created by GNUInstallDirs.
+message("CMAKE_INSTALL_LIBDIR = ${CMAKE_INSTALL_LIBDIR}")
 install(TARGETS libswoc
 EXPORT libswoc-config
-ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # seems to have no effect.
 )
 install(DIRECTORY include/swoc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
 
@@ -69,9 +71,10 @@ install(EXPORT libswoc-config
 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libswoc
 )
 
-set(PKG_CONFIG_FILE ${CMAKE_BINARY_DIR}/libswoc.pc)
+
+set(PKG_CONFIG_FILE ${CMAKE_INSTALL_LIBDIR}/libswoc.pc)
 configure_file("libswoc.pc.cmake" ${PKG_CONFIG_FILE} @ONLY)
-install(FILES ${PKG_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+install(FILES ${PKG_CONFIG_FILE} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
 
 # Alledgedly this makes the targets "importable from the build directory" but 
I see no evidence of that.
 # AFAICT the file isn't created at all even with this enabled.
diff --git a/code/libswoc.pc.cmake b/code/libswoc.pc.cmake
index 2bd65a1..c65ba62 100644
--- a/code/libswoc.pc.cmake
+++ b/code/libswoc.pc.cmake
@@ -7,5 +7,5 @@ Name: LibSWOC++
 Description: A collection of solid C++ utilities and classes.
 Version: @LIBSWOC_VERSION@
 Requires:
-Libs: -L${libdir} -lswoc++
+Libs: -L${libdir} -lswoc
 Cflags: -I${includedir}
diff --git a/doc/Makefile b/doc/MakeDocFile
similarity index 100%
rename from doc/Makefile
rename to doc/MakeDocFile



(trafficserver-libswoc) 01/01: Minor fixes, pkgconfig and example code.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-3
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 342675bcb1e52f9e4dfc57f165f51148a977a79f
Author: Alan M. Carroll 
AuthorDate: Tue May 5 16:36:39 2020 -0500

Minor fixes, pkgconfig and example code.
---
 code/include/swoc/bwf_ex.h | 2 +-
 code/libswoc.static.pc.in  | 2 +-
 example/ex_netdb.cc| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/code/include/swoc/bwf_ex.h b/code/include/swoc/bwf_ex.h
index d3ed09f..b84426d 100644
--- a/code/include/swoc/bwf_ex.h
+++ b/code/include/swoc/bwf_ex.h
@@ -72,7 +72,7 @@ FirstOfConverter(T&& t) {
 } // namespace detail
 
 /// Print the first of a list of strings that is not an empty string.
-/// All arguments must be convertible to @c std::string.
+/// All arguments must be convertible to @c std::string_view.
 template
 std::string_view
 FirstOf(Args&& ... args) {
diff --git a/code/libswoc.static.pc.in b/code/libswoc.static.pc.in
index 103f9a4..4439dbb 100644
--- a/code/libswoc.static.pc.in
+++ b/code/libswoc.static.pc.in
@@ -7,5 +7,5 @@ Name: LibSWOC++
 Description: A collection of solid C++ utilities and classes.
 Version: pkg_version
 Requires:
-Libs: -l${libdir}swoc.pkg_version.a
+Libs: -l${libdir}/libswoc.pkg_version.a
 Cflags: -I${includedir}
diff --git a/example/ex_netdb.cc b/example/ex_netdb.cc
index 7e8c323..ffb563f 100644
--- a/example/ex_netdb.cc
+++ b/example/ex_netdb.cc
@@ -103,7 +103,7 @@ swoc::Lexicon PodTypeNames {{
 namespace swoc {
 
 BufferWriter& bwformat(BufferWriter& w, bwf::Spec const& spec, PodType pt) {
-  return bwformat(w, spec, (PodTypeNames[pt]);
+  return bwformat(w, spec, (PodTypeNames[pt]));
 }
 
 BufferWriter& bwformat(BufferWriter& w, bwf::Spec const& spec, FlagSet const& 
flags) {



(trafficserver-libswoc) branch dev-1-2-13 created (now 338f761)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 338f761  Fix bugs in MemSpan prefix, suffix methods.

This branch includes the following new commits:

 new 5987ae0  Update to 1.2.13.
 new dc9a061  CMake cleanup for better build and install.
 new dc659e5  TextView: add "clip_prefix_of" and "clip_suffix_of".
 new d7e6d15  Fix svto_radix comment.
 new 85b5f2d  Add "0b" for binary prefix checking to svtoi.
 new 3513d8e  Fix typos.
 new 4499a8d  Remove unused code from Unit Parser example.
 new 338f761  Fix bugs in MemSpan prefix, suffix methods.

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




(trafficserver-libswoc) 04/08: Fix svto_radix comment.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-13
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit d7e6d15fd9f3b705732a40ff0e4bae4d5ad8ad39
Author: Alan M. Carroll 
AuthorDate: Thu Nov 5 14:40:47 2020 -0600

Fix svto_radix comment.
---
 code/include/swoc/TextView.h | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/code/include/swoc/TextView.h b/code/include/swoc/TextView.h
index 78aded2..40485a0 100644
--- a/code/include/swoc/TextView.h
+++ b/code/include/swoc/TextView.h
@@ -808,13 +808,6 @@ uintmax_t svtou(TextView src, TextView *parsed = nullptr, 
int base = 0);
  * inside @c svtoi for the common cases of 8, 10, and 16, therefore normally 
this isn't much more
  * performant in those cases than just @c svtoi. Because of this only positive 
values are parsed.
  * If determining the radix from the text or signed value parsing is needed, 
used @c svtoi.
- * This is a specialized function useful only where conversion performance is 
critical, or for some
- * other reason the numeric text has already been parsed out. The performance 
gains comes from
- * templating the divisor which enables the compiler to optimize the 
multiplication (e.g., for
- * powers of 2 shifts is used). It is used inside @c svtoi and @c svtou for 
the common cases of 8,
- * 10, and 16, therefore normally this isn't much more performant than @c 
svtoi. Because of this
- * only positive values are parsed. If determining the radix from the text or 
signed value parsing
- * is needed, used @c svtoi.
  *
  * @a src is updated in place to indicate what characters were parsed. Parsing 
stops on the first
  * invalid digit, so any leading non-digit characters (e.g. whitespace) must 
already be removed.
@@ -832,8 +825,7 @@ svto_radix(swoc::TextView ) {
   while (src.size() && (0 <= (v = swoc::svtoi_convert[uint8_t(*src)])) && v < 
N)
   {
 auto n = zret * N + v;
-if (n < zret)
-{ // overflow / wrap
+if (n < zret) { // overflow / wrap
   return std::numeric_limits::max();
 }
 zret = n;



(trafficserver-libswoc) 17/18: Change IPSpace to return iterator instead of PAYLOAD*

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit e8c587796efdf127df5eeb4e82e2048b4aab025d
Author: Alan M. Carroll 
AuthorDate: Tue Mar 3 09:50:40 2020 -0600

Change IPSpace to return iterator instead of PAYLOAD*
---
 swoc++/include/swoc/DiscreteRange.h | 15 
 swoc++/include/swoc/swoc_ip.h   | 68 +++--
 unit_tests/ex_ipspace_properties.cc |  3 +-
 unit_tests/test_IntrusiveDList.cc   |  6 
 unit_tests/test_ip.cc   | 59 
 5 files changed, 80 insertions(+), 71 deletions(-)

diff --git a/swoc++/include/swoc/DiscreteRange.h 
b/swoc++/include/swoc/DiscreteRange.h
index c76f235..f4dc4d9 100644
--- a/swoc++/include/swoc/DiscreteRange.h
+++ b/swoc++/include/swoc/DiscreteRange.h
@@ -698,6 +698,7 @@ protected:
 
 public:
   using iterator = typename decltype(_list)::iterator;
+  using const_iterator = typename decltype(_list)::const_iterator;
 
   DiscreteSpace() = default;
   ~DiscreteSpace();
@@ -756,7 +757,7 @@ public:
* @param metric The metric for which to search.
* @return The payload for @a metric if found, @c nullptr if not found.
*/
-  PAYLOAD * find(METRIC const );
+  iterator find(METRIC const );
 
   /// @return The number of distinct ranges.
   size_t count() const;
@@ -870,27 +871,27 @@ DiscreteSpace::head() -> Node *{
 }
 
 template 
-PAYLOAD *
-DiscreteSpace::find(METRIC const ) {
+auto
+DiscreteSpace::find(METRIC const ) -> iterator {
   auto n = _root; // current node to test.
   while (n) {
 if (metric < n->min()) {
   if (n->_hull.contains(metric)) {
 n = n->left();
   } else {
-return nullptr;
+return this->end();
   }
 } else if (n->max() < metric) {
   if (n->_hull.contains(metric)) {
 n = n->right();
   } else {
-return nullptr;
+return this->end();
   }
 } else {
-  return >payload();
+  return _list.iterator_for(n);
 }
   }
-  return nullptr;
+  return this->end();
 }
 
 template 
diff --git a/swoc++/include/swoc/swoc_ip.h b/swoc++/include/swoc/swoc_ip.h
index 4d40e3f..85c7d8a 100644
--- a/swoc++/include/swoc/swoc_ip.h
+++ b/swoc++/include/swoc/swoc_ip.h
@@ -1,5 +1,6 @@
 #pragma once
 #pragma once
+#pragma once
 // SPDX-License-Identifier: Apache-2.0
 /** @file
IP address and network related classes.
@@ -1438,38 +1439,6 @@ public:
 return *this;
   }
 
-  /** Find the payload for an @a addr.
-   *
-   * @param addr Address to find.
-   * @return The payload if any, @c nullptr if the address is not in the space.
-   */
-  PAYLOAD *find(IP4Addr const& addr) {
-return _ip4.find(addr);
-  }
-
-  /** Find the payload for an @a addr.
-   *
-   * @param addr Address to find.
-   * @return The payload if any, @c nullptr if the address is not in the space.
-   */
-  PAYLOAD *find(IP6Addr const& addr) {
-return _ip6.find(addr);
-  }
-
-  /** Find the payload for an @a addr.
-   *
-   * @param addr Address to find.
-   * @return The payload if any, @c nullptr if the address is not in the space.
-   */
-  PAYLOAD *find(IPAddr const& addr) {
-if (addr.is_ip4()) {
-  return _ip4.find(IP4Addr{addr});
-} else if (addr.is_ip6()) {
-  return _ip6.find(IP6Addr{addr});
-}
-return nullptr;
-  }
-
   /// @return The number of distinct ranges.
   size_t count() const { return _ip4.count() + _ip6.count(); }
 
@@ -1564,7 +1533,7 @@ public:
   };
 
   /** Iterator.
-   * THe value type is a tuple of the IP address range and the @a PAYLOAD. The 
range is constant
+   * The value type is a tuple of the IP address range and the @a PAYLOAD. The 
range is constant
* and the @a PAYLOAD is a reference. This can be used to update the @a 
PAYLOAD for this range.
*
* @note Range merges are not trigged by modifications of the @a PAYLOAD via 
an iterator.
@@ -1631,6 +1600,39 @@ public:
 using super_type::super_type; /// Inherit supertype constructors.
   };
 
+  /** Find the payload for an @a addr.
+   *
+   * @param addr Address to find.
+   * @return Iterator for the range containing @a addr.
+   */
+  iterator find(IPAddr const& addr) {
+if (addr.is_ip4()) {
+  return iterator(_ip4.find(IP4Addr{addr}), _ip6.begin());
+} else if (addr.is_ip6()) {
+  return iterator(_ip4.end(), _ip6.find(IP6Addr{addr}));
+}
+return this->end();
+  }
+
+  /** Find the payload for an @a addr.
+   *
+   * @param addr Address to find.
+   * @return The payload if any, @c nullptr if the address is not in the space.
+   */
+  iterator find(IP4Addr const& addr) {
+auto spot = _ip4.find(addr);
+return spot == _ip4.end() ? this->end() : iterator{_ip4.find(addr), 
_ip6.begin()};
+  }
+
+  /** Find the payload for an @a addr.
+   *
+   * @param addr Address to find.
+   * @return The payload if any, @c nullptr if the 

(trafficserver-libswoc) 16/18: Tweak to test std::tie.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit ed60e6184bd548495353f70c195bc4d0512f55b2
Author: Alan M. Carroll 
AuthorDate: Tue Mar 3 07:20:19 2020 -0600

Tweak to test std::tie.
---
 unit_tests/test_ip.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc
index e9e3e8e..a088e72 100644
--- a/unit_tests/test_ip.cc
+++ b/unit_tests/test_ip.cc
@@ -713,9 +713,11 @@ TEST_CASE("IPSpace docJJ", "[libswoc][ipspace][docJJ]") {
   // Check iterator copying.
   idx = 0;
   Space::iterator iter;
+  IPRange range;
+  PAYLOAD bits;
   for (auto spot = space.begin(); spot != space.end() ; ++spot) {
 iter = spot;
-auto const& [range, bits]{*iter};
+std::tie(range, bits) = *iter;
 REQUIRE(idx < results.size());
 CHECK(bits == make_bits(results[idx]));
 ++idx;



(trafficserver-libswoc) 09/18: Build fixes.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit e92f175b2b6b8a7a805bcddcfad50306e31422cb
Author: Alan M. Carroll 
AuthorDate: Fri Feb 28 15:51:58 2020 -0600

Build fixes.
---
 swoc++/swoc++-shared.part | 1 -
 swoc++/swoc++-static.part | 1 -
 swoc++/swoc++.part| 2 ++
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/swoc++/swoc++-shared.part b/swoc++/swoc++-shared.part
index 4b5ddfb..df0b7d3 100644
--- a/swoc++/swoc++-shared.part
+++ b/swoc++/swoc++-shared.part
@@ -11,7 +11,6 @@ env.AppendUnique(
 # build the library
 out = env.SharedLibrary("libswoc++", src_files)
 env.InstallLib(out)
-env.InstallInclude(env.get("inc_files"))
 
 # Export the package config.
 pc_file = env.Substfile("libswoc++.pc", "libswoc++.pc.in"
diff --git a/swoc++/swoc++-static.part b/swoc++/swoc++-static.part
index 62b38ba..e7defe3 100644
--- a/swoc++/swoc++-static.part
+++ b/swoc++/swoc++-static.part
@@ -11,7 +11,6 @@ env.AppendUnique(
 # build the library
 out = env.StaticLibrary("libswoc++", src_files)
 env.InstallLib(out)
-env.InstallInclude(env.get("inc_files"))
 
 # Export the package config.
 pc_file = env.Substfile("libswoc++-static.pc", "libswoc++-static.pc.in"
diff --git a/swoc++/swoc++.part b/swoc++/swoc++.part
index 19013cb..4c4df61 100644
--- a/swoc++/swoc++.part
+++ b/swoc++/swoc++.part
@@ -16,6 +16,8 @@ src_files = [
 
 # export the include directory
 inc_files = Pattern(src_dir="include/swoc", includes=["*.h"])
+#env.InstallInclude(env.get("inc_files"))
+env.InstallInclude(inc_files)
 
 env.AppendUnique(
 CCFLAGS=['-std=c++17' ],



(trafficserver-libswoc) 13/18: Fix release mode testing issues.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit fdab1196b3662018ea6c19aee0a324af21db86a3
Author: Alan M. Carroll 
AuthorDate: Mon Mar 2 10:15:06 2020 -0600

Fix release mode testing issues.
---
 swoc++/include/swoc/MemSpan.h   |  2 +-
 swoc++/include/swoc/TextView.h  | 23 +--
 swoc++/swoc++-headers.part  |  2 +-
 unit_tests/CMakeLists.txt   |  2 +-
 unit_tests/ex_ipspace_properties.cc |  3 ++-
 unit_tests/test_ip.cc   | 26 ++
 6 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/swoc++/include/swoc/MemSpan.h b/swoc++/include/swoc/MemSpan.h
index 81862c5..f341311 100644
--- a/swoc++/include/swoc/MemSpan.h
+++ b/swoc++/include/swoc/MemSpan.h
@@ -749,7 +749,7 @@ MemSpan::remove_suffix(size_t count) {
 template 
 constexpr MemSpan
 MemSpan::subspan(size_t offset, size_t count) const {
-  return offset <= _count ? self_type{this->data() + offset, std::min(count, 
_count - offset)} : self_type{};
+  return offset < _count ? self_type{this->data() + offset, std::min(count, 
_count - offset)} : self_type{};
 }
 
 template 
diff --git a/swoc++/include/swoc/TextView.h b/swoc++/include/swoc/TextView.h
index 49d0909..db20a21 100644
--- a/swoc++/include/swoc/TextView.h
+++ b/swoc++/include/swoc/TextView.h
@@ -174,11 +174,25 @@ public:
   /// Assign from a @c std::string.
   self_type =(const std::string );
 
+  /** Assign a view of the @a c_str
+   *
+   * @param c_str Pointer to C string.
+   * @return @a this
+   *
+   * @note @c c_str must be a null terminated string. The null byte is not 
included in the view.
+   */
+  self_type& assign(char const* c_str);;
+
   /// Explicitly set the start @a ptr and size @a n of the view.
   self_type (char const *ptr, size_t n);
 
-  /// Explicitly set the view to the half open range [ @a first , @a last )
-  self_type (char const *first, char const *lsat);
+  /** Assign the half open view [ @a b , @a e ) to @a this
+   *
+   * @param b First character in the view.
+   * @param e One character after the last character in the view.
+   * @return @a this
+   */
+  self_type (char const *b, char const *e);
 
   /// Explicitly set the view from a @c std::string
   self_type (std::string const );
@@ -900,6 +914,11 @@ TextView::operator=(const std::string ) {
   return *this;
 }
 
+inline TextView&
+TextView::assign(char const *c_str) {
+  return this->assign(c_str, strlen(c_str));
+}
+
 inline TextView &
 TextView::assign(const std::string ) {
   *this = super_type(s);
diff --git a/swoc++/swoc++-headers.part b/swoc++/swoc++-headers.part
index b0cd428..4c61a89 100644
--- a/swoc++/swoc++-headers.part
+++ b/swoc++/swoc++-headers.part
@@ -2,5 +2,5 @@ Import("*")
 PartName("headers")
 
 # export the include directory
-inc_files = Pattern(src_dir="include/swoc", includes=["*.h"])
+inc_files = Pattern(src_dir="include", includes=["swoc/*.h"])
 env.InstallInclude(inc_files)
diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt
index fd17d9f..39de7a7 100644
--- a/unit_tests/CMakeLists.txt
+++ b/unit_tests/CMakeLists.txt
@@ -28,4 +28,4 @@ add_executable(test_libswoc
 
 target_link_libraries(test_libswoc PUBLIC swoc++)
 set_target_properties(test_libswoc PROPERTIES CLANG_FORMAT_DIRS 
${CMAKE_CURRENT_SOURCE_DIR})
-add_definitions(-DVERBOSE_EXAMPLE_OUTPUT=1)
+#add_definitions(-DVERBOSE_EXAMPLE_OUTPUT=1)
diff --git a/unit_tests/ex_ipspace_properties.cc 
b/unit_tests/ex_ipspace_properties.cc
index e0f0e8e..3420e6a 100644
--- a/unit_tests/ex_ipspace_properties.cc
+++ b/unit_tests/ex_ipspace_properties.cc
@@ -348,7 +348,8 @@ TextView Table::localize(TextView const) {
 TextView Table::token(TextView & line) {
   TextView::size_type idx = 0;
   // Characters of interest.
-  TextView sep_list { {'"', SEP} , 2 };
+  static char constexpr separators[2] = { '"', SEP };
+  static TextView sep_list { separators, 2 };
   bool in_quote_p  = false;
   while (idx < line.size()) {
 // Next character of interest.
diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc
index 286d590..51f40d6 100644
--- a/unit_tests/test_ip.cc
+++ b/unit_tests/test_ip.cc
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 using namespace std::literals;
@@ -643,17 +644,17 @@ TEST_CASE("IPSpace docJJ", "[libswoc][ipspace][docJJ]") {
 return bits;
   };
 
-  std::array>, 9> ranges 
= {
+  std::array, 9> ranges = {
   {
-  {"100.0.0.0-100.0.0.255", {0}}
-  , {"100.0.1.0-100.0.1.255", {1}}
-  , {"100.0.2.0-100.0.2.255", {2}}
-  , {"100.0.3.0-100.0.3.255", {3}}
-  , {"100.0.4.0-100.0.4.255", {4}}
-  , {"100.0.5.0-100.0.5.255", {5}}
-  , {"100.0.6.0-100.0.6.255", {6}}
-  , {"100.0.0.0-100.0.0.255", {31}}
-  , {"100.0.1.0-100.0.1.255", {30}}
+  

(trafficserver-libswoc) 05/18: Build fixes.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 0a66f76554b1eeba1b2eedba929040f7f4dee0b9
Author: Alan M. Carroll 
AuthorDate: Fri Feb 28 13:59:52 2020 -0600

Build fixes.
---
 swoc++/swoc++.part | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/swoc++/swoc++.part b/swoc++/swoc++.part
index af83276..8ffc040 100644
--- a/swoc++/swoc++.part
+++ b/swoc++/swoc++.part
@@ -28,4 +28,4 @@ env.InstallInclude(
 )
 
 env.Part("swoc++-static.part", package_group="libswoc", src_files=src_files)
-env.Part("swoc++-shared.part", package_group="libswoc" src_files=src_files)
+env.Part("swoc++-shared.part", package_group="libswoc", src_files=src_files)



(trafficserver-libswoc) 06/18: Build fixes.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 7996b47610cb54978f6a1cb603fce5df77ad6367
Author: Alan M. Carroll 
AuthorDate: Fri Feb 28 14:04:25 2020 -0600

Build fixes.
---
 swoc++/swoc++.part | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/swoc++/swoc++.part b/swoc++/swoc++.part
index 8ffc040..a881991 100644
--- a/swoc++/swoc++.part
+++ b/swoc++/swoc++.part
@@ -19,9 +19,6 @@ env.AppendUnique(
 CPPPATH=["include"],
 )
 
-# build the library
-out = env.SharedLibrary("libswoc++",files)
-env.InstallLib(out)
 # export the include directory
 env.InstallInclude(
 Pattern(src_dir="include/",includes=["*.h"]),



(trafficserver-libswoc) 18/18: Fix warnings - not actually enabled by CMake, fixed that and the warnings.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 22e279184af0855a56790cca1a8599ff5ea5f04b
Author: Alan M. Carroll 
AuthorDate: Tue Mar 3 16:10:18 2020 -0600

Fix warnings - not actually enabled by CMake, fixed that and the warnings.
---
 swoc++/CMakeLists.txt   |  3 ++-
 swoc++/include/swoc/ArenaWriter.h   |  2 +-
 swoc++/include/swoc/DiscreteRange.h |  2 +-
 swoc++/include/swoc/Lexicon.h   |  3 +--
 swoc++/include/swoc/bwf_base.h  |  4 ++--
 swoc++/include/swoc/swoc_ip.h   |  8 
 swoc++/src/bw_ip_format.cc  | 21 -
 swoc++/src/swoc_ip.cc   | 13 +++--
 unit_tests/CMakeLists.txt   |  1 +
 unit_tests/ex_TextView.cc   |  2 +-
 unit_tests/ex_bw_format.cc  |  1 -
 unit_tests/ex_ipspace_properties.cc |  3 ++-
 unit_tests/test_BufferWriter.cc |  4 ++--
 unit_tests/test_IntrusiveDList.cc   |  5 -
 unit_tests/test_Lexicon.cc  |  2 +-
 unit_tests/test_MemArena.cc |  2 +-
 unit_tests/test_ip.cc   |  2 +-
 17 files changed, 27 insertions(+), 51 deletions(-)

diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index cbe96df..a836c7e 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -45,7 +45,8 @@ set(CC_FILES
 )
 
 add_library(swoc++ STATIC ${CC_FILES})
-add_compile_options(-Wall -Wextra -Werror -Wno-ignored-qualifiers 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
+#add_compile_options(-Wall -Wextra -Werror -Wno-unused-parameter 
-Wno-format-truncation -Wno-stringop-overflow -Wno-invalid-offsetof)
+target_compile_options(swoc++ PRIVATE -Wall -Wextra -Werror 
-Wno-unused-parameter -Wno-format-truncation -Wno-stringop-overflow 
-Wno-invalid-offsetof)
 
 # Not quite sure how this works, but I think it generates one of two paths 
depending on the context.
 # That is, the generator functions return non-empty strings only in the 
corresponding context.
diff --git a/swoc++/include/swoc/ArenaWriter.h 
b/swoc++/include/swoc/ArenaWriter.h
index 2c41150..a09c573 100644
--- a/swoc++/include/swoc/ArenaWriter.h
+++ b/swoc++/include/swoc/ArenaWriter.h
@@ -59,6 +59,6 @@ protected:
   void realloc(size_t n);
 };
 
-inline swoc::ArenaWriter::ArenaWriter(swoc::MemArena ) : _arena(arena), 
super_type(arena.remnant()) {}
+inline swoc::ArenaWriter::ArenaWriter(swoc::MemArena ) : 
super_type(arena.remnant()), _arena(arena) {}
 
 } // namespace swoc
diff --git a/swoc++/include/swoc/DiscreteRange.h 
b/swoc++/include/swoc/DiscreteRange.h
index f4dc4d9..967460b 100644
--- a/swoc++/include/swoc/DiscreteRange.h
+++ b/swoc++/include/swoc/DiscreteRange.h
@@ -594,9 +594,9 @@ protected:
 using super_type = detail::RBNode; ///< Parent class.
 friend class DiscreteSpace;
 
-PAYLOAD _payload{}; ///< Default constructor, should zero init if @c 
PAYLOAD is a pointer.
 range_type _range;  ///< Range covered by this node.
 range_type _hull;   ///< Range covered by subtree rooted at this node.
+PAYLOAD _payload{}; ///< Default constructor, should zero init if @c 
PAYLOAD is a pointer.
 
   public:
 /// Linkage for @c IntrusiveDList.
diff --git a/swoc++/include/swoc/Lexicon.h b/swoc++/include/swoc/Lexicon.h
index cb782f5..7317f86 100644
--- a/swoc++/include/swoc/Lexicon.h
+++ b/swoc++/include/swoc/Lexicon.h
@@ -47,8 +47,7 @@ namespace detail
   std::string
   what(std::string_view const , Args &&... args) {
 std::string zret;
-swoc::bwprint_v(zret, fmt, std::forward_as_tuple(args...));
-return std::move(zret);
+return swoc::bwprint_v(zret, fmt, std::forward_as_tuple(args...));
   }
 } // namespace detail
 
diff --git a/swoc++/include/swoc/bwf_base.h b/swoc++/include/swoc/bwf_base.h
index a8aa874..af894af 100644
--- a/swoc++/include/swoc/bwf_base.h
+++ b/swoc++/include/swoc/bwf_base.h
@@ -376,7 +376,7 @@ namespace bwf
   }
 
 protected:
-  Binding(ContextNames const , context_type ) : _names(names), 
_ctx(ctx) {}
+  Binding(ContextNames const , context_type ) : _ctx(ctx), 
_names(names) {}
 
   context_type &_ctx; ///< Context for generators.
   ContextNames const &_names; ///< Base set of names.
@@ -846,7 +846,7 @@ BufferWriter::print_nfv(Binding &, Extractor &, 
bwf::ArgPack const 
   // via the specifier.
   using spec_type =
 typename 
std::remove_reference::type::operator()))>::type;
-  size_t N= args.count();
+  int N= args.count();
   int arg_idx = 0; // the next argument index to be processed.
 
   // Parser is required to return @c false if there's no more data, @c true if 
something was parsed.
diff --git a/swoc++/include/swoc/swoc_ip.h b/swoc++/include/swoc/swoc_ip.h
index 85c7d8a..59dce88 100644
--- a/swoc++/include/swoc/swoc_ip.h
+++ b/swoc++/include/swoc/swoc_ip.h
@@ -523,13 +523,13 @@ public:
   

(trafficserver-libswoc) 11/18: Better testing of network extraction.

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-14
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 914c5c28946f14a079834a8eb70973855f948cf4
Author: Alan M. Carroll 
AuthorDate: Mon Mar 2 07:23:42 2020 -0600

Better testing of network extraction.
---
 swoc++/include/swoc/swoc_ip.h | 930 ++
 swoc++/src/swoc_ip.cc |  42 ++
 unit_tests/test_ip.cc | 283 +++--
 3 files changed, 861 insertions(+), 394 deletions(-)

diff --git a/swoc++/include/swoc/swoc_ip.h b/swoc++/include/swoc/swoc_ip.h
index 736a6e6..788c727 100644
--- a/swoc++/include/swoc/swoc_ip.h
+++ b/swoc++/include/swoc/swoc_ip.h
@@ -14,8 +14,7 @@
 #include 
 #include 
 
-namespace swoc
-{
+namespace swoc {
 class IP4Addr;
 class IP6Addr;
 class IPAddr;
@@ -46,10 +45,12 @@ union IPEndpoint {
 
   /// Default construct invalid instance.
   IPEndpoint();
+
   /// Construct from the @a text representation of an address.
-  IPEndpoint(string_view const );
+  IPEndpoint(string_view const);
+
   // Construct from @a IPAddr
-  IPEndpoint(IPAddr const );
+  IPEndpoint(IPAddr const);
 
   /** Break a string in to IP address relevant tokens.
*
@@ -62,7 +63,8 @@ union IPEndpoint {
* Any of the out parameters can be @c nullptr in which case they are not 
updated.
* This parses and discards the IPv6 brackets.
*/
-  static bool tokenize(string_view src, string_view *host = nullptr, 
string_view *port = nullptr, string_view *rest = nullptr);
+  static bool tokenize(string_view src, string_view *host = nullptr, 
string_view *port = nullptr
+   , string_view *rest = nullptr);
 
   /** Parse a string for an IP address.
 
@@ -71,16 +73,16 @@ union IPEndpoint {
 
   @return @c true on success, @c false otherwise.
   */
-  bool parse(string_view const );
+  bool parse(string_view const);
 
   /// Invalidate a @c sockaddr.
   static void invalidate(sockaddr *addr);
 
   /// Invalidate this endpoint.
-  self_type ();
+  self_type();
 
   /// Copy constructor.
-  self_type =(self_type const );
+  self_type=(self_type const);
 
   /** Copy (assign) the contents of @a src to @a dst.
*
@@ -96,18 +98,20 @@ union IPEndpoint {
   /** Assign from a socket address.
   The entire address (all parts) are copied if the @a ip is valid.
   */
-  self_type (sockaddr const *addr);
+  self_type(sockaddr const *addr);
 
   /// Assign from an @a addr and @a port.
-  self_type (IPAddr const , in_port_t port = 0);
+  self_type(IPAddr const, in_port_t port = 0);
 
   /// Copy to @a sa.
-  const self_type (sockaddr *addr) const;
+  const self_type(sockaddr *addr) const;
 
   /// Test for valid IP address.
   bool is_valid() const;
+
   /// Test for IPv4.
   bool is_ip4() const;
+
   /// Test for IPv6.
   bool is_ip6() const;
 
@@ -123,28 +127,34 @@ union IPEndpoint {
   /// Set to be the ANY address for family @a family.
   /// @a family must be @c AF_INET or @c AF_INET6.
   /// @return This object.
-  self_type _to_any(int family);
+  self_type_to_any(int family);
 
   /// Set to be loopback address for family @a family.
   /// @a family must be @c AF_INET or @c AF_INET6.
   /// @return This object.
-  self_type _to_loopback(int family);
+  self_type_to_loopback(int family);
 
   /// Port in network order.
-  in_port_t ();
+  in_port_t();
+
   /// Port in network order.
   in_port_t port() const;
+
   /// Port in host horder.
   in_port_t host_order_port() const;
+
   /// Port in network order from @a sockaddr.
-  static in_port_t (sockaddr *sa);
+  static in_port_t(sockaddr *sa);
+
   /// Port in network order from @a sockaddr.
   static in_port_t port(sockaddr const *sa);
+
   /// Port in host order directly from a @c sockaddr
   static in_port_t host_order_port(sockaddr const *sa);
 
   /// Automatic conversion to @c sockaddr.
   operator sockaddr *() { return  }
+
   /// Automatic conversion to @c sockaddr.
   operator sockaddr const *() const { return  }
 
@@ -158,6 +168,7 @@ union IPEndpoint {
 class IP4Addr {
   using self_type = IP4Addr; ///< Self reference type.
   friend class IP4Range;
+
 public:
   static constexpr size_t SIZE = sizeof(in_addr_t); ///< Size of IPv4 address 
in bytes.
   static constexpr size_t WIDTH = BITSPERBYTE * SIZE; ///< # of bits in an 
address.
@@ -170,44 +181,50 @@ public:
   /// @note Host order seems odd, but all of the standard network macro values 
such as @c INADDR_LOOPBACK
   /// are in host order.
   explicit constexpr IP4Addr(in_addr_t addr);
+
   /// Construct from @c sockaddr_in.
   explicit IP4Addr(sockaddr_in const *sa);
+
   /// Construct from text representation.
   /// If the @a text is invalid the result is an invalid instance.
-  IP4Addr(string_view const );
+  IP4Addr(string_view const);
+
   /// Construct from generic address @a addr.
-  explicit IP4Addr(IPAddr const& addr);
+  explicit IP4Addr(IPAddr const);
 
   /// Assign from 

(trafficserver-libswoc) branch dev-1-2-3 created (now 342675b)

2024-01-30 Thread bneradt
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-2-3
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


  at 342675b  Minor fixes, pkgconfig and example code.

This branch includes the following new commits:

 new 342675b  Minor fixes, pkgconfig and example code.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




  1   2   >