You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2024/01/30 16:26:43 UTC
(trafficserver-libswoc) 02/02: Run clang format.
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 ae2519761f5b4871a1d962651609df300935d49f
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Wed Nov 8 16:37:32 2023 -0600
Run clang format.
---
code/include/swoc/BufferWriter.h | 25 +-
code/include/swoc/DiscreteRange.h | 74 +--
code/include/swoc/Errata.h | 116 ++---
code/include/swoc/IPAddr.h | 144 +++---
code/include/swoc/IPEndpoint.h | 54 +--
code/include/swoc/IPRange.h | 402 +++++++++++------
code/include/swoc/IPSrv.h | 454 +++++++++++++------
code/include/swoc/IntrusiveDList.h | 100 +++--
code/include/swoc/IntrusiveHashMap.h | 9 +-
code/include/swoc/Lexicon.h | 5 +-
code/include/swoc/MemArena.h | 29 +-
code/include/swoc/MemSpan.h | 339 +++++++-------
code/include/swoc/Scalar.h | 10 +-
code/include/swoc/TextView.h | 109 +++--
code/include/swoc/Vectray.h | 315 ++++++-------
code/include/swoc/bwf_base.h | 72 +--
code/include/swoc/bwf_ex.h | 10 +-
code/include/swoc/bwf_fwd.h | 8 +-
code/include/swoc/bwf_ip.h | 10 +-
code/include/swoc/bwf_std.h | 10 +-
code/include/swoc/swoc_file.h | 48 +-
code/include/swoc/swoc_meta.h | 4 +-
code/src/ArenaWriter.cc | 3 +-
code/src/Errata.cc | 33 +-
code/src/MemArena.cc | 27 +-
code/src/RBTree.cc | 6 +-
code/src/TextView.cc | 11 +-
code/src/bw_format.cc | 249 ++++------
code/src/bw_ip_format.cc | 30 +-
code/src/swoc_file.cc | 118 ++---
code/src/swoc_ip.cc | 89 ++--
example/ex_diskstats.cc | 22 +-
example/ex_flat_space.cc | 93 ++--
example/ex_host_file.cc | 11 +-
example/ex_lru_cache.cc | 107 +++--
example/ex_netcompact.cc | 26 +-
example/ex_netdb.cc | 153 +++----
unit_tests/ex_IntrusiveDList.cc | 59 +--
unit_tests/ex_Lexicon.cc | 77 ++--
unit_tests/ex_MemArena.cc | 27 +-
unit_tests/ex_TextView.cc | 72 ++-
unit_tests/ex_UnitParser.cc | 74 ++-
unit_tests/ex_bw_format.cc | 103 ++---
unit_tests/ex_ipspace_properties.cc | 242 ++++++----
unit_tests/test_BufferWriter.cc | 87 ++--
unit_tests/test_Errata.cc | 68 ++-
unit_tests/test_IntrusiveDList.cc | 42 +-
unit_tests/test_IntrusiveHashMap.cc | 27 +-
unit_tests/test_Lexicon.cc | 161 ++++---
unit_tests/test_MemArena.cc | 88 ++--
unit_tests/test_MemSpan.cc | 59 ++-
unit_tests/test_Scalar.cc | 12 +-
unit_tests/test_TextView.cc | 91 ++--
unit_tests/test_Vectray.cc | 20 +-
unit_tests/test_bw_format.cc | 43 +-
unit_tests/test_ip.cc | 847 +++++++++++++++++------------------
unit_tests/test_meta.cc | 30 +-
unit_tests/test_range.cc | 9 +-
unit_tests/test_swoc_file.cc | 33 +-
unit_tests/unit_test_main.cc | 3 +-
60 files changed, 2944 insertions(+), 2655 deletions(-)
diff --git a/code/include/swoc/BufferWriter.h b/code/include/swoc/BufferWriter.h
index 85e17f1..154da37 100644
--- a/code/include/swoc/BufferWriter.h
+++ b/code/include/swoc/BufferWriter.h
@@ -63,7 +63,7 @@ public:
* @internal The char poointer overloads protect this method in order to protect against including
* the terminal nul in the destination buffer.
*/
- BufferWriter & write(MemSpan<void const> span);
+ BufferWriter &write(MemSpan<void const> span);
/// @return Pointer to first byte in buffer.
virtual const char *data() const = 0;
@@ -177,7 +177,7 @@ public:
* @note This must be declared here, but the implementation is in @c bwf_base.h. That file does
* not need to be included if formatted output is not used.
*/
- template <typename... Args> BufferWriter &print(const TextView &fmt, Args &&... args);
+ template <typename... Args> BufferWriter &print(const TextView &fmt, Args &&...args);
/** Formatted output to the buffer.
*
@@ -199,7 +199,7 @@ public:
* @param args Arguments for the format string.
* @return @a this.
*/
- template <typename... Args> BufferWriter &print(const bwf::Format &fmt, Args &&... args);
+ template <typename... Args> BufferWriter &print(const bwf::Format &fmt, Args &&...args);
/** Formatted output to the buffer.
*
@@ -273,7 +273,7 @@ public:
*
* Essentially this forwards @a t to @c bwformat.
*/
- template <typename T> BufferWriter & format(bwf::Spec const& spec, T && t);
+ template <typename T> BufferWriter &format(bwf::Spec const &spec, T &&t);
/** Write formattted data.
*
@@ -284,7 +284,7 @@ public:
*
* Essentially this forwards @a t to @c bwformat.
*/
- template <typename T> BufferWriter & format(bwf::Spec const& spec, T const& t);
+ template <typename T> BufferWriter &format(bwf::Spec const &spec, T const &t);
/** IO stream operator.
*
@@ -396,11 +396,11 @@ public:
std::ostream &operator>>(std::ostream &stream) const override;
/// @cond COVARY
- template <typename... Rest> self_type &print(TextView fmt, Rest &&... rest);
+ template <typename... Rest> self_type &print(TextView fmt, Rest &&...rest);
template <typename... Args> self_type &print_v(TextView fmt, std::tuple<Args...> const &args);
- template <typename... Args> self_type &print(bwf::Format const &fmt, Args &&... args);
+ template <typename... Args> self_type &print(bwf::Format const &fmt, Args &&...args);
template <typename... Args> self_type &print_v(bwf::Format const &fmt, std::tuple<Args...> const &args);
/// @endcond
@@ -464,15 +464,17 @@ BufferWriter::write(const void *data, size_t length) {
return *this;
}
-# if 0
+#if 0
inline BufferWriter &
BufferWriter::write(const std::string_view &sv) {
return this->write(sv.data(), sv.size());
}
-# endif
+#endif
inline BufferWriter &
-BufferWriter::write(MemSpan<void const> span) { return this->write(span.data(), span.size()); }
+BufferWriter::write(MemSpan<void const> span) {
+ return this->write(span.data(), span.size());
+}
inline char *
BufferWriter::aux_data() {
@@ -592,8 +594,7 @@ FixedBufferWriter::extent() const {
return _attempted;
}
-inline auto
-FixedBufferWriter::restrict(size_t n) -> self_type & {
+inline auto FixedBufferWriter::restrict(size_t n) -> self_type & {
if (n > _capacity) {
throw(std::invalid_argument{"FixedBufferWriter restrict value more than capacity"});
}
diff --git a/code/include/swoc/DiscreteRange.h b/code/include/swoc/DiscreteRange.h
index ff681f2..cfd8dba 100644
--- a/code/include/swoc/DiscreteRange.h
+++ b/code/include/swoc/DiscreteRange.h
@@ -215,7 +215,7 @@ public:
*
* @note No checks are done, the caller must ensure it is valid to decremented the current maximum.
*/
- self_type & clip_max();
+ self_type &clip_max();
/** Minimum value.
* @return the minimum value in the range.
@@ -345,7 +345,7 @@ public:
explicit operator bool() const;
/** Maximality.
- * @return @c true if this range contains every value.
+ * @return @c true if this range contains every value.
*/
bool is_maximal() const;
@@ -355,13 +355,13 @@ public:
self_type &operator&=(self_type const &that);
/** Convex hull.
- * Minimally extend @a this to cover all elements in @c this and @a that.
- * @return @a this.
+ * Minimally extend @a this to cover all elements in @c this and @a that.
+ * @return @a this.
*/
self_type &operator|=(self_type const &that);
/// Make the range empty.
- self_type & clear();
+ self_type &clear();
/** Functor for lexicographic ordering.
If, for some reason, an interval needs to be put in a container
@@ -378,9 +378,9 @@ public:
of the overall tuples.
*/
struct lexicographic_order {
- using first_argument_type = self_type;
+ using first_argument_type = self_type;
using second_argument_type = self_type;
- using result_type = bool;
+ using result_type = bool;
//! Functor operator.
bool operator()(self_type const &lhs, self_type const &rhs) const;
@@ -412,7 +412,9 @@ DiscreteRange<T>::operator!() const {
return _min > _max;
}
-template <typename T> DiscreteRange<T>::operator bool() const { return _min <= _max; }
+template <typename T> DiscreteRange<T>::operator bool() const {
+ return _min <= _max;
+}
template <typename T>
bool
@@ -460,7 +462,7 @@ DiscreteRange<T>::left_edge_relationship(self_type const &that) const -> EdgeRel
template <typename T>
auto
-DiscreteRange<T>::relationship(self_type const &that) const -> Relation{
+DiscreteRange<T>::relationship(self_type const &that) const -> Relation {
Relation retval = Relation::NONE;
if (this->has_intersection(that)) {
if (*this == that)
@@ -894,14 +896,14 @@ public:
* @param m Search value.
* @return Rightmost range that starts at or before @a m.
*/
- iterator lower_bound(METRIC const& m);
+ iterator lower_bound(METRIC const &m);
/** Upper bound.
*
* @param m search value
* @return Leftmost range that starts after @a m.
*/
- iterator upper_bound(METRIC const& m);
+ iterator upper_bound(METRIC const &m);
/** Intersection of @a range with container.
*
@@ -911,7 +913,7 @@ public:
* @see lower_bound
* @see upper_bound
*/
- std::pair<iterator, iterator> intersection(range_type const& range);
+ std::pair<iterator, iterator> intersection(range_type const &range);
/// @return The number of distinct ranges.
size_t count() const;
@@ -920,13 +922,25 @@ public:
bool empty() const;
/// @return Iterator for the first range.
- iterator begin() { return _list.begin(); }
+ iterator
+ begin() {
+ return _list.begin();
+ }
/// @return Iterator past the last node.
- iterator end() { return _list.end(); }
+ iterator
+ end() {
+ return _list.end();
+ }
/// @return Iterator for the first range.
- const_iterator begin() const { return _list.begin(); }
+ const_iterator
+ begin() const {
+ return _list.begin();
+ }
/// @return Iterator past the last node.
- const_iterator end() const { return _list.end(); }
+ const_iterator
+ end() const {
+ return _list.end();
+ }
/// Remove all ranges.
void clear();
@@ -1090,8 +1104,7 @@ DiscreteSpace<METRIC, PAYLOAD>::find(METRIC const &metric) -> iterator {
template <typename METRIC, typename PAYLOAD>
auto
-DiscreteSpace<METRIC, PAYLOAD>::find(METRIC const &metric) const -> const_iterator
-{
+DiscreteSpace<METRIC, PAYLOAD>::find(METRIC const &metric) const -> const_iterator {
return const_cast<self_type *>(this)->find(metric);
}
@@ -1128,7 +1141,7 @@ DiscreteSpace<METRIC, PAYLOAD>::upper_node(METRIC const &target) -> Node * {
Node *zret = nullptr; // best node so far.
// Fast check if there is no range past @a target.
- if (auto ln = _list.tail() ; ln == nullptr || ln->min() <= target) {
+ if (auto ln = _list.tail(); ln == nullptr || ln->min() <= target) {
return nullptr;
}
@@ -1171,28 +1184,28 @@ template <typename METRIC, typename PAYLOAD>
auto
DiscreteSpace<METRIC, PAYLOAD>::intersection(DiscreteSpace::range_type const &range) -> std::pair<iterator, iterator> {
// Quick checks for null intersection
- if (this->head() == nullptr || // empty
+ if (this->head() == nullptr || // empty
this->head()->_range.min() > range.max() || // before first range
- this->tail()->_range.max() < range.min() // after last range
+ this->tail()->_range.max() < range.min() // after last range
) {
- return { this->end(), this->end() };
+ return {this->end(), this->end()};
}
// Invariant - the search range intersects the convex hull of the ranges. This doesn't require the search
// range to intersect any of the actual ranges.
- auto * lower = this->lower_node(range.min());
- auto * upper = this->upper_node(range.max());
+ auto *lower = this->lower_node(range.min());
+ auto *upper = this->upper_node(range.max());
if (lower == nullptr) {
lower = this->head();
} else if (lower->_range.max() < range.min()) {
- lower = next(lower); // lower is before @a range so @c next must be at or past.
+ lower = next(lower); // lower is before @a range so @c next must be at or past.
if (lower->_range.min() > range.max()) { // @a range is in an uncolored gap.
- return { this->end(), this->end() };
+ return {this->end(), this->end()};
}
}
- return { _list.iterator_for(lower), upper ? _list.iterator_for(upper) : this->end() };
+ return {_list.iterator_for(lower), upper ? _list.iterator_for(upper) : this->end()};
}
template <typename METRIC, typename PAYLOAD>
@@ -1293,8 +1306,8 @@ template <typename METRIC, typename PAYLOAD>
DiscreteSpace<METRIC, PAYLOAD> &
DiscreteSpace<METRIC, PAYLOAD>::mark(DiscreteSpace::range_type const &range, PAYLOAD const &payload) {
Node *n = this->lower_node(range.min()); // current node.
- Node *x = nullptr; // New node, gets set if we re-use an existing one.
- Node *y = nullptr; // Temporary for removing and advancing.
+ Node *x = nullptr; // New node, gets set if we re-use an existing one.
+ Node *y = nullptr; // Temporary for removing and advancing.
// Use carefully, only in situations where it is known there is no overflow.
auto max_plus_1 = ++metric_type{range.max()};
@@ -1736,8 +1749,7 @@ DiscreteSpace<METRIC, PAYLOAD>::blend(DiscreteSpace::range_type const &range, U
template <typename METRIC, typename PAYLOAD>
void
-DiscreteSpace<METRIC, PAYLOAD>::clear()
-{
+DiscreteSpace<METRIC, PAYLOAD>::clear() {
for (auto &node : _list) {
std::destroy_at(&node.payload());
}
diff --git a/code/include/swoc/Errata.h b/code/include/swoc/Errata.h
index 6b619ab..59ec0d4 100644
--- a/code/include/swoc/Errata.h
+++ b/code/include/swoc/Errata.h
@@ -68,7 +68,7 @@ public:
explicit constexpr Severity(severity_type n) : _raw(n) {} ///< No implicit conversion from numeric.
- Severity(Severity const &that) = default;
+ Severity(Severity const &that) = default;
Severity &operator=(Severity const &that) = default;
operator severity_type() const { return _raw; } ///< Implicit conversion to numeric.
@@ -189,26 +189,26 @@ protected:
/// Allocate from the arena.
swoc::MemSpan<char> alloc(size_t n);
- TextView _annotation_glue_text = DEFAULT_ANNOTATION_GLUE_TEXT;
+ TextView _annotation_glue_text = DEFAULT_ANNOTATION_GLUE_TEXT;
TextView _annotation_severity_glue_text = DEFAULT_SEVERITY_GLUE_TEXT;
- TextView _severity_glue_text = DEFAULT_SEVERITY_GLUE_TEXT;
- TextView _indent_text = DEFAULT_INDENT_TEXT;
- bool _glue_final_p = true; ///< Add glue after the last annotation?
-
- std::optional<Severity> _severity; ///< Severity.
- code_type _code{Errata::DEFAULT_CODE}; ///< Message code / ID
- Container _notes; ///< The message stack.
- swoc::MemArena _arena; ///< Annotation text storage.
+ TextView _severity_glue_text = DEFAULT_SEVERITY_GLUE_TEXT;
+ TextView _indent_text = DEFAULT_INDENT_TEXT;
+ bool _glue_final_p = true; ///< Add glue after the last annotation?
+
+ std::optional<Severity> _severity; ///< Severity.
+ code_type _code{Errata::DEFAULT_CODE}; ///< Message code / ID
+ Container _notes; ///< The message stack.
+ swoc::MemArena _arena; ///< Annotation text storage.
};
public:
/// Default constructor - empty errata, very fast.
Errata() = default;
- Errata(self_type const &that) = delete; ///< No constant copy construction.
- Errata(self_type &&that) noexcept; ///< Move constructor.
- self_type &operator=(self_type const &that) = delete; // no copy assignemnt.
- self_type &operator =(self_type &&that); ///< Move assignment.
- ~Errata(); ///< Destructor.
+ Errata(self_type const &that) = delete; ///< No constant copy construction.
+ Errata(self_type &&that) noexcept; ///< Move constructor.
+ self_type &operator=(self_type const &that) = delete; // no copy assignemnt.
+ self_type &operator=(self_type &&that); ///< Move assignment.
+ ~Errata(); ///< Destructor.
/** Construct with a severity.
*
@@ -262,12 +262,11 @@ public:
*
* Cosntructs with error @a code and @a severity and an formatted annotation.
*/
- template <typename... Args> Errata(code_type const &code, Severity severity, std::string_view fmt, Args &&... args);
+ template <typename... Args> Errata(code_type const &code, Severity severity, std::string_view fmt, Args &&...args);
-
- template <typename... Args> Errata(code_type const &type, std::string_view fmt, Args &&... args);
- template <typename... Args> Errata(Severity severity, std::string_view fmt, Args &&... args);
- template <typename... Args> explicit Errata(std::string_view fmt, Args &&... args);
+ template <typename... Args> Errata(code_type const &type, std::string_view fmt, Args &&...args);
+ template <typename... Args> Errata(Severity severity, std::string_view fmt, Args &&...args);
+ template <typename... Args> explicit Errata(std::string_view fmt, Args &&...args);
/** Add an @c Annotation to the top with @a text.
* @param text Text of the message.
@@ -326,7 +325,7 @@ public:
*
* @return A reference to this object.
*/
- template <typename... Args> self_type ¬e(std::string_view fmt, Args &&... args);
+ template <typename... Args> self_type ¬e(std::string_view fmt, Args &&...args);
/** Append an @c Annotation.
* @param fmt Format string (@c BufferWriter style).
@@ -346,7 +345,7 @@ public:
*
* The severity is updated to @a severity if the latter is more severe.
*/
- template <typename... Args> self_type ¬e(Severity severity, std::string_view fmt, Args &&... args);
+ template <typename... Args> self_type ¬e(Severity severity, std::string_view fmt, Args &&...args);
/** Append an @c Annotation.
* @param severity Local severity.
@@ -409,7 +408,7 @@ public:
* @see register_sink
* @see clear
*/
- self_type & sink();
+ self_type &sink();
friend std::ostream &operator<<(std::ostream &, self_type const &);
@@ -450,7 +449,10 @@ public:
bool is_ok() const;
/// @return If there is top level severity.
- bool has_severity() const { return _data && _data->_severity.has_value(); }
+ bool
+ has_severity() const {
+ return _data && _data->_severity.has_value();
+ }
/// @return Top level severity.
Severity severity() const;
@@ -462,16 +464,16 @@ public:
*
* @see update
*/
- self_type & assign(Severity severity);
+ self_type &assign(Severity severity);
/** Set the severity.
- *
- * @param severity Minimum severity
- * @return @a this
- *
- * This sets the internal severity to the maximum of @a severity and the current severity.
- *
- * @see assign
+ *
+ * @param severity Minimum severity
+ * @return @a this
+ *
+ * This sets the internal severity to the maximum of @a severity and the current severity.
+ *
+ * @see assign
*/
self_type &update(Severity severity);
@@ -479,7 +481,7 @@ public:
code_type const &code() const;
/// Set the @a code for @a this.
- self_type & assign(code_type code);
+ self_type &assign(code_type code);
/// Number of messages in the errata.
size_t length() const;
@@ -527,7 +529,7 @@ public:
* @param final_glue_p Add glue after last annotation?
* @return @a this
*/
- self_type & assign_annotation_glue_text(TextView text, bool final_glue_p = false);
+ self_type &assign_annotation_glue_text(TextView text, bool final_glue_p = false);
/// @return Glue text for the annotation severity.
TextView annotation_severity_glue_text() const;
@@ -537,7 +539,7 @@ public:
* @param text Glue text.
* @return @a this
*/
- self_type & assign_annotation_severity_glue_text(TextView text);
+ self_type &assign_annotation_severity_glue_text(TextView text);
/// @return The severity glue text for @a this.
TextView severity_glue_text() const;
@@ -547,7 +549,7 @@ public:
* @param text Glue text.
* @return @a this
*/
- self_type & assign_severity_glue_text(TextView text);
+ self_type &assign_severity_glue_text(TextView text);
/// @return The text used for each level of indentation.
TextView indent_text() const;
@@ -557,7 +559,7 @@ public:
* @param text Text for each level of indentation.
* @return @a this.
*/
- self_type & assign_indent_text(TextView text);
+ self_type &assign_indent_text(TextView text);
/** Base class for erratum sink.
@@ -587,8 +589,8 @@ public:
/// Convenience wrapper class to enable using functions directly for sinks.
struct SinkWrapper : public Sink {
/// Constructor.
- SinkWrapper(SinkHandler const& f) : _f(f) {}
- SinkWrapper(SinkHandler && f) : _f(std::move(f)) {}
+ SinkWrapper(SinkHandler const &f) : _f(f) {}
+ SinkWrapper(SinkHandler &&f) : _f(std::move(f)) {}
/// Operator to invoke the function.
void operator()(Errata const &e) const override;
SinkHandler _f; ///< Client supplied handler.
@@ -602,7 +604,7 @@ public:
/// Register a sink function for abandonded erratum.
static void
- register_sink(SinkHandler && f) {
+ register_sink(SinkHandler &&f) {
register_sink(Sink::Handle(new SinkWrapper(std::move(f))));
}
@@ -756,7 +758,7 @@ public:
* @param args Arguments for @a fmt.
* @return @a *this
*/
- template <typename... Args> self_type ¬e(std::string_view fmt, Args &&... args);
+ template <typename... Args> self_type ¬e(std::string_view fmt, Args &&...args);
/** Append a message in to the result.
*
@@ -766,7 +768,7 @@ public:
* @param args Arguments for @a fmt.
* @return @a *this
*/
- template <typename... Args> self_type ¬e(Severity severity, std::string_view fmt, Args &&... args);
+ template <typename... Args> self_type ¬e(Severity severity, std::string_view fmt, Args &&...args);
/** Copy messages from @a that to @a this.
*
@@ -996,20 +998,20 @@ inline Errata::Errata(code_type const &code, const std::string_view &text) : Err
inline Errata::Errata(Severity severity, const std::string_view &text) : Errata(DEFAULT_CODE, severity, text) {}
template <typename... Args>
-Errata::Errata(code_type const &code, Severity severity, std::string_view fmt, Args &&... args) : Errata(code, severity) {
+Errata::Errata(code_type const &code, Severity severity, std::string_view fmt, Args &&...args) : Errata(code, severity) {
this->note_v(fmt, std::forward_as_tuple(args...));
}
template <typename... Args>
-Errata::Errata(code_type const &code, std::string_view fmt, Args &&... args)
+Errata::Errata(code_type const &code, std::string_view fmt, Args &&...args)
: Errata(code, DEFAULT_SEVERITY, fmt, std::forward<Args>(args)...) {}
template <typename... Args>
-Errata::Errata(Severity severity, std::string_view fmt, Args &&... args)
+Errata::Errata(Severity severity, std::string_view fmt, Args &&...args)
: Errata(DEFAULT_CODE, severity, fmt, std::forward<Args>(args)...) {}
template <typename... Args>
-Errata::Errata(std::string_view fmt, Args &&... args) : Errata(DEFAULT_CODE, DEFAULT_SEVERITY, fmt, std::forward<Args>(args)...) {}
+Errata::Errata(std::string_view fmt, Args &&...args) : Errata(DEFAULT_CODE, DEFAULT_SEVERITY, fmt, std::forward<Args>(args)...) {}
-inline Errata&
+inline Errata &
Errata::clear() {
if (_data) {
_data->~Data(); // destructs the @c MemArena in @a _data which releases memory.
@@ -1046,7 +1048,8 @@ Errata::code() const -> code_type const & {
return this->empty() ? DEFAULT_CODE : _data->_code;
}
-inline auto Errata::assign(code_type code) -> self_type & {
+inline auto
+Errata::assign(code_type code) -> self_type & {
this->data()->_code = code;
return *this;
}
@@ -1056,7 +1059,8 @@ Errata::severity() const -> Severity {
return _data ? _data->_severity.value() : DEFAULT_SEVERITY;
}
-inline auto Errata::assign(Severity severity) -> self_type & {
+inline auto
+Errata::assign(Severity severity) -> self_type & {
this->data()->_severity = severity;
return *this;
}
@@ -1136,13 +1140,13 @@ Errata::note_v(Severity severity, std::string_view fmt, std::tuple<Args...> cons
template <typename... Args>
Errata &
-Errata::note(std::string_view fmt, Args &&... args) {
+Errata::note(std::string_view fmt, Args &&...args) {
return this->note_sv({}, fmt, std::forward_as_tuple(args...));
}
template <typename... Args>
Errata &
-Errata::note(Severity severity, std::string_view fmt, Args &&... args) {
+Errata::note(Severity severity, std::string_view fmt, Args &&...args) {
return this->note_sv(severity, fmt, std::forward_as_tuple(args...));
}
@@ -1174,7 +1178,7 @@ Errata::annotation_glue_text() const {
inline auto
Errata::assign_annotation_glue_text(TextView text, bool final_glue_p) -> self_type & {
this->data()->_annotation_glue_text = this->data()->localize(text);
- this->data()->_glue_final_p = final_glue_p;
+ this->data()->_glue_final_p = final_glue_p;
return *this;
}
@@ -1249,7 +1253,7 @@ Rv<R>::note(const code_type &code, Severity severity) -> self_type & {
template <typename R>
template <typename... Args>
auto
-Rv<R>::note(std::string_view fmt, Args &&... args) -> self_type & {
+Rv<R>::note(std::string_view fmt, Args &&...args) -> self_type & {
_errata.note(fmt, std::forward<Args>(args)...);
return *this;
}
@@ -1257,7 +1261,7 @@ Rv<R>::note(std::string_view fmt, Args &&... args) -> self_type & {
template <typename R>
template <typename... Args>
auto
-Rv<R>::note(Severity severity, std::string_view fmt, Args &&... args) -> self_type & {
+Rv<R>::note(Severity severity, std::string_view fmt, Args &&...args) -> self_type & {
_errata.note(severity, fmt, std::forward<Args>(args)...);
return *this;
}
@@ -1380,7 +1384,9 @@ BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, Errata const &);
// Tuple / structured binding support.
namespace std {
/// @cond INTERNAL_DETAIL
-template <size_t IDX, typename R> class tuple_element<IDX, swoc::Rv<R>> { static_assert("swoc:Rv tuple index out of range"); };
+template <size_t IDX, typename R> class tuple_element<IDX, swoc::Rv<R>> {
+ static_assert("swoc:Rv tuple index out of range");
+};
template <typename R> class tuple_element<0, swoc::Rv<R>> {
public:
diff --git a/code/include/swoc/IPAddr.h b/code/include/swoc/IPAddr.h
index c808364..690ee14 100644
--- a/code/include/swoc/IPAddr.h
+++ b/code/include/swoc/IPAddr.h
@@ -34,14 +34,14 @@ public:
static constexpr size_t SIZE = sizeof(in_addr_t); ///< Size of IPv4 address in bytes.
static constexpr size_t WIDTH = std::numeric_limits<unsigned char>::digits * SIZE; ///< # of bits in an address.
- static const self_type MIN; ///< Minimum value.
- static const self_type MAX; ///< Maximum value.
- static constexpr sa_family_t AF_value = AF_INET; ///< Address family type.
+ static const self_type MIN; ///< Minimum value.
+ static const self_type MAX; ///< Maximum value.
+ static constexpr sa_family_t AF_value = AF_INET; ///< Address family type.
constexpr IP4Addr() = default; ///< Default constructor - ANY address.
/// Copy constructor.
- IP4Addr(self_type const& that) = default;
+ IP4Addr(self_type const &that) = default;
/// Construct using IPv4 @a addr (in host order).
/// @note Host order seems odd, but all of the standard network macro values such as @c INADDR_LOOPBACK
@@ -56,7 +56,7 @@ public:
IP4Addr(string_view const &text);
/// Self assignment.
- self_type & operator=(self_type const& that) = default;
+ self_type &operator=(self_type const &that) = default;
/// Assign from IPv4 raw address.
self_type &operator=(in_addr_t ip);
@@ -114,7 +114,7 @@ public:
* @return @c true if @a text is a valid IPv4 address, @c false otherwise.
*
* Whitespace is trimmed from @text before parsing. If the parse fails @a this is set to @c INADDR_ANY.
- */
+ */
bool load(string_view const &text);
/// Standard ternary compare.
@@ -224,7 +224,7 @@ public:
/// Maximum value of an address.
static const self_type MAX;
- IP6Addr() = default; ///< Default constructor - ANY address.
+ IP6Addr() = default; ///< Default constructor - ANY address.
IP6Addr(self_type const &that) = default;
/// Construct using IPv6 @a addr.
@@ -245,7 +245,7 @@ public:
explicit IP6Addr(IP4Addr addr);
/// Self assignment.
- self_type & operator=(self_type const& that) = default;
+ self_type &operator=(self_type const &that) = default;
/** Left shift.
*
@@ -296,7 +296,7 @@ public:
* @param idx Byte index.
* @return The "text order" byte.
*/
- constexpr uint8_t operator [] (int idx) const;
+ constexpr uint8_t operator[](int idx) const;
/** Update socket address with this address.
*
@@ -322,7 +322,7 @@ public:
* @param dst Destination for host order address.
* @return @a dst
*/
- in6_addr& host_order(in6_addr & dst) const;
+ in6_addr &host_order(in6_addr &dst) const;
/// Return the address in network order.
in6_addr network_order() const;
@@ -371,7 +371,7 @@ public:
*
* @return @a this
*/
- self_type & clear();
+ self_type &clear();
/** Bitwise AND.
*
@@ -405,11 +405,17 @@ public:
*/
static void reorder(raw_type &dst, in6_addr const &src);
- template < typename T > auto as_span() -> std::enable_if_t<swoc::meta::is_any_of_v<T, std::byte, uint8_t, uint16_t, uint32_t, uint64_t>, swoc::MemSpan<T>> {
+ template <typename T>
+ auto
+ as_span() -> std::enable_if_t<swoc::meta::is_any_of_v<T, std::byte, uint8_t, uint16_t, uint32_t, uint64_t>, swoc::MemSpan<T>> {
return swoc::MemSpan(_addr._store).template rebind<T>();
}
- template < typename T > auto as_span() const -> std::enable_if_t<swoc::meta::is_any_of_v<typename std::remove_const_t<T>, std::byte, uint8_t, uint16_t, uint32_t, uint64_t>, swoc::MemSpan<T const>> {
+ template <typename T>
+ auto
+ as_span() const
+ -> std::enable_if_t<swoc::meta::is_any_of_v<typename std::remove_const_t<T>, std::byte, uint8_t, uint16_t, uint32_t, uint64_t>,
+ swoc::MemSpan<T const>> {
return swoc::MemSpan<uint64_t const>(_addr._store).template rebind<T const>();
}
@@ -467,7 +473,7 @@ protected:
/// Index of bytes in @a _addr._raw
/// This converts MSB (0) to LSB (15) indices to the bytes in the binary format.
- static constexpr std::array<unsigned, SIZE> RAW_IDX = { 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8 };
+ static constexpr std::array<unsigned, SIZE> RAW_IDX = {7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8};
/// Convert between network and host order.
/// The conversion is symmetric.
@@ -480,7 +486,10 @@ protected:
* @param msw The most significant 64 bits, host order.
* @param lsw The least significant 64 bits, host order.
*/
- IP6Addr(word_store_type::value_type msw, word_store_type::value_type lsw) : _addr{{msw, lsw}} {}
+ IP6Addr(word_store_type::value_type msw, word_store_type::value_type lsw)
+ : _addr{
+ {msw, lsw}
+ } {}
friend IP6Addr operator&(IP6Addr const &addr, IPMask const &mask);
@@ -496,9 +505,9 @@ class IPAddr {
using self_type = IPAddr; ///< Self reference type.
public:
- IPAddr() = default; ///< Default constructor - invalid result.
- IPAddr(self_type const &that) = default; ///< Copy constructor.
- self_type & operator = (self_type const& that) = default; ///< Copy assignment.
+ IPAddr() = default; ///< Default constructor - invalid result.
+ IPAddr(self_type const &that) = default; ///< Copy constructor.
+ self_type &operator=(self_type const &that) = default; ///< Copy assignment.
/// Construct using IPv4 @a addr.
explicit IPAddr(in_addr_t addr);
@@ -570,7 +579,7 @@ public:
* @param sa Destination.
* @return @a sa
*/
- sockaddr * copy_to(sockaddr * sa);
+ sockaddr *copy_to(sockaddr *sa);
/** Parse a string and load the result in @a this.
*
@@ -635,8 +644,8 @@ protected:
/// Address data.
union raw_addr_type {
- IP4Addr _ip4; ///< IPv4 address (host)
- IP6Addr _ip6; ///< IPv6 address (host)
+ IP4Addr _ip4; ///< IPv4 address (host)
+ IP6Addr _ip6; ///< IPv6 address (host)
constexpr raw_addr_type();
@@ -704,7 +713,7 @@ public:
static self_type mask_for(IP6Addr const &addr);
/// Change to default constructed state (invalid).
- self_type & clear();
+ self_type &clear();
/// The width of the mask.
raw_type width() const;
@@ -716,7 +725,7 @@ public:
*
* Effectively shifts the mask left, bringing in 0 bits on the right.
*/
- self_type & operator<<=(raw_type n);
+ self_type &operator<<=(raw_type n);
/** Narrow the mask (cover fewer addresses).
*
@@ -725,7 +734,7 @@ public:
*
* Effectively shift the mask right, bringing in 1 bits on the left.
*/
- self_type & operator>>=(raw_type n);
+ self_type &operator>>=(raw_type n);
/** The mask as an IPv4 address.
*
@@ -822,7 +831,7 @@ IP4Addr::operator=(in_addr_t ip) -> self_type & {
inline sockaddr *
IP4Addr::copy_to(sockaddr *sa) const {
- this->copy_to(reinterpret_cast<sockaddr_in*>(sa));
+ this->copy_to(reinterpret_cast<sockaddr_in *>(sa));
return sa;
}
@@ -894,11 +903,12 @@ IP4Addr::is_link_local() const {
return (_addr & 0xFFFF0000) == 0xA9FE0000; // 169.254.0.0/16
}
-inline bool IP4Addr::is_private() const {
- return (((_addr & 0xFF000000) == 0x0A000000) || // 10.0.0.0/8
- ((_addr & 0xFFC00000) == 0x64400000) || // 100.64.0.0/10
+inline bool
+IP4Addr::is_private() const {
+ return (((_addr & 0xFF000000) == 0x0A000000) || // 10.0.0.0/8
+ ((_addr & 0xFFC00000) == 0x64400000) || // 100.64.0.0/10
((_addr & 0xFFF00000) == 0xAC100000) || // 172.16.0.0/12
- ((_addr & 0xFFFF0000) == 0xC0A80000) // 192.168.0.0/16
+ ((_addr & 0xFFFF0000) == 0xC0A80000) // 192.168.0.0/16
);
}
@@ -935,7 +945,7 @@ inline IP6Addr::IP6Addr(string_view const &text) {
}
inline IP6Addr::IP6Addr(IP4Addr addr) {
- _addr._store[MSW] = 0;
+ _addr._store[MSW] = 0;
_addr._quad[QUAD_IDX[4]] = 0;
_addr._quad[QUAD_IDX[5]] = 0xffff;
_addr._quad[QUAD_IDX[6]] = addr.host_order() >> QUAD_WIDTH;
@@ -967,19 +977,22 @@ IP6Addr::is_link_local() const {
return _addr._raw[RAW_IDX[0]] == 0xFE && (_addr._raw[RAW_IDX[1]] & 0xC0) == 0x80; // fe80::/10
}
-inline bool IP6Addr::is_private() const {
- return (_addr._raw[RAW_IDX[0]]& 0xFE) == 0xFC; // fc00::/7
+inline bool
+IP6Addr::is_private() const {
+ return (_addr._raw[RAW_IDX[0]] & 0xFE) == 0xFC; // fc00::/7
}
inline in6_addr
IP6Addr::host_order() const {
- Addr zret { {_addr._store[LSW], _addr._store[MSW] }};
+ Addr zret{
+ {_addr._store[LSW], _addr._store[MSW]}
+ };
return zret._in6;
}
inline in6_addr &
-IP6Addr::host_order(in6_addr & dst) const {
- Addr * addr = reinterpret_cast<Addr*>(&dst);
+IP6Addr::host_order(in6_addr &dst) const {
+ Addr *addr = reinterpret_cast<Addr *>(&dst);
addr->_store[0] = _addr._store[LSW];
addr->_store[1] = _addr._store[MSW];
return dst;
@@ -992,7 +1005,7 @@ IP6Addr::network_order() const {
}
inline in6_addr &
-IP6Addr::network_order(in6_addr & dst) const {
+IP6Addr::network_order(in6_addr &dst) const {
self_type::reorder(dst, _addr._raw);
return dst;
}
@@ -1045,20 +1058,23 @@ IP6Addr::reorder(unsigned char dst[WORD_SIZE], unsigned char const src[WORD_SIZE
/// @return @c true if @a lhs is equal to @a rhs.
inline bool
operator==(IP6Addr const &lhs, IP6Addr const &rhs) {
- return lhs._addr._store[IP6Addr::MSW] == rhs._addr._store[IP6Addr::MSW] && lhs._addr._store[IP6Addr::LSW] == rhs._addr._store[IP6Addr::LSW];
+ return lhs._addr._store[IP6Addr::MSW] == rhs._addr._store[IP6Addr::MSW] &&
+ lhs._addr._store[IP6Addr::LSW] == rhs._addr._store[IP6Addr::LSW];
}
/// @return @c true if @a lhs is not equal to @a rhs.
inline bool
operator!=(IP6Addr const &lhs, IP6Addr const &rhs) {
- return lhs._addr._store[IP6Addr::MSW] != rhs._addr._store[IP6Addr::MSW] || lhs._addr._store[IP6Addr::LSW] != rhs._addr._store[IP6Addr::LSW];
+ return lhs._addr._store[IP6Addr::MSW] != rhs._addr._store[IP6Addr::MSW] ||
+ lhs._addr._store[IP6Addr::LSW] != rhs._addr._store[IP6Addr::LSW];
}
/// @return @c true if @a lhs is less than @a rhs.
inline bool
operator<(IP6Addr const &lhs, IP6Addr const &rhs) {
return lhs._addr._store[IP6Addr::MSW] < rhs._addr._store[IP6Addr::MSW] ||
- (lhs._addr._store[IP6Addr::MSW] == rhs._addr._store[IP6Addr::MSW] && lhs._addr._store[IP6Addr::LSW] < rhs._addr._store[IP6Addr::LSW]);
+ (lhs._addr._store[IP6Addr::MSW] == rhs._addr._store[IP6Addr::MSW] &&
+ lhs._addr._store[IP6Addr::LSW] < rhs._addr._store[IP6Addr::LSW]);
}
/// @return @c true if @a lhs is greater than @a rhs.
@@ -1071,7 +1087,8 @@ operator>(IP6Addr const &lhs, IP6Addr const &rhs) {
inline bool
operator<=(IP6Addr const &lhs, IP6Addr const &rhs) {
return lhs._addr._store[IP6Addr::MSW] < rhs._addr._store[IP6Addr::MSW] ||
- (lhs._addr._store[IP6Addr::MSW] == rhs._addr._store[IP6Addr::MSW] && lhs._addr._store[IP6Addr::LSW] <= rhs._addr._store[IP6Addr::LSW]);
+ (lhs._addr._store[IP6Addr::MSW] == rhs._addr._store[IP6Addr::MSW] &&
+ lhs._addr._store[IP6Addr::LSW] <= rhs._addr._store[IP6Addr::LSW]);
}
/// @return @c true if @a lhs is greater than or equal to @a rhs.
@@ -1082,7 +1099,7 @@ operator>=(IP6Addr const &lhs, IP6Addr const &rhs) {
inline sockaddr *
IP6Addr::copy_to(sockaddr *sa) const {
- this->copy_to(reinterpret_cast<sockaddr_in6*>(sa));
+ this->copy_to(reinterpret_cast<sockaddr_in6 *>(sa));
return sa;
}
@@ -1160,7 +1177,7 @@ IPMask::as_ip4() const {
}
inline auto
-IPMask::clear() -> self_type & {
+IPMask::clear() -> self_type & {
_cidr = INVALID;
return *this;
}
@@ -1275,16 +1292,12 @@ IPAddr::is_loopback() const {
inline bool
IPAddr::is_link_local() const {
- return this->is_ip4() ? this->ip4().is_link_local()
- : this->is_ip6() ? this->ip6().is_link_local()
- : false;
+ return this->is_ip4() ? this->ip4().is_link_local() : this->is_ip6() ? this->ip6().is_link_local() : false;
}
inline bool
IPAddr::is_private() const {
- return this->is_ip4() ? this->ip4().is_private()
- : this->is_ip6() ? this->ip6().is_private()
- : false;
+ return this->is_ip4() ? this->ip4().is_private() : this->is_ip6() ? this->ip6().is_private() : false;
}
inline IPAddr &
@@ -1357,21 +1370,31 @@ operator!=(sockaddr const *lhs, IPAddr const &rhs) {
return !(rhs == lhs);
}
-inline IP4Addr const & IPAddr::ip4() const { return _addr._ip4; }
-inline IPAddr::operator IP4Addr() const { return _addr._ip4; }
+inline IP4Addr const &
+IPAddr::ip4() const {
+ return _addr._ip4;
+}
+inline IPAddr::operator IP4Addr() const {
+ return _addr._ip4;
+}
-inline IP6Addr const & IPAddr::ip6() const { return _addr._ip6; }
-inline IPAddr::operator IP6Addr() const { return _addr._ip6; }
+inline IP6Addr const &
+IPAddr::ip6() const {
+ return _addr._ip6;
+}
+inline IPAddr::operator IP6Addr() const {
+ return _addr._ip6;
+}
inline bool
IPAddr::operator==(self_type const &that) const {
switch (_family) {
case AF_INET:
return that._family == AF_INET && _addr._ip4 == that._addr._ip4;
- case AF_INET6:
- return that._family == AF_INET6 && _addr._ip6 == that._addr._ip6;
- default:
- return ! that.is_valid();
+ case AF_INET6:
+ return that._family == AF_INET6 && _addr._ip6 == that._addr._ip6;
+ default:
+ return !that.is_valid();
}
}
@@ -1442,14 +1465,16 @@ namespace std {
/// Standard hash support for @a IP4Addr.
template <> struct hash<swoc::IP4Addr> {
- size_t operator()(swoc::IP4Addr const &addr) const {
+ size_t
+ operator()(swoc::IP4Addr const &addr) const {
return addr.network_order();
}
};
/// Standard hash support for @a IP6Addr.
template <> struct hash<swoc::IP6Addr> {
- size_t operator()(swoc::IP6Addr const &addr) const {
+ size_t
+ operator()(swoc::IP6Addr const &addr) const {
// XOR the 64 chunks
auto words = addr.as_span<uint64_t>();
return words[0] ^ words[1];
@@ -1458,7 +1483,8 @@ template <> struct hash<swoc::IP6Addr> {
/// Standard hash support for @a IPAddr.
template <> struct hash<swoc::IPAddr> {
- size_t operator()(swoc::IPAddr const &addr) const {
+ size_t
+ operator()(swoc::IPAddr const &addr) const {
return addr.is_ip4() ? hash<swoc::IP4Addr>()(addr.ip4()) : addr.is_ip6() ? hash<swoc::IP6Addr>()(addr.ip6()) : 0;
}
};
diff --git a/code/include/swoc/IPEndpoint.h b/code/include/swoc/IPEndpoint.h
index f7779c9..edfa707 100644
--- a/code/include/swoc/IPEndpoint.h
+++ b/code/include/swoc/IPEndpoint.h
@@ -36,7 +36,7 @@ class IP6Srv;
for an IP endpoint is present.
*/
union IPEndpoint {
- using self_type = IPEndpoint; ///< Self reference type.
+ using self_type = IPEndpoint; ///< Self reference type.
using string_view = std::string_view;
struct sockaddr sa; ///< Generic address.
@@ -55,16 +55,16 @@ union IPEndpoint {
explicit IPEndpoint(IPAddr const &addr);
/// Construct from address and port.
- explicit IPEndpoint(IPSrv const& srv);
+ explicit IPEndpoint(IPSrv const &srv);
/// Construct from generic socket address.
IPEndpoint(sockaddr const *addr);
/// Construct from @a sockaddr_in
- IPEndpoint(sockaddr_in const* sin);
+ IPEndpoint(sockaddr_in const *sin);
/// Construct from @a sockaddr_in6
- IPEndpoint(sockaddr_in6 const * sin6);
+ IPEndpoint(sockaddr_in6 const *sin6);
/// Copy assignment.
self_type &operator=(self_type const &that);
@@ -120,34 +120,34 @@ union IPEndpoint {
* @param sin IPv4 socket address.
* @return @a this
*/
- self_type &assign(sockaddr_in const * sin);
+ self_type &assign(sockaddr_in const *sin);
/** Assign from IPv6 socket address.
*
* @param sin6 IPv6 socket address.
* @return @a this
*/
- self_type &assign(sockaddr_in6 const * sin6);
+ self_type &assign(sockaddr_in6 const *sin6);
/// Assign from IP address.
self_type &assign(IPAddr const &addr);
- [[deprecated("Use IPSrv")]] self_type &assign(IPAddr const& addr, in_port_t port);
+ [[deprecated("Use IPSrv")]] self_type &assign(IPAddr const &addr, in_port_t port);
/// Assign from IPv4 address.
- self_type &assign(IP4Addr const& addr);
+ self_type &assign(IP4Addr const &addr);
/// Assign from IPv4 address.
- self_type &assign(IP6Addr const& addr);
+ self_type &assign(IP6Addr const &addr);
/// Assign from IPv4 service.
- self_type &assign(IP4Srv const& srv);
+ self_type &assign(IP4Srv const &srv);
/// Assign from IPv6 service.
- self_type &assign(IP6Srv const& srv);
+ self_type &assign(IP6Srv const &srv);
/// Assign from IP service.
- self_type &assign(IPSrv const& srv);
+ self_type &assign(IPSrv const &srv);
/// Copy to @a sa.
const self_type ©_to(sockaddr *addr) const;
@@ -171,16 +171,16 @@ union IPEndpoint {
sa_family_t family() const;
/// @return A pointer to a @c sockaddr_in or @c nullptr if not IPv4.
- sockaddr_in * ip4();
+ sockaddr_in *ip4();
/// @return A pointer to a @c sockaddr_in or @c nullptr if not IPv4.
- sockaddr_in const * ip4() const;
+ sockaddr_in const *ip4() const;
/// @return A pointer to a @c sockaddr_in6 or @c nullptr if not IPv6.
- sockaddr_in6 * ip6();
+ sockaddr_in6 *ip6();
/// @return A pointer to a @c sockaddr_in6 or @c nullptr if not IPv6.
- sockaddr_in6 const * ip6() const;
+ sockaddr_in6 const *ip6() const;
/// Set to be the ANY address for family @a family.
/// @a family must be @c AF_INET or @c AF_INET6.
@@ -262,7 +262,7 @@ inline IPEndpoint::IPEndpoint(IPAddr const &addr) {
this->assign(addr);
}
-inline IPEndpoint::IPEndpoint(IPSrv const& srv) {
+inline IPEndpoint::IPEndpoint(IPSrv const &srv) {
this->assign(srv);
}
@@ -295,13 +295,13 @@ IPEndpoint::operator=(self_type const &that) {
}
inline IPEndpoint &
-IPEndpoint::assign(sockaddr_in const * sin) {
+IPEndpoint::assign(sockaddr_in const *sin) {
std::memcpy(&sa4, sin, sizeof(sockaddr_in));
return *this;
}
inline IPEndpoint &
-IPEndpoint::assign(sockaddr_in6 const * sin6) {
+IPEndpoint::assign(sockaddr_in6 const *sin6) {
std::memcpy(&sa6, sin6, sizeof(sockaddr_in6));
return *this;
}
@@ -355,7 +355,7 @@ IPEndpoint::ip6() const {
inline in_port_t
IPEndpoint::network_order_port() const {
- return this->is_valid() ? this->port(const_cast<sockaddr*>(&sa)) : 0;
+ return this->is_valid() ? this->port(const_cast<sockaddr *>(&sa)) : 0;
}
inline in_port_t
@@ -373,8 +373,8 @@ IPEndpoint::port(sockaddr *sa) {
switch (sa->sa_family) {
case AF_INET:
return reinterpret_cast<sockaddr_in *>(sa)->sin_port;
- case AF_INET6:
- return reinterpret_cast<sockaddr_in6 *>(sa)->sin6_port;
+ case AF_INET6:
+ return reinterpret_cast<sockaddr_in6 *>(sa)->sin6_port;
}
// Force a failure upstream by returning a null reference.
throw std::domain_error("sockaddr does not contain a valid IP address");
@@ -382,19 +382,21 @@ IPEndpoint::port(sockaddr *sa) {
inline in_port_t
IPEndpoint::network_order_port(sockaddr const *sa) {
- return self_type::is_valid(sa) ? self_type::port(const_cast<sockaddr*>(sa)) : 0;
+ return self_type::is_valid(sa) ? self_type::port(const_cast<sockaddr *>(sa)) : 0;
}
inline in_port_t
IPEndpoint::host_order_port(sockaddr const *sa) {
- return self_type::is_valid(sa) ? ntohs(self_type::port(const_cast<sockaddr*>(sa))) : 0;
+ return self_type::is_valid(sa) ? ntohs(self_type::port(const_cast<sockaddr *>(sa))) : 0;
}
inline swoc::MemSpan<void const>
IPEndpoint::raw_addr() const {
switch (sa.sa_family) {
- case AF_INET: return { &sa4.sin_addr , sizeof(sa4.sin_addr) };
- case AF_INET6: return { &sa6.sin6_addr, sizeof(sa6.sin6_addr) };
+ case AF_INET:
+ return {&sa4.sin_addr, sizeof(sa4.sin_addr)};
+ case AF_INET6:
+ return {&sa6.sin6_addr, sizeof(sa6.sin6_addr)};
}
return {};
}
diff --git a/code/include/swoc/IPRange.h b/code/include/swoc/IPRange.h
index c984a3d..197e6e6 100644
--- a/code/include/swoc/IPRange.h
+++ b/code/include/swoc/IPRange.h
@@ -83,7 +83,10 @@ public:
IPMask network_mask() const;
/// @return The range family.
- sa_family_t family() const { return AF_INET; }
+ sa_family_t
+ family() const {
+ return AF_INET;
+ }
class NetSource;
@@ -128,7 +131,7 @@ public:
using const_iterator = iterator;
iterator begin() const; ///< First network.
- static iterator end() ; ///< Past last network.
+ static iterator end(); ///< Past last network.
/// Return @c true if there are valid networks, @c false if not.
bool empty() const;
@@ -224,7 +227,10 @@ public:
IPMask network_mask() const;
/// @return The range family.
- sa_family_t family() const { return AF_INET6; }
+ sa_family_t
+ family() const {
+ return AF_INET6;
+ }
class NetSource;
@@ -281,7 +287,7 @@ public:
self_type *operator->();
/// @return The current network address.
- IP6Addr const & addr() const;
+ IP6Addr const &addr() const;
/// Iterator support.
/// @return The current network mask.
@@ -348,7 +354,7 @@ public:
*
* @param addr Address of range.
*/
- IPRange(IPAddr const& addr) : IPRange(addr, addr) {}
+ IPRange(IPAddr const &addr) : IPRange(addr, addr) {}
/** Construct a singleton range.
*
@@ -360,7 +366,7 @@ public:
*
* @param addr Address of range.
*/
- IPRange(IP6Addr const & addr) : IPRange(addr, addr) {}
+ IPRange(IP6Addr const &addr) : IPRange(addr, addr) {}
/// Construct from an IPv4 @a range.
IPRange(IP4Range const &range);
@@ -369,7 +375,7 @@ public:
IPRange(IP6Range const &range);
/// Construct from view.
- IPRange(IPRangeView const& view);
+ IPRange(IPRangeView const &view);
/** Construct from a string format.
*
@@ -385,7 +391,7 @@ public:
* @param max Maximum value.
* @return @a this.
*/
- self_type & assign(IP4Addr const& min, IP4Addr const& max);
+ self_type &assign(IP4Addr const &min, IP4Addr const &max);
/** Update with an IPv6 range.
*
@@ -393,15 +399,15 @@ public:
* @param max Maximum address.
* @return @a this
*/
- self_type & assign(IP6Addr const& min, IP6Addr const& max);
+ self_type &assign(IP6Addr const &min, IP6Addr const &max);
/// Assign from view.
- self_type & operator = (IPRangeView const& rv);
+ self_type &operator=(IPRangeView const &rv);
/// Equality
bool operator==(self_type const &that) const;
/// Inequality
- bool operator!=(self_type const& that) const;
+ bool operator!=(self_type const &that) const;
/// @return @c true if this is an IPv4 range, @c false if not.
bool is_ip4() const;
@@ -436,16 +442,25 @@ public:
bool empty() const;
/// Make the range empty / invalid.
- self_type & clear();
+ self_type &clear();
/// @return The IPv4 range.
- IP4Range const & ip4() const { return _range._ip4; }
+ IP4Range const &
+ ip4() const {
+ return _range._ip4;
+ }
/// @return The IPv6 range.
- IP6Range const & ip6() const { return _range._ip6; }
+ IP6Range const &
+ ip6() const {
+ return _range._ip6;
+ }
/// @return The range family.
- sa_family_t family() const { return _family; }
+ sa_family_t
+ family() const {
+ return _family;
+ }
/** Compute the mask for @a this as a network.
*
@@ -510,7 +525,7 @@ public:
explicit NetSource(range_type const &range);
/// Construct from view.
- explicit NetSource(IPRangeView const& rv);
+ explicit NetSource(IPRangeView const &rv);
/// Copy constructor.
NetSource(self_type const &that) = default;
@@ -551,7 +566,7 @@ public:
protected:
union {
- std::monostate _nil; ///< Default value, no addresses.
+ std::monostate _nil; ///< Default value, no addresses.
IP4Range::NetSource _ip4; ///< IPv4 addresses.
IP6Range::NetSource _ip6; ///< IPv6 addresses.
};
@@ -580,15 +595,15 @@ class IPRangeView {
/// Storage for the view pointer - union because only one can be valid.
union storage_type {
std::monostate _nil; ///< No data present.
- IP4Range const * _4; ///< IPv4 range.
- IP6Range const * _6; ///< IPv6 range.
- void const * _void; ///< Used only for fast copy in construction and assignment.
+ IP4Range const *_4; ///< IPv4 range.
+ IP6Range const *_6; ///< IPv6 range.
+ void const *_void; ///< Used only for fast copy in construction and assignment.
// These constructors are needed to make the default construction / assignent methods work.
// Otherwise the compiler thinks the union isn't initialized.
storage_type() = default;
storage_type(std::monostate) {}
- storage_type(storage_type const& that);
+ storage_type(storage_type const &that);
storage_type & operator = (storage_type const& rhs);
};
@@ -597,7 +612,7 @@ public:
IPRangeView() = default;
/// Compare to a range.
- bool operator == (IPRange const& r) const;
+ bool operator==(IPRange const &r) const;
/// @return @c true if there is no valid view to a range.
bool valid() const;
@@ -606,13 +621,13 @@ public:
bool empty() const;
/// Reset to invalid view.
- self_type & clear();
+ self_type &clear();
/// Update the view.
- self_type & assign(IP4Range const& r);
+ self_type &assign(IP4Range const &r);
/// Update the view.
- self_type & assign(IP6Range const& r);
+ self_type &assign(IP6Range const &r);
/// @return @c true if this is an IPv4 range.
bool is_ip4() const;
@@ -628,10 +643,10 @@ public:
bool is(sa_family_t family) const;
/// @return Reference to the viewed IPv4 range.
- IP4Range const& ip4() const;
+ IP4Range const &ip4() const;
/// @return Reference to the viewd IPv6 range.
- IP6Range const& ip6() const;
+ IP6Range const &ip6() const;
/// @{
/// Forwarding methods.
@@ -643,10 +658,10 @@ public:
IPAddr max() const;
/// Equality.
- bool operator == (self_type const& that) const;
+ bool operator==(self_type const &that) const;
/// Inequality.
- bool operator != (self_type const& that) const;
+ bool operator!=(self_type const &that) const;
/** Generate a list of networks covering @a this range.
*
@@ -654,13 +669,16 @@ public:
*
* @see IPRange::networks
*/
- IPRange::NetSource networks() const { return IPRange::NetSource(*this); }
+ IPRange::NetSource
+ networks() const {
+ return IPRange::NetSource(*this);
+ }
/// @}
protected:
- storage_type _raw = { std::monostate() }; ///< Storage for the view pointer.
- sa_family_t _family = AF_UNSPEC; ///< Range address family.
+ storage_type _raw = {std::monostate()}; ///< Storage for the view pointer.
+ sa_family_t _family = AF_UNSPEC; ///< Range address family.
};
/// An IPv4 network.
@@ -714,7 +732,11 @@ public:
self_type &assign(IP4Addr const &addr, IPMask const &mask);
/// Reset network to invalid state.
- self_type & clear() { _mask.clear(); return *this; }
+ self_type &
+ clear() {
+ _mask.clear();
+ return *this;
+ }
/// Equality.
bool operator==(self_type const &that) const;
@@ -857,13 +879,22 @@ public:
IPRange as_range() const;
/// @return @c true if network is IPv4.
- bool is_ip4() const { return _addr.is_ip4(); }
+ bool
+ is_ip4() const {
+ return _addr.is_ip4();
+ }
/// @return @c true if network is IPv6.
- bool is_ip6() const { return _addr.is_ip6(); }
+ bool
+ is_ip6() const {
+ return _addr.is_ip6();
+ }
/// Address family of network.
- sa_family_t family() const { return _addr.family(); }
+ sa_family_t
+ family() const {
+ return _addr.family();
+ }
/// @return The network as explicitly IPv4.
IP4Net ip4() const;
@@ -880,7 +911,7 @@ public:
self_type &assign(IPAddr const &addr, IPMask const &mask);
/// Reset network to invalid state.
- self_type & clear();
+ self_type &clear();
/// Equality.
bool operator==(self_type const &that) const;
@@ -912,16 +943,16 @@ namespace detail {
*
* @see IPSpace
*/
-template < typename PAYLOAD > struct ip_space_const_value_type {
+template <typename PAYLOAD> struct ip_space_const_value_type {
using self_type = ip_space_const_value_type;
- IPRangeView _rv; ///< View to the current range.
- PAYLOAD * _payload = nullptr; ///< Payload for @a _range.
+ IPRangeView _rv; ///< View to the current range.
+ PAYLOAD *_payload = nullptr; ///< Payload for @a _range.
ip_space_const_value_type() = default;
/// Reset to default constructed state.
- self_type & clear();
+ self_type &clear();
/** Update the internal state.
*
@@ -929,7 +960,7 @@ template < typename PAYLOAD > struct ip_space_const_value_type {
* @param payload Payload.
* @return @a this.
*/
- self_type & assign(IP4Range const& r, PAYLOAD & payload);
+ self_type &assign(IP4Range const &r, PAYLOAD &payload);
/** Update the internal state.
*
@@ -937,29 +968,41 @@ template < typename PAYLOAD > struct ip_space_const_value_type {
* @param payload Payload.
* @return @a this.
*/
- self_type & assign(IP6Range const& r, PAYLOAD & payload);
+ self_type &assign(IP6Range const &r, PAYLOAD &payload);
/** Update from another instance.
*
* @param that Other instance.
* @return @a this.
*/
- self_type & assign(self_type const& that);
+ self_type &assign(self_type const &that);
/// Support assignemnt to @c std::tie.
- std::tuple<IPRangeView, PAYLOAD &> tuple() const { return { _rv, *_payload }; }
+ std::tuple<IPRangeView, PAYLOAD &>
+ tuple() const {
+ return {_rv, *_payload};
+ }
/// Equality against an equivalent tuple.
- bool operator == (std::tuple<swoc::IPRange, PAYLOAD> const& t) const;
+ bool operator==(std::tuple<swoc::IPRange, PAYLOAD> const &t) const;
/// @return The address range.
- IPRange range() const { return _rv; }
+ IPRange
+ range() const {
+ return _rv;
+ }
/// @return The range view.
- IPRangeView range_view() const { return _rv; }
+ IPRangeView
+ range_view() const {
+ return _rv;
+ }
/// @return A reference to the payload (user content).
- PAYLOAD const & payload() const { return *_payload; }
+ PAYLOAD const &
+ payload() const {
+ return *_payload;
+ }
};
/** Value type for @c IPSpace.
@@ -974,13 +1017,15 @@ template < typename PAYLOAD > struct ip_space_const_value_type {
*
* @see IPSpace
*/
-template < typename PAYLOAD > struct ip_space_value_type : ip_space_const_value_type<PAYLOAD> {
- using self_type = ip_space_value_type;
+template <typename PAYLOAD> struct ip_space_value_type : ip_space_const_value_type<PAYLOAD> {
+ using self_type = ip_space_value_type;
using super_type = ip_space_const_value_type<PAYLOAD>;
/// @return A reference to the payload (user content).
- PAYLOAD & payload() { return *super_type::_payload; }
-
+ PAYLOAD &
+ payload() {
+ return *super_type::_payload;
+ }
};
template <typename PAYLOAD>
@@ -993,7 +1038,7 @@ ip_space_const_value_type<PAYLOAD>::clear() -> self_type & {
template <typename PAYLOAD>
auto
-ip_space_const_value_type<PAYLOAD>::assign(IP4Range const &r, PAYLOAD &payload) -> self_type &{
+ip_space_const_value_type<PAYLOAD>::assign(IP4Range const &r, PAYLOAD &payload) -> self_type & {
_rv.assign(r);
_payload = &payload;
return *this;
@@ -1010,7 +1055,7 @@ ip_space_const_value_type<PAYLOAD>::assign(IP6Range const &r, PAYLOAD &payload)
template <typename PAYLOAD>
auto
ip_space_const_value_type<PAYLOAD>::assign(ip_space_const_value_type::self_type const &that) -> self_type & {
- _rv = that._rv;
+ _rv = that._rv;
_payload = that._payload;
return *this;
}
@@ -1042,7 +1087,7 @@ template <typename PAYLOAD> class IPSpace {
using IP6Space = DiscreteSpace<IP6Addr, PAYLOAD>;
public:
- using payload_t = PAYLOAD; ///< Export payload type.
+ using payload_t = PAYLOAD; ///< Export payload type.
/// Iterator value, a range and payload.
using value_type = detail::ip_space_value_type<PAYLOAD>;
@@ -1097,11 +1142,9 @@ public:
*/
template <typename F, typename U = PAYLOAD> self_type &blend(IPRange const &range, U const &color, F &&blender);
- template <typename F, typename U = PAYLOAD>
- self_type & blend(IP4Range const &range, U const &color, F &&blender);
+ template <typename F, typename U = PAYLOAD> self_type &blend(IP4Range const &range, U const &color, F &&blender);
- template <typename F, typename U = PAYLOAD>
- self_type & blend(IP6Range const &range, U const &color, F &&blender);
+ template <typename F, typename U = PAYLOAD> self_type &blend(IP6Range const &range, U const &color, F &&blender);
/// @return The number of distinct ranges.
size_t count() const;
@@ -1222,9 +1265,15 @@ public:
// and returning that type without a cast creates a temporary which causes some nasty side effects.
/// @return Properly type cast range from iterator.
- IP4Range const& r4() { return static_cast<IP4Range const&>(_iter_4->range()); }
+ IP4Range const &
+ r4() {
+ return static_cast<IP4Range const &>(_iter_4->range());
+ }
/// @return Properly type cast range from iterator.
- IP6Range const& r6() { return static_cast<IP6Range const&>(_iter_6->range()); }
+ IP6Range const &
+ r6() {
+ return static_cast<IP6Range const &>(_iter_6->range());
+ }
};
/** Iterator.
@@ -1243,7 +1292,8 @@ public:
using super_type::super_type; /// Inherit supertype constructors.
/// Protected constructor to convert const to non-const.
/// @note This makes for much less code duplication in iterator relevant methods.
- iterator(const_iterator const& that) : const_iterator(that) {}
+ iterator(const_iterator const &that) : const_iterator(that) {}
+
public:
/// Value type of iteration.
using value_type = detail::ip_space_value_type<PAYLOAD>;
@@ -1289,7 +1339,7 @@ public:
protected:
// Retrieve the value and convert from the super (const) type value to the value for iterator.
- value_type & value() const;
+ value_type &value() const;
};
/** Find the payload for an @a addr.
@@ -1376,9 +1426,10 @@ public:
* @param r Search range.
* @return Iterator pair covering ranges that intersect @a r.
*/
- std::pair<iterator, iterator> intersection(IP4Range const& r) {
- auto && [ begin, end ] = _ip4.intersection(r);
- return { this->iterator_at(begin), this->iterator_at(end) };
+ std::pair<iterator, iterator>
+ intersection(IP4Range const &r) {
+ auto &&[begin, end] = _ip4.intersection(r);
+ return {this->iterator_at(begin), this->iterator_at(end)};
}
/** Sequnce of ranges that intersect @a r.
@@ -1386,9 +1437,10 @@ public:
* @param r Search range.
* @return Iterator pair covering ranges that intersect @a r.
*/
- std::pair<iterator, iterator> intersection(IP6Range const& r) {
- auto && [ begin, end ] = _ip6.intersection(r);
- return { this->iterator_at(begin), this->iterator_at(end) };
+ std::pair<iterator, iterator>
+ intersection(IP6Range const &r) {
+ auto &&[begin, end] = _ip6.intersection(r);
+ return {this->iterator_at(begin), this->iterator_at(end)};
}
/** Sequnce of ranges that intersect @a r.
@@ -1396,23 +1448,26 @@ public:
* @param r Search range.
* @return Iterator pair covering ranges that intersect @a r.
*/
- std::pair<iterator, iterator> intersection(IPRange const& r) {
+ std::pair<iterator, iterator>
+ intersection(IPRange const &r) {
if (r.is_ip4()) {
return this->intersection(r.ip4());
} else if (r.is_ip6()) {
return this->intersection(r.ip6());
}
- return { this->end(), this->end() };
+ return {this->end(), this->end()};
}
protected:
IP4Space _ip4; ///< Sub-space containing IPv4 ranges.
IP6Space _ip6; ///< sub-space containing IPv6 ranges.
- iterator iterator_at(typename IP4Space::const_iterator const& spot) {
+ iterator
+ iterator_at(typename IP4Space::const_iterator const &spot) {
return iterator(spot, _ip6.begin());
}
- iterator iterator_at(typename IP6Space::const_iterator const& spot) {
+ iterator
+ iterator_at(typename IP6Space::const_iterator const &spot) {
return iterator(_ip4.end(), spot);
}
@@ -1427,8 +1482,7 @@ protected:
*
* @note Because there is only one value stored, there is no difference between @c mark and @c fill.
*/
-class IPRangeSet
-{
+class IPRangeSet {
using self_type = IPRangeSet;
/// Empty struct to use for payload.
@@ -1480,7 +1534,7 @@ public:
/// Bidirectional constant iterator for iteration over ranges.
class const_iterator {
- using self_type = const_iterator; ///< Self reference type.
+ using self_type = const_iterator; ///< Self reference type.
using super_type = Space::const_iterator;
friend class IPRangeSet;
@@ -1536,18 +1590,24 @@ public:
bool operator!=(self_type const &that) const;
protected:
- const_iterator(super_type const& spot) : _iter(spot) {}
+ const_iterator(super_type const &spot) : _iter(spot) {}
super_type _iter; ///< Underlying iterator.
- IPRange _r; ///< Some less temporary storage for dereferences.
+ IPRange _r; ///< Some less temporary storage for dereferences.
};
using iterator = const_iterator;
/// @return Iterator to first range.
- const_iterator begin() const { return _addrs.begin(); }
+ const_iterator
+ begin() const {
+ return _addrs.begin();
+ }
/// @return Iterator past last range.
- const_iterator end() const { return _addrs.end(); }
+ const_iterator
+ end() const {
+ return _addrs.end();
+ }
protected:
/// The address set.
@@ -1555,28 +1615,24 @@ protected:
};
inline auto
-IPRangeSet::mark(swoc::IPRange const &r) -> self_type &
-{
+IPRangeSet::mark(swoc::IPRange const &r) -> self_type & {
_addrs.mark(r, MARK);
return *this;
}
inline auto
-IPRangeSet::fill(swoc::IPRange const &r) -> self_type &
-{
+IPRangeSet::fill(swoc::IPRange const &r) -> self_type & {
_addrs.mark(r, MARK);
return *this;
}
inline bool
-IPRangeSet::contains(swoc::IPAddr const &addr) const
-{
+IPRangeSet::contains(swoc::IPAddr const &addr) const {
return _addrs.find(addr) != _addrs.end();
}
inline size_t
-IPRangeSet::count() const
-{
+IPRangeSet::count() const {
return _addrs.count();
}
@@ -1586,26 +1642,25 @@ IPRangeSet::empty() const {
}
inline void
-IPRangeSet::clear()
-{
+IPRangeSet::clear() {
_addrs.clear();
}
inline bool
-IPRangeSet::Mark::operator==(IPRangeSet::Mark::self_type const &)
-{
+IPRangeSet::Mark::operator==(IPRangeSet::Mark::self_type const &) {
return true;
}
inline bool
-IPRangeSet::Mark::operator!=(IPRangeSet::Mark::self_type const &)
-{
+IPRangeSet::Mark::operator!=(IPRangeSet::Mark::self_type const &) {
return false;
}
template <typename PAYLOAD>
-IPSpace<PAYLOAD>::const_iterator::const_iterator(typename IP4Space::const_iterator const &iter4, typename IP6Space::const_iterator const &iter6)
-: _iter_4(static_cast<typename IP4Space::iterator const&>(iter4)), _iter_6(static_cast<typename IP6Space::iterator const&>(iter6)) {
+IPSpace<PAYLOAD>::const_iterator::const_iterator(typename IP4Space::const_iterator const &iter4,
+ typename IP6Space::const_iterator const &iter6)
+ : _iter_4(static_cast<typename IP4Space::iterator const &>(iter4)),
+ _iter_6(static_cast<typename IP6Space::iterator const &>(iter6)) {
if (_iter_4.has_next()) {
_value.assign(this->r4(), _iter_4->payload());
} else if (_iter_6.has_next()) {
@@ -1720,7 +1775,7 @@ IPSpace<PAYLOAD>::iterator::operator=(self_type const &that) -> self_type & {
template <typename PAYLOAD>
auto
IPSpace<PAYLOAD>::iterator::value() const -> value_type & {
- return reinterpret_cast<value_type&>(const_cast<self_type*>(this)->_value);
+ return reinterpret_cast<value_type &>(const_cast<self_type *>(this)->_value);
}
template <typename PAYLOAD>
@@ -1814,7 +1869,7 @@ inline IPRange::IPRange(string_view const &text) {
this->load(text);
}
-inline IPRange::IPRange(IPRangeView const& view) {
+inline IPRange::IPRange(IPRangeView const &view) {
if (AF_INET == view._family) {
*this = *view._raw._4;
} else if (AF_INET6 == view._family) {
@@ -1864,7 +1919,7 @@ IPRange::is(sa_family_t family) const {
inline bool
IPRange::operator!=(const self_type &that) const {
- return ! (*this == that);
+ return !(*this == that);
}
inline bool
@@ -1872,7 +1927,8 @@ IPRange::is_ip4() const {
return AF_INET == _family;
}
-inline bool IPRange::is_ip6() const {
+inline bool
+IPRange::is_ip6() const {
return AF_INET6 == _family;
}
@@ -1884,23 +1940,38 @@ IPRangeView::clear() -> self_type & {
inline bool
IPRangeView::empty() const {
- return AF_INET6 == _family ? _raw._6->empty()
- : AF_INET == _family ? _raw._4->empty()
- : true;
+ return AF_INET6 == _family ? _raw._6->empty() : AF_INET == _family ? _raw._4->empty() : true;
}
-inline bool IPRangeView::is_ip4() const { return AF_INET == _family; }
+inline bool
+IPRangeView::is_ip4() const {
+ return AF_INET == _family;
+}
-inline bool IPRangeView::is_ip6() const { return AF_INET6 == _family; }
+inline bool
+IPRangeView::is_ip6() const {
+ return AF_INET6 == _family;
+}
-inline bool IPRangeView::is(sa_family_t f) const { return f == _family; }
+inline bool
+IPRangeView::is(sa_family_t f) const {
+ return f == _family;
+}
-inline IP4Range const & IPRangeView::ip4() const { return *_raw._4; }
+inline IP4Range const &
+IPRangeView::ip4() const {
+ return *_raw._4;
+}
-inline IP6Range const & IPRangeView::ip6() const { return *_raw._6; }
+inline IP6Range const &
+IPRangeView::ip6() const {
+ return *_raw._6;
+}
inline bool
-IPRangeView::valid() const { return AF_INET == _family || AF_INET6 == _family; }
+IPRangeView::valid() const {
+ return AF_INET == _family || AF_INET6 == _family;
+}
inline auto
IPRangeView::assign(IP4Range const &r) -> self_type & {
@@ -1918,7 +1989,7 @@ IPRangeView::assign(IP6Range const &r) -> self_type & {
inline bool
IPRangeView::operator!=(IPRangeView::self_type const &that) const {
- return ! (*this == that);
+ return !(*this == that);
}
inline IPAddr
@@ -1942,7 +2013,7 @@ IP4Net::mask() const {
inline bool
IP4Net::empty() const {
- return ! _mask.is_valid();
+ return !_mask.is_valid();
}
inline IP4Addr
@@ -1986,7 +2057,7 @@ IP6Net::mask() const {
inline bool
IP6Net::empty() const {
- return ! _mask.is_valid();
+ return !_mask.is_valid();
}
inline IP6Addr
@@ -2029,7 +2100,7 @@ inline IPNet::IPNet(TextView text) {
inline bool
IPNet::empty() const {
- return ! _mask.is_valid();
+ return !_mask.is_valid();
}
inline IPAddr
@@ -2373,44 +2444,76 @@ IPSpace<PAYLOAD>::clear() {
}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::begin() -> iterator { return iterator{_ip4.begin(), _ip6.begin()}; }
+auto
+IPSpace<PAYLOAD>::begin() -> iterator {
+ return iterator{_ip4.begin(), _ip6.begin()};
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::begin() const -> const_iterator { return const_cast<self_type *>(this)->begin(); }
+auto
+IPSpace<PAYLOAD>::begin() const -> const_iterator {
+ return const_cast<self_type *>(this)->begin();
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::end() -> iterator { return iterator{_ip4.end(), _ip6.end()}; }
+auto
+IPSpace<PAYLOAD>::end() -> iterator {
+ return iterator{_ip4.end(), _ip6.end()};
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::end() const -> const_iterator { return const_cast<self_type *>(this)->end(); }
+auto
+IPSpace<PAYLOAD>::end() const -> const_iterator {
+ return const_cast<self_type *>(this)->end();
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::begin_ip4() -> iterator { return this->begin(); }
+auto
+IPSpace<PAYLOAD>::begin_ip4() -> iterator {
+ return this->begin();
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::begin_ip4() const -> const_iterator { return this->begin(); }
+auto
+IPSpace<PAYLOAD>::begin_ip4() const -> const_iterator {
+ return this->begin();
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::end_ip4() -> iterator { return { _ip4.end(), _ip6.begin() }; }
+auto
+IPSpace<PAYLOAD>::end_ip4() -> iterator {
+ return {_ip4.end(), _ip6.begin()};
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::end_ip4() const -> const_iterator { return const_cast<self_type*>(this)->end_ip4(); }
+auto
+IPSpace<PAYLOAD>::end_ip4() const -> const_iterator {
+ return const_cast<self_type *>(this)->end_ip4();
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::begin_ip6() -> iterator {
- return { _ip4.end(), _ip6.begin() };
+auto
+IPSpace<PAYLOAD>::begin_ip6() -> iterator {
+ return {_ip4.end(), _ip6.begin()};
}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::begin_ip6() const -> const_iterator {
- return const_cast<self_type*>(this)->begin_ip6();
+auto
+IPSpace<PAYLOAD>::begin_ip6() const -> const_iterator {
+ return const_cast<self_type *>(this)->begin_ip6();
}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::end_ip6() -> iterator { return this->end(); }
+auto
+IPSpace<PAYLOAD>::end_ip6() -> iterator {
+ return this->end();
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::end_ip6() const -> const_iterator { return this->end(); }
+auto
+IPSpace<PAYLOAD>::end_ip6() const -> const_iterator {
+ return this->end();
+}
template <typename PAYLOAD>
auto
@@ -2424,7 +2527,8 @@ IPSpace<PAYLOAD>::find(IPAddr const &addr) -> iterator {
}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::find(IPAddr const &addr) const -> const_iterator {
+auto
+IPSpace<PAYLOAD>::find(IPAddr const &addr) const -> const_iterator {
if (addr.is_ip4()) {
return this->find(addr.ip4());
} else if (addr.is_ip6()) {
@@ -2436,8 +2540,8 @@ auto IPSpace<PAYLOAD>::find(IPAddr const &addr) const -> const_iterator {
template <typename PAYLOAD>
auto
IPSpace<PAYLOAD>::find(IP4Addr const &addr) -> iterator {
- if ( auto spot = _ip4.find(addr) ; spot != _ip4.end()) {
- return { spot, _ip6.begin() };
+ if (auto spot = _ip4.find(addr); spot != _ip4.end()) {
+ return {spot, _ip6.begin()};
}
return this->end();
}
@@ -2445,17 +2549,23 @@ IPSpace<PAYLOAD>::find(IP4Addr const &addr) -> iterator {
template <typename PAYLOAD>
auto
IPSpace<PAYLOAD>::find(IP4Addr const &addr) const -> const_iterator {
- if ( auto spot = _ip4.find(addr) ; spot != _ip4.end()) {
- return { spot, _ip6.begin() };
+ if (auto spot = _ip4.find(addr); spot != _ip4.end()) {
+ return {spot, _ip6.begin()};
}
return this->end();
}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::find(IP6Addr const &addr) -> iterator { return {_ip4.end(), _ip6.find(addr)}; }
+auto
+IPSpace<PAYLOAD>::find(IP6Addr const &addr) -> iterator {
+ return {_ip4.end(), _ip6.find(addr)};
+}
template <typename PAYLOAD>
-auto IPSpace<PAYLOAD>::find(IP6Addr const &addr) const -> const_iterator { return const_iterator{_ip4.end(), _ip6.find(addr)}; }
+auto
+IPSpace<PAYLOAD>::find(IP6Addr const &addr) const -> const_iterator {
+ return const_iterator{_ip4.end(), _ip6.find(addr)};
+}
template <typename PAYLOAD>
auto
@@ -2563,7 +2673,9 @@ namespace std {
// -- Tuple support for IP4Net --
template <> class tuple_size<swoc::IP4Net> : public std::integral_constant<size_t, 2> {};
-template <size_t IDX> class tuple_element<IDX, swoc::IP4Net> { static_assert("swoc::IP4Net tuple index out of range"); };
+template <size_t IDX> class tuple_element<IDX, swoc::IP4Net> {
+ static_assert("swoc::IP4Net tuple index out of range");
+};
template <> class tuple_element<0, swoc::IP4Net> {
public:
@@ -2578,7 +2690,9 @@ public:
// -- Tuple support for IP6Net --
template <> class tuple_size<swoc::IP6Net> : public std::integral_constant<size_t, 2> {};
-template <size_t IDX> class tuple_element<IDX, swoc::IP6Net> { static_assert("swoc::IP6Net tuple index out of range"); };
+template <size_t IDX> class tuple_element<IDX, swoc::IP6Net> {
+ static_assert("swoc::IP6Net tuple index out of range");
+};
template <> class tuple_element<0, swoc::IP6Net> {
public:
@@ -2593,7 +2707,9 @@ public:
// -- Tuple support for IPNet --
template <> class tuple_size<swoc::IPNet> : public std::integral_constant<size_t, 2> {};
-template <size_t IDX> class tuple_element<IDX, swoc::IPNet> { static_assert("swoc::IPNet tuple index out of range"); };
+template <size_t IDX> class tuple_element<IDX, swoc::IPNet> {
+ static_assert("swoc::IPNet tuple index out of range");
+};
template <> class tuple_element<0, swoc::IPNet> {
public:
@@ -2682,7 +2798,7 @@ public:
namespace swoc { inline namespace SWOC_VERSION_NS { namespace detail {
template <size_t IDX, typename P>
auto
-get(ip_space_const_value_type<P> const& p) -> typename std::tuple_element<IDX, ip_space_const_value_type<P>>::type {
+get(ip_space_const_value_type<P> const &p) -> typename std::tuple_element<IDX, ip_space_const_value_type<P>>::type {
if constexpr (IDX == 0) {
return p._rv;
} else if constexpr (IDX == 1) {
@@ -2692,18 +2808,20 @@ get(ip_space_const_value_type<P> const& p) -> typename std::tuple_element<IDX, i
template <size_t IDX, typename P>
auto
-get(ip_space_value_type<P> const& p) -> typename std::tuple_element<IDX, ip_space_value_type<P>>::type {
+get(ip_space_value_type<P> const &p) -> typename std::tuple_element<IDX, ip_space_value_type<P>>::type {
if constexpr (IDX == 0) {
return p._rv;
} else if constexpr (IDX == 1) {
return *(p._payload);
}
}
-}}} // namespace swoc::detail
+}}} // namespace swoc::SWOC_VERSION_NS::detail
// Support unqualified @c get because ADL doesn't seem to work.
using swoc::detail::get;
// Support @c std::get
-namespace std { using swoc::detail::get; }
+namespace std {
+using swoc::detail::get;
+}
/// @endcond
diff --git a/code/include/swoc/IPSrv.h b/code/include/swoc/IPSrv.h
index e0e4d48..de2f5e8 100644
--- a/code/include/swoc/IPSrv.h
+++ b/code/include/swoc/IPSrv.h
@@ -37,13 +37,13 @@ public:
*
* If @a that is not IPv4 the result is a default constructed instance.
*/
- explicit IP4Srv(IPSrv const& that);
+ explicit IP4Srv(IPSrv const &that);
/** Construct from socket address.
*
* @param sa Socket address.
*/
- IP4Srv(sockaddr_in const * s) : _addr(s), _port(ntohs(s->sin_port)) {}
+ IP4Srv(sockaddr_in const *s) : _addr(s), _port(ntohs(s->sin_port)) {}
/** Construct from a string.
*
@@ -54,10 +54,10 @@ public:
explicit IP4Srv(swoc::TextView text);
/// Implicit conversion to an address.
- constexpr operator IP4Addr const& () const;
+ constexpr operator IP4Addr const &() const;
/// @return The address.
- constexpr IP4Addr const& addr() const;
+ constexpr IP4Addr const &addr() const;
/// @return The host_order_port in host order.
in_port_t host_order_port() const;
@@ -70,13 +70,13 @@ public:
/// @note Useful primarily for template classes.
static constexpr sa_family_t family();
- bool operator == (self_type that) const;
- bool operator != (self_type that) const;
+ bool operator==(self_type that) const;
+ bool operator!=(self_type that) const;
- bool operator < (self_type that) const;
- bool operator <= (self_type const& that) const;
- bool operator > (self_type const& that) const;
- bool operator >= (self_type const& that) const;
+ bool operator<(self_type that) const;
+ bool operator<=(self_type const &that) const;
+ bool operator>(self_type const &that) const;
+ bool operator>=(self_type const &that) const;
/** Load from a string.
*
@@ -90,14 +90,14 @@ public:
* @param addr Address to assign.
* @return @a this
*/
- self_type & assign(IP4Addr const& addr);
+ self_type &assign(IP4Addr const &addr);
/** Change the host_order_port.
*
* @param port Port to assign.
* @return @a this.
*/
- self_type & assign(in_port_t port);
+ self_type &assign(in_port_t port);
/** Change the address and port.
*
@@ -105,17 +105,17 @@ public:
* @param port Port to assign.
* @return @a this
*/
- self_type & assign(IP4Addr const& addr, in_port_t port);
+ self_type &assign(IP4Addr const &addr, in_port_t port);
/** Change the address and port.
*
* @param s A socket address.
* @return @a this
*/
- self_type & assign(sockaddr_in const * s);
+ self_type &assign(sockaddr_in const *s);
protected:
- IP4Addr _addr; ///< Address.
+ IP4Addr _addr; ///< Address.
in_port_t _port = 0; ///< Port.
};
@@ -140,13 +140,13 @@ public:
*
* If @a that is not IPv6 the result is a default constructed instance.
*/
- explicit IP6Srv(IPSrv const& that);
+ explicit IP6Srv(IPSrv const &that);
/** Construct from a socket address.
*
* @param s Socket address.
*/
- explicit IP6Srv(sockaddr_in6 const * s);
+ explicit IP6Srv(sockaddr_in6 const *s);
/** Construct from a string.
*
@@ -164,10 +164,10 @@ public:
bool load(swoc::TextView text);
/// Implicit conversion to address.
- constexpr operator IP6Addr const& () const;
+ constexpr operator IP6Addr const &() const;
/// @return The address.
- constexpr IP6Addr const& addr() const;
+ constexpr IP6Addr const &addr() const;
/// @return The port in host order.
in_port_t host_order_port() const;
/// @return The port in network order.
@@ -178,27 +178,27 @@ public:
/// @note Useful primarily for template classes.
static constexpr sa_family_t family();
- bool operator == (self_type that) const;
- bool operator != (self_type that) const;
+ bool operator==(self_type that) const;
+ bool operator!=(self_type that) const;
- bool operator < (self_type that) const;
- bool operator <= (self_type const& that) const;
- bool operator > (self_type const& that) const;
- bool operator >= (self_type const& that) const;
+ bool operator<(self_type that) const;
+ bool operator<=(self_type const &that) const;
+ bool operator>(self_type const &that) const;
+ bool operator>=(self_type const &that) const;
/** Change the address.
*
* @param addr Address to assign.
* @return @a this
*/
- self_type & assign(IP6Addr const& addr);
+ self_type &assign(IP6Addr const &addr);
/** Change the host_order_port.
*
* @param port Port to assign.
* @return @a this.
*/
- self_type & assign(in_port_t port);
+ self_type &assign(in_port_t port);
/** Change the address and host_order_port.
*
@@ -206,17 +206,17 @@ public:
* @param port Port to assign.
* @return @a this
*/
- self_type & assign(IP6Addr const& addr, in_port_t port);
+ self_type &assign(IP6Addr const &addr, in_port_t port);
/** Change the address and port.
*
* @param s A socket address.
* @return @a this
*/
- self_type & assign(sockaddr_in6 const * s);
+ self_type &assign(sockaddr_in6 const *s);
protected:
- IP6Addr _addr; ///< Address.
+ IP6Addr _addr; ///< Address.
in_port_t _port = 0; ///< Port.
};
@@ -230,10 +230,10 @@ public:
explicit IPSrv(IP4Addr addr, in_port_t port = 0) : _srv(IP4Srv{addr, port}), _family(addr.family()) {}
explicit IPSrv(IP6Addr addr, in_port_t port = 0) : _srv(IP6Srv{addr, port}), _family(addr.family()) {}
explicit IPSrv(IPAddr addr, in_port_t port = 0);
- explicit IPSrv(sockaddr const * sa);
- explicit IPSrv(sockaddr_in const * s);
- explicit IPSrv(sockaddr_in6 const * s);
- explicit IPSrv(IPEndpoint const& ep);
+ explicit IPSrv(sockaddr const *sa);
+ explicit IPSrv(sockaddr_in const *s);
+ explicit IPSrv(sockaddr_in6 const *s);
+ explicit IPSrv(IPEndpoint const &ep);
/** Construct from a string.
*
@@ -265,23 +265,29 @@ public:
bool is_ip6() const;
/// @return The IPv4 data.
- IP4Srv const& ip4() const { return _srv._ip4; }
+ IP4Srv const &
+ ip4() const {
+ return _srv._ip4;
+ }
/// @return The IPv6 data.
- IP6Srv const& ip6() const { return _srv._ip6; }
+ IP6Srv const &
+ ip6() const {
+ return _srv._ip6;
+ }
/** Change the address.
*
* @param addr Address to assign.
* @return @a this
*/
- self_type & assign(IP4Addr const& addr);
+ self_type &assign(IP4Addr const &addr);
/** Change the address.
*
* @param addr Address to assign.
* @return @a this
*/
- self_type & assign(IP6Addr const& addr);
+ self_type &assign(IP6Addr const &addr);
/** Change the address.
*
@@ -290,14 +296,14 @@ public:
*
* If @a addr isn't valid then no assignment is made.
*/
- self_type & assign(IPAddr const& addr);
+ self_type &assign(IPAddr const &addr);
/** Change the host_order_port.
*
* @param port Port in host order.
* @return @a this.
*/
- self_type & assign(in_port_t port);
+ self_type &assign(in_port_t port);
/** Change the address and port.
*
@@ -305,7 +311,7 @@ public:
* @param port Port to assign.
* @return @a this
*/
- self_type & assign(IP4Addr const& addr, in_port_t port);
+ self_type &assign(IP4Addr const &addr, in_port_t port);
/** Change the address and port.
*
@@ -313,28 +319,28 @@ public:
* @param port Port to assign.
* @return @a this
*/
- self_type & assign(IP6Addr const& addr, in_port_t port);
+ self_type &assign(IP6Addr const &addr, in_port_t port);
/** Change the address and port.
*
* @param sa Socket address.
* @return @a this
*/
- self_type & assign(sockaddr const * sa);
+ self_type &assign(sockaddr const *sa);
/** Change the address and port.
*
* @param s Socket address.
* @return @a this
*/
- self_type & assign(sockaddr_in const * s);
+ self_type &assign(sockaddr_in const *s);
/** Change the address and port.
*
* @param s Socket address.
* @return @a this
*/
- self_type & assign(sockaddr_in6 const * s);
+ self_type &assign(sockaddr_in6 const *s);
/** Change the address and host_order_port.
*
@@ -344,30 +350,39 @@ public:
*
* If @a addr isn't valid then no assignment is made.
*/
- self_type & assign(IPAddr const& addr, in_port_t port);
-
- self_type & operator = (self_type const& that) = default;
- self_type & operator = (IP4Srv const& that);
- self_type & operator = (IP6Srv const& that);
- self_type & operator = (sockaddr const * sa) { return this->assign(sa); }
- self_type & operator = (sockaddr_in const * s) { return this->assign(s); }
- self_type & operator = (sockaddr_in6 const * s) { return this->assign(s); }
+ self_type &assign(IPAddr const &addr, in_port_t port);
+
+ self_type &operator=(self_type const &that) = default;
+ self_type &operator=(IP4Srv const &that);
+ self_type &operator=(IP6Srv const &that);
+ self_type &
+ operator=(sockaddr const *sa) {
+ return this->assign(sa);
+ }
+ self_type &
+ operator=(sockaddr_in const *s) {
+ return this->assign(s);
+ }
+ self_type &
+ operator=(sockaddr_in6 const *s) {
+ return this->assign(s);
+ }
protected:
/// Family specialized data.
union data {
- IP4Srv _ip4; ///< IPv4 address (host)
- IP6Srv _ip6; ///< IPv6 address (host)
+ IP4Srv _ip4; ///< IPv4 address (host)
+ IP6Srv _ip6; ///< IPv6 address (host)
- data() {}; // enable default construction.
+ data(){}; // enable default construction.
/// Construct from IPv4 data.
explicit data(IP4Srv const &srv) : _ip4(srv) {}
- explicit data(sockaddr_in const * s) : _ip4(s) {}
+ explicit data(sockaddr_in const *s) : _ip4(s) {}
/// Construct from IPv6 data.
explicit data(IP6Srv const &srv) : _ip6(srv) {}
- explicit data(sockaddr_in6 const * s) : _ip6(s) {}
+ explicit data(sockaddr_in6 const *s) : _ip6(s) {}
/// @return A generic address.
IPAddr addr(sa_family_t f) const;
@@ -377,7 +392,6 @@ protected:
} _srv;
sa_family_t _family = AF_UNSPEC; ///< Protocol family.
-
};
// --- Implementation
@@ -385,22 +399,72 @@ protected:
inline IP4Srv::IP4Srv(IP4Addr addr, in_port_t port) : _addr(addr), _port(port) {}
inline IP4Srv::IP4Srv(IPSrv const &that) : IP4Srv(that.is_ip4() ? that.ip4() : self_type{}) {}
-inline auto IP4Srv::assign(IP4Addr const &addr) -> self_type & { _addr = addr; return *this; }
-inline auto IP4Srv::assign(in_port_t port) -> self_type & { _port = port; return *this; }
-inline auto IP4Srv::assign(IP4Addr const &addr, in_port_t port) -> self_type & { _addr = addr; _port = port; return *this;}
-inline auto IP4Srv::assign(sockaddr_in const * s) -> self_type & { _addr = s; _port = ntohs(s->sin_port); return *this; }
-inline constexpr IP4Srv::operator IP4Addr const &() const { return _addr; }
-inline constexpr IP4Addr const & IP4Srv::addr() const { return _addr; }
-inline in_port_t IP4Srv::host_order_port() const { return _port; }
-inline in_port_t IP4Srv::network_order_port() const { return htons(_port); }
-inline constexpr sa_family_t IP4Srv::family() { return AF_INET; }
-
-inline bool IP4Srv::operator==(IP4Srv::self_type that) const { return _addr == that._addr && _port == that._port; }
-inline bool IP4Srv::operator!=(IP4Srv::self_type that) const { return _addr != that._addr || _port != that._port; }
-inline bool IP4Srv::operator< (IP4Srv::self_type that) const { return _addr < that._addr || (_addr == that._addr && _port < that._port); }
-inline bool IP4Srv::operator<=(IP4Srv::self_type const &that) const { return _addr < that._addr || (_addr == that._addr && _port <= that._port); }
-inline bool IP4Srv::operator> (IP4Srv::self_type const &that) const { return that < *this; }
-inline bool IP4Srv::operator>=(IP4Srv::self_type const &that) const { return that <= *this; }
+inline auto
+IP4Srv::assign(IP4Addr const &addr) -> self_type & {
+ _addr = addr;
+ return *this;
+}
+inline auto
+IP4Srv::assign(in_port_t port) -> self_type & {
+ _port = port;
+ return *this;
+}
+inline auto
+IP4Srv::assign(IP4Addr const &addr, in_port_t port) -> self_type & {
+ _addr = addr;
+ _port = port;
+ return *this;
+}
+inline auto
+IP4Srv::assign(sockaddr_in const *s) -> self_type & {
+ _addr = s;
+ _port = ntohs(s->sin_port);
+ return *this;
+}
+inline constexpr IP4Srv::operator IP4Addr const &() const {
+ return _addr;
+}
+inline constexpr IP4Addr const &
+IP4Srv::addr() const {
+ return _addr;
+}
+inline in_port_t
+IP4Srv::host_order_port() const {
+ return _port;
+}
+inline in_port_t
+IP4Srv::network_order_port() const {
+ return htons(_port);
+}
+inline constexpr sa_family_t
+IP4Srv::family() {
+ return AF_INET;
+}
+
+inline bool
+IP4Srv::operator==(IP4Srv::self_type that) const {
+ return _addr == that._addr && _port == that._port;
+}
+inline bool
+IP4Srv::operator!=(IP4Srv::self_type that) const {
+ return _addr != that._addr || _port != that._port;
+}
+inline bool
+IP4Srv::operator<(IP4Srv::self_type that) const {
+ return _addr < that._addr || (_addr == that._addr && _port < that._port);
+}
+inline bool
+IP4Srv::operator<=(IP4Srv::self_type const &that) const {
+ return _addr < that._addr || (_addr == that._addr && _port <= that._port);
+}
+inline bool
+IP4Srv::operator>(IP4Srv::self_type const &that) const {
+ return that < *this;
+}
+inline bool
+IP4Srv::operator>=(IP4Srv::self_type const &that) const {
+ return that <= *this;
+}
/// --- IPv6
@@ -408,24 +472,62 @@ inline IP6Srv::IP6Srv(IP6Addr addr, in_port_t port) : _addr(addr), _port(port) {
inline IP6Srv::IP6Srv(IPSrv const &that) : IP6Srv(that.is_ip6() ? that.ip6() : self_type{}) {}
inline IP6Srv::IP6Srv(const sockaddr_in6 *s) : _addr(s->sin6_addr), _port(ntohs(s->sin6_port)) {}
-inline constexpr IP6Srv::operator IP6Addr const &() const { return _addr; }
-inline constexpr IP6Addr const & IP6Srv::addr() const { return _addr; }
-inline in_port_t IP6Srv::host_order_port() const { return _port; }
-inline in_port_t IP6Srv::network_order_port() const { return htons(_port); }
-inline constexpr sa_family_t IP6Srv::family() { return AF_INET6; }
+inline constexpr IP6Srv::operator IP6Addr const &() const {
+ return _addr;
+}
+inline constexpr IP6Addr const &
+IP6Srv::addr() const {
+ return _addr;
+}
+inline in_port_t
+IP6Srv::host_order_port() const {
+ return _port;
+}
+inline in_port_t
+IP6Srv::network_order_port() const {
+ return htons(_port);
+}
+inline constexpr sa_family_t
+IP6Srv::family() {
+ return AF_INET6;
+}
-inline bool IP6Srv::operator==(IP6Srv::self_type that) const { return _addr == that._addr && _port == that._port; }
-inline bool IP6Srv::operator!=(IP6Srv::self_type that) const { return _port != that._port || _addr != that._addr; }
-inline bool IP6Srv::operator< (IP6Srv::self_type that) const { return _addr < that._addr || (_addr == that._addr && _port < that._port); }
-inline bool IP6Srv::operator<=(IP6Srv::self_type const &that) const { return _addr < that._addr || (_addr == that._addr && _port <= that._port); }
-inline bool IP6Srv::operator> (IP6Srv::self_type const &that) const { return that < *this; }
-inline bool IP6Srv::operator>=(IP6Srv::self_type const &that) const { return that <= *this; }
+inline bool
+IP6Srv::operator==(IP6Srv::self_type that) const {
+ return _addr == that._addr && _port == that._port;
+}
+inline bool
+IP6Srv::operator!=(IP6Srv::self_type that) const {
+ return _port != that._port || _addr != that._addr;
+}
+inline bool
+IP6Srv::operator<(IP6Srv::self_type that) const {
+ return _addr < that._addr || (_addr == that._addr && _port < that._port);
+}
+inline bool
+IP6Srv::operator<=(IP6Srv::self_type const &that) const {
+ return _addr < that._addr || (_addr == that._addr && _port <= that._port);
+}
+inline bool
+IP6Srv::operator>(IP6Srv::self_type const &that) const {
+ return that < *this;
+}
+inline bool
+IP6Srv::operator>=(IP6Srv::self_type const &that) const {
+ return that <= *this;
+}
inline auto
-IP6Srv::assign(in_port_t port) -> self_type & { _port = port; return *this; }
+IP6Srv::assign(in_port_t port) -> self_type & {
+ _port = port;
+ return *this;
+}
inline auto
-IP6Srv::assign(IP6Addr const &addr) -> self_type & { _addr = addr; return *this; }
+IP6Srv::assign(IP6Addr const &addr) -> self_type & {
+ _addr = addr;
+ return *this;
+}
inline auto
IP6Srv::assign(IP6Addr const &addr, in_port_t port) -> self_type & {
@@ -445,12 +547,26 @@ IP6Srv::assign(sockaddr_in6 const *s) -> self_type & {
inline IPSrv::IPSrv(const sockaddr_in *s) : _srv(s), _family(AF_INET) {}
inline IPSrv::IPSrv(const sockaddr_in6 *s) : _srv(s), _family(AF_INET6) {}
-inline IPSrv::IPSrv(const sockaddr *sa) { this->assign(sa); }
+inline IPSrv::IPSrv(const sockaddr *sa) {
+ this->assign(sa);
+}
-inline IPAddr IPSrv::addr() const { return _srv.addr(_family); }
-inline constexpr sa_family_t IPSrv::family() const { return _family; }
-inline bool IPSrv::is_ip4() const { return _family == AF_INET; }
-inline bool IPSrv::is_ip6() const { return _family == AF_INET6; }
+inline IPAddr
+IPSrv::addr() const {
+ return _srv.addr(_family);
+}
+inline constexpr sa_family_t
+IPSrv::family() const {
+ return _family;
+}
+inline bool
+IPSrv::is_ip4() const {
+ return _family == AF_INET;
+}
+inline bool
+IPSrv::is_ip6() const {
+ return _family == AF_INET6;
+}
inline auto
IPSrv::assign(IP6Addr const &addr) -> self_type & {
@@ -482,58 +598,73 @@ IPSrv::assign(IP4Addr const &addr) -> self_type & {
inline auto
IPSrv::assign(in_port_t port) -> self_type & {
- if (this->is_ip4()) { _srv._ip4.assign(port); }
- else if (this->is_ip6()) { _srv._ip6.assign(port); }
+ if (this->is_ip4()) {
+ _srv._ip4.assign(port);
+ } else if (this->is_ip6()) {
+ _srv._ip6.assign(port);
+ }
return *this;
}
inline auto
IPSrv::assign(IPAddr const &addr) -> self_type & {
- if (addr.is_ip4()) { this->assign(addr.ip4()); }
- else if (addr.is_ip6()) { this->assign(addr.ip6());}
+ if (addr.is_ip4()) {
+ this->assign(addr.ip4());
+ } else if (addr.is_ip6()) {
+ this->assign(addr.ip6());
+ }
return *this;
}
inline auto
IPSrv::assign(IPAddr const &addr, in_port_t port) -> self_type & {
- if (addr.is_ip4()) { this->assign(addr.ip4(), port); _family = addr.family(); }
- else if (addr.is_ip6()) { this->assign(addr.ip6(), port); _family = addr.family(); }
+ if (addr.is_ip4()) {
+ this->assign(addr.ip4(), port);
+ _family = addr.family();
+ } else if (addr.is_ip6()) {
+ this->assign(addr.ip6(), port);
+ _family = addr.family();
+ }
return *this;
}
inline auto
IPSrv::operator=(IP4Srv const &that) -> self_type & {
- _family = that.family();
+ _family = that.family();
_srv._ip4 = that;
return *this;
}
inline auto
IPSrv::operator=(IP6Srv const &that) -> self_type & {
- _family = that.family();
+ _family = that.family();
_srv._ip6 = that;
return *this;
}
inline auto
-IPSrv::assign(sockaddr_in const * s) -> self_type & {
+IPSrv::assign(sockaddr_in const *s) -> self_type & {
_family = _srv._ip4.family();
_srv._ip4.assign(s);
return *this;
}
inline auto
-IPSrv::assign(sockaddr_in6 const * s) -> self_type & {
+IPSrv::assign(sockaddr_in6 const *s) -> self_type & {
_family = _srv._ip6.family();
_srv._ip6.assign(s);
return *this;
}
inline constexpr in_port_t
-IPSrv::host_order_port() const { return _srv.port(_family); }
+IPSrv::host_order_port() const {
+ return _srv.port(_family);
+}
inline in_port_t
-IPSrv::network_order_port() const { return ntohs(_srv.port(_family)); }
+IPSrv::network_order_port() const {
+ return ntohs(_srv.port(_family));
+}
inline IPAddr
IPSrv::data::addr(sa_family_t f) const {
@@ -546,135 +677,166 @@ IPSrv::data::port(sa_family_t f) const {
}
// --- Independent comparisons.
-inline bool operator == (IPSrv const& lhs, IP4Srv const& rhs) {
+inline bool
+operator==(IPSrv const &lhs, IP4Srv const &rhs) {
return lhs.is_ip4() && lhs.ip4() == rhs;
}
-inline bool operator == (IP4Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator==(IP4Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip4() && rhs.ip4() == lhs;
}
-inline bool operator != (IPSrv const& lhs, IP4Srv const& rhs) {
- return ! lhs.is_ip4() || lhs.ip4() != rhs;
+inline bool
+operator!=(IPSrv const &lhs, IP4Srv const &rhs) {
+ return !lhs.is_ip4() || lhs.ip4() != rhs;
}
-inline bool operator != (IP4Srv const& lhs, IPSrv const& rhs) {
- return ! rhs.is_ip4() || rhs.ip4() != lhs;
+inline bool
+operator!=(IP4Srv const &lhs, IPSrv const &rhs) {
+ return !rhs.is_ip4() || rhs.ip4() != lhs;
}
-inline bool operator < (IPSrv const& lhs, IP4Srv const& rhs) {
+inline bool
+operator<(IPSrv const &lhs, IP4Srv const &rhs) {
return lhs.is_ip4() && lhs.ip4() < rhs;
}
-inline bool operator < (IP4Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator<(IP4Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip4() && lhs < rhs.ip4();
}
-inline bool operator <= (IPSrv const& lhs, IP4Srv const& rhs) {
+inline bool
+operator<=(IPSrv const &lhs, IP4Srv const &rhs) {
return lhs.is_ip4() && lhs.ip4() <= rhs;
}
-inline bool operator <= (IP4Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator<=(IP4Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip4() && lhs <= rhs.ip4();
}
-inline bool operator > (IPSrv const& lhs, IP4Srv const& rhs) {
+inline bool
+operator>(IPSrv const &lhs, IP4Srv const &rhs) {
return lhs.is_ip4() && lhs.ip4() > rhs;
}
-inline bool operator > (IP4Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator>(IP4Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip4() && lhs > rhs.ip4();
}
-inline bool operator >= (IPSrv const& lhs, IP4Srv const& rhs) {
+inline bool
+operator>=(IPSrv const &lhs, IP4Srv const &rhs) {
return lhs.is_ip4() && lhs.ip4() >= rhs;
}
-inline bool operator >= (IP4Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator>=(IP4Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip4() && lhs >= rhs.ip4();
}
-
-inline bool operator == (IPSrv const& lhs, IP6Srv const& rhs) {
+inline bool
+operator==(IPSrv const &lhs, IP6Srv const &rhs) {
return lhs.is_ip6() && lhs.ip6() == rhs;
}
-inline bool operator == (IP6Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator==(IP6Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip6() && rhs.ip6() == lhs;
}
-inline bool operator != (IPSrv const& lhs, IP6Srv const& rhs) {
- return ! lhs.is_ip6() || lhs.ip6() != rhs;
+inline bool
+operator!=(IPSrv const &lhs, IP6Srv const &rhs) {
+ return !lhs.is_ip6() || lhs.ip6() != rhs;
}
-inline bool operator != (IP6Srv const& lhs, IPSrv const& rhs) {
- return ! rhs.is_ip6() || rhs.ip6() != lhs;
+inline bool
+operator!=(IP6Srv const &lhs, IPSrv const &rhs) {
+ return !rhs.is_ip6() || rhs.ip6() != lhs;
}
-inline bool operator < (IPSrv const& lhs, IP6Srv const& rhs) {
+inline bool
+operator<(IPSrv const &lhs, IP6Srv const &rhs) {
return lhs.is_ip6() && lhs.ip6() < rhs;
}
-inline bool operator < (IP6Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator<(IP6Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip6() && lhs < rhs.ip6();
}
-inline bool operator <= (IPSrv const& lhs, IP6Srv const& rhs) {
+inline bool
+operator<=(IPSrv const &lhs, IP6Srv const &rhs) {
return lhs.is_ip6() && lhs.ip6() <= rhs;
}
-inline bool operator <= (IP6Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator<=(IP6Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip6() && lhs <= rhs.ip6();
}
-inline bool operator > (IPSrv const& lhs, IP6Srv const& rhs) {
+inline bool
+operator>(IPSrv const &lhs, IP6Srv const &rhs) {
return lhs.is_ip6() && lhs.ip6() > rhs;
}
-inline bool operator > (IP6Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator>(IP6Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip6() && lhs > rhs.ip6();
}
-inline bool operator >= (IPSrv const& lhs, IP6Srv const& rhs) {
+inline bool
+operator>=(IPSrv const &lhs, IP6Srv const &rhs) {
return lhs.is_ip6() && lhs.ip6() >= rhs;
}
-inline bool operator >= (IP6Srv const& lhs, IPSrv const& rhs) {
+inline bool
+operator>=(IP6Srv const &lhs, IPSrv const &rhs) {
return rhs.is_ip6() && lhs >= rhs.ip6();
}
// --- Cross address equality
-inline bool operator == (IPSrv const& lhs, IP4Addr const& rhs) {
+inline bool
+operator==(IPSrv const &lhs, IP4Addr const &rhs) {
return lhs.is_ip4() && lhs.ip4() == rhs;
}
-inline bool operator == (IP4Addr const& lhs, IPSrv const& rhs) {
+inline bool
+operator==(IP4Addr const &lhs, IPSrv const &rhs) {
return rhs.is_ip4() && lhs == rhs.ip4();
}
-inline bool operator != (IPSrv const& lhs, IP4Addr const& rhs) {
- return ! lhs.is_ip4() || lhs.ip4() != rhs;
+inline bool
+operator!=(IPSrv const &lhs, IP4Addr const &rhs) {
+ return !lhs.is_ip4() || lhs.ip4() != rhs;
}
-inline bool operator != (IP4Addr const& lhs, IPSrv const& rhs) {
- return ! rhs.is_ip4() || lhs != rhs.ip4();
+inline bool
+operator!=(IP4Addr const &lhs, IPSrv const &rhs) {
+ return !rhs.is_ip4() || lhs != rhs.ip4();
}
-inline bool operator == (IPSrv const& lhs, IP6Addr const& rhs) {
+inline bool
+operator==(IPSrv const &lhs, IP6Addr const &rhs) {
return lhs.is_ip6() && lhs.ip6() == rhs;
}
-inline bool operator == (IP6Addr const& lhs, IPSrv const& rhs) {
+inline bool
+operator==(IP6Addr const &lhs, IPSrv const &rhs) {
return rhs.is_ip6() && lhs == rhs.ip6();
}
-inline bool operator != (IPSrv const& lhs, IP6Addr const& rhs) {
- return ! lhs.is_ip6() || lhs.ip6() != rhs;
+inline bool
+operator!=(IPSrv const &lhs, IP6Addr const &rhs) {
+ return !lhs.is_ip6() || lhs.ip6() != rhs;
}
-inline bool operator != (IP6Addr const& lhs, IPSrv const& rhs) {
- return ! rhs.is_ip6() || lhs != rhs.ip6();
+inline bool
+operator!=(IP6Addr const &lhs, IPSrv const &rhs) {
+ return !rhs.is_ip6() || lhs != rhs.ip6();
}
}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/include/swoc/IntrusiveDList.h b/code/include/swoc/IntrusiveDList.h
index 5e48884..2b5b0a2 100644
--- a/code/include/swoc/IntrusiveDList.h
+++ b/code/include/swoc/IntrusiveDList.h
@@ -346,7 +346,7 @@ public:
*
* The elements are removed from @a src, which becomes empty.
*/
- self_type & append(self_type & src);
+ self_type &append(self_type &src);
/** Prepend a list.
*
@@ -355,7 +355,7 @@ public:
*
* The elements are removed from @a src, which becomes empty.
*/
- self_type & prepend(self_type & src);
+ self_type &prepend(self_type &src);
/** Splice in a list after an existing element.
*
@@ -363,7 +363,7 @@ public:
* @param src List to splice.
* @return @a this
*/
- self_type &insert_after(value_type *target, self_type & src);
+ self_type &insert_after(value_type *target, self_type &src);
/** Splice in a list before an existing element.
*
@@ -371,7 +371,7 @@ public:
* @param src List to splice.
* @return @a this
*/
- self_type &insert_before(value_type *target, self_type & src);
+ self_type &insert_before(value_type *target, self_type &src);
/** Splice in a list after an existing element.
*
@@ -379,7 +379,7 @@ public:
* @param src List to splice.
* @return @a this
*/
- self_type &insert_after(iterator const &target, self_type & src);
+ self_type &insert_after(iterator const &target, self_type &src);
/** Splice in a list before an existing element.
*
@@ -387,7 +387,7 @@ public:
* @param src List to splice.
* @return @a this
*/
- self_type &insert_before(iterator const &target, self_type & src);
+ self_type &insert_before(iterator const &target, self_type &src);
/// Remove all elements.
/// @note @b No memory management is done!
@@ -552,12 +552,12 @@ IntrusiveLinkageRebind<T, L>::prev_ptr(T *thing) {
return ptr_ref_cast<T>(L::prev_ptr(thing));
}
-template < typename T > struct IntrusiveLinks {
- T * _next = nullptr;
- T * _prev = nullptr;
+template <typename T> struct IntrusiveLinks {
+ T *_next = nullptr;
+ T *_prev = nullptr;
};
-template < typename T, IntrusiveLinks<T> (T::* links) > struct IntrusiveLinkDescriptor {
+template <typename T, IntrusiveLinks<T>(T::*links)> struct IntrusiveLinkDescriptor {
static T *&next_ptr(T *thing); ///< Retrieve reference to next pointer.
static T *&prev_ptr(T *thing); ///< Retrive reference to previous pointer.
};
@@ -841,16 +841,16 @@ IntrusiveDList<L>::insert_before(iterator const &target, value_type *v) -> self_
template <typename L>
auto
-IntrusiveDList<L>::insert_after(value_type *target, self_type & src) -> self_type & {
+IntrusiveDList<L>::insert_after(value_type *target, self_type &src) -> self_type & {
if (target && src._count > 0) {
if (_tail == target) {
this->append(src);
- } else { // invariant - @a target is not tail therefore has a successor.
- L::next_ptr(src._tail) = L::next_ptr(target); // link @a src tail to @a target successor
+ } else { // invariant - @a target is not tail therefore has a successor.
+ L::next_ptr(src._tail) = L::next_ptr(target); // link @a src tail to @a target successor
L::prev_ptr(L::next_ptr(src._tail)) = src._tail;
L::prev_ptr(src._head) = target; // link @a src head to @target
- L::next_ptr(target) = src._head;
+ L::next_ptr(target) = src._head;
_count += src._count;
src.clear();
@@ -861,22 +861,22 @@ IntrusiveDList<L>::insert_after(value_type *target, self_type & src) -> self_typ
template <typename L>
auto
-IntrusiveDList<L>::insert_after(iterator const &target, self_type & src) -> self_type & {
+IntrusiveDList<L>::insert_after(iterator const &target, self_type &src) -> self_type & {
return this->insert_after(target._v, src);
}
template <typename L>
auto
-IntrusiveDList<L>::insert_before(value_type *target, self_type & src) -> self_type & {
+IntrusiveDList<L>::insert_before(value_type *target, self_type &src) -> self_type & {
if (target && src._count > 0) {
if (_head == target) {
this->prepend(src);
- } else { // invariant - @a target is not head and therefore has a predecessor.
- L::prev_ptr(src._head) = L::prev_ptr(target); // link @a src head to @a target predecessor
+ } else { // invariant - @a target is not head and therefore has a predecessor.
+ L::prev_ptr(src._head) = L::prev_ptr(target); // link @a src head to @a target predecessor
L::next_ptr(L::prev_ptr(target)) = src._head;
L::next_ptr(src._tail) = target; // link @a src tail to @a target
- L::prev_ptr(target) = src._tail;
+ L::prev_ptr(target) = src._tail;
_count += src._count;
src.clear();
@@ -887,7 +887,7 @@ IntrusiveDList<L>::insert_before(value_type *target, self_type & src) -> self_ty
template <typename L>
auto
-IntrusiveDList<L>::insert_before(iterator const &target, self_type & src) -> self_type & {
+IntrusiveDList<L>::insert_before(iterator const &target, self_type &src) -> self_type & {
return this->insert_before(target._v, src);
}
@@ -1041,14 +1041,18 @@ IntrusiveDList<L>::nth(unsigned int n) -> iterator {
return {};
}
- value_type * spot;
- if (n < _count/2) { // closer to head, count from there..
+ value_type *spot;
+ if (n < _count / 2) { // closer to head, count from there..
spot = _head;
- while (n-- > 0) { spot = L::next_ptr(spot); }
+ while (n-- > 0) {
+ spot = L::next_ptr(spot);
+ }
} else { // count from tail
- spot = _tail;
+ spot = _tail;
unsigned idx = _count - 1;
- while (idx-- > n) { spot = L::prev_ptr(spot); }
+ while (idx-- > n) {
+ spot = L::prev_ptr(spot);
+ }
}
return iterator_for(spot);
}
@@ -1056,7 +1060,6 @@ IntrusiveDList<L>::nth(unsigned int n) -> iterator {
template <typename L>
auto
IntrusiveDList<L>::take_prefix(unsigned int n) -> self_type {
-
if (n == 0) {
return {};
}
@@ -1068,16 +1071,16 @@ IntrusiveDList<L>::take_prefix(unsigned int n) -> self_type {
// Invariant - there is at least one element that will not be taken.
self_type zret;
- value_type * spot = this->nth(n); // new @a head for @a this
+ value_type *spot = this->nth(n); // new @a head for @a this
- zret._count = n;
- zret._head = _head;
- zret._tail = L::prev_ptr(spot);
+ zret._count = n;
+ zret._head = _head;
+ zret._tail = L::prev_ptr(spot);
L::next_ptr(zret._tail) = nullptr;
- _count -= n;
- _head = spot;
- L::prev_ptr(_head) = nullptr;
+ _count -= n;
+ _head = spot;
+ L::prev_ptr(_head) = nullptr;
return zret;
}
@@ -1094,7 +1097,6 @@ IntrusiveDList<L>::split_prefix(unsigned int n) -> self_type {
template <typename L>
auto
IntrusiveDList<L>::take_suffix(unsigned int n) -> self_type {
-
if (n == 0) {
return {};
}
@@ -1106,16 +1108,16 @@ IntrusiveDList<L>::take_suffix(unsigned int n) -> self_type {
// Invariant - there is at least one element that will not be taken.
self_type zret;
- value_type * spot = this->nth(_count - n - 1); // new @a tail for @a this
+ value_type *spot = this->nth(_count - n - 1); // new @a tail for @a this
- zret._count = n;
- zret._head = L::next_ptr(spot);
+ zret._count = n;
+ zret._head = L::next_ptr(spot);
L::prev_ptr(zret._head) = nullptr;
- zret._tail = _tail;
+ zret._tail = _tail;
- _count -= n;
- _tail = spot;
- L::next_ptr(_tail) = nullptr;
+ _count -= n;
+ _tail = spot;
+ L::next_ptr(_tail) = nullptr;
return zret;
}
@@ -1136,10 +1138,10 @@ IntrusiveDList<L>::prepend(IntrusiveDList::self_type &src) -> self_type & {
if (_count == 0) {
*this = std::move(src);
} else {
- L::prev_ptr(_head) = src._tail;
- L::next_ptr(src._tail) = _head;
- _count += src._count;
- _head = src._head;
+ L::prev_ptr(_head) = src._tail;
+ L::next_ptr(src._tail) = _head;
+ _count += src._count;
+ _head = src._head;
src.clear();
}
}
@@ -1153,10 +1155,10 @@ IntrusiveDList<L>::append(IntrusiveDList::self_type &src) -> self_type & {
if (_count == 0) {
*this = std::move(src);
} else {
- L::next_ptr(_tail) = src._head;
- L::prev_ptr(src._head) = _tail;
- _count += src._count;
- _tail = src._tail;
+ L::next_ptr(_tail) = src._head;
+ L::prev_ptr(src._head) = _tail;
+ _count += src._count;
+ _tail = src._tail;
src.clear();
}
}
diff --git a/code/include/swoc/IntrusiveHashMap.h b/code/include/swoc/IntrusiveHashMap.h
index dce1bca..4bbe3b6 100644
--- a/code/include/swoc/IntrusiveHashMap.h
+++ b/code/include/swoc/IntrusiveHashMap.h
@@ -305,10 +305,11 @@ protected:
IntrusiveHashMap &operator=(const IntrusiveHashMap &) = delete;
// Hash table size prime list.
- static constexpr std::array<size_t, 29> PRIME = {{1, 3, 7, 13, 31, 61, 127, 251,
- 509, 1021, 2039, 4093, 8191, 16381, 32749, 65521,
- 131071, 262139, 524287, 1048573, 2097143, 4194301, 8388593, 16777213,
- 33554393, 67108859, 134217689, 268435399, 536870909}};
+ static constexpr std::array<size_t, 29> PRIME = {
+ {1, 3, 7, 13, 31, 61, 127, 251, 509, 1021,
+ 2039, 4093, 8191, 16381, 32749, 65521, 131071, 262139, 524287, 1048573,
+ 2097143, 4194301, 8388593, 16777213, 33554393, 67108859, 134217689, 268435399, 536870909}
+ };
};
template <typename H>
diff --git a/code/include/swoc/Lexicon.h b/code/include/swoc/Lexicon.h
index 166cb6f..c574bc7 100644
--- a/code/include/swoc/Lexicon.h
+++ b/code/include/swoc/Lexicon.h
@@ -41,7 +41,7 @@ what(std::string_view const &fmt, Args &&...args) {
// Exported because inner classes in template classes cannot be used in partial specialization
// which is required for tuple support. This should be removed next time there is a API changing
// release because tuple access is being deprecated.
-template < typename E > struct lexicon_pair_type {
+template <typename E> struct lexicon_pair_type {
E _value;
TextView _name;
@@ -844,7 +844,7 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, Lexicon<E> const &lex) {
return w;
}
-}} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
namespace std {
@@ -873,4 +873,3 @@ get(swoc::detail::lexicon_pair_type<E> const &p) -> typename std::tuple_element<
}
} // namespace std
-
diff --git a/code/include/swoc/MemArena.h b/code/include/swoc/MemArena.h
index 6c1bc0f..b699e60 100644
--- a/code/include/swoc/MemArena.h
+++ b/code/include/swoc/MemArena.h
@@ -207,10 +207,10 @@ public:
~MemArena();
/// No copy assignment.
- self_type & operator=(self_type const & that) = delete;
+ self_type &operator=(self_type const &that) = delete;
/// Move assignment.
- self_type & operator=(self_type &&that) noexcept;
+ self_type &operator=(self_type &&that) noexcept;
/** Make a self-contained instance.
*
@@ -279,7 +279,7 @@ public:
general it is a bad idea to make objects in the Arena that own memory that is not also in the
Arena.
*/
- template <typename T, typename... Args> T *make(Args &&... args);
+ template <typename T, typename... Args> T *make(Args &&...args);
/** Freeze reserved memory.
@@ -384,7 +384,7 @@ public:
size_t reserved_size() const;
using const_iterator = BlockList::const_iterator; ///< Constant element iteration.
- using iterator = const_iterator; ///< Element iteration.
+ using iterator = const_iterator; ///< Element iteration.
/// First active block.
const_iterator begin() const;
@@ -397,6 +397,7 @@ public:
/// After last frozen block.
const_iterator frozen_end() const;
+
protected:
/** Internally allocates a new block of memory of size @a n bytes.
*
@@ -502,7 +503,7 @@ public:
void clear();
/// Access the wrapped arena directly.
- MemArena & arena();
+ MemArena &arena();
};
// --- Implementation ---
@@ -581,7 +582,7 @@ MemArena::Block::operator delete([[maybe_unused]] void *ptr, void *place) noexce
inline size_t
MemArena::Block::align_padding(void const *ptr, size_t align) {
- if (auto delta = uintptr_t(ptr) & (align - 1) ; delta > 0) {
+ if (auto delta = uintptr_t(ptr) & (align - 1); delta > 0) {
return align - delta;
}
return 0;
@@ -597,7 +598,7 @@ MemArena::alloc_span(size_t n) {
template <typename T, typename... Args>
T *
-MemArena::make(Args &&... args) {
+MemArena::make(Args &&...args) {
return new (this->alloc(sizeof(T), alignof(T)).data()) T(std::forward<Args>(args)...);
}
@@ -610,10 +611,14 @@ MemArena::remnant_span(size_t n) {
template <>
inline MemSpan<void>
-MemArena::remnant_span<void>(size_t n) { return this->require(n).remnant().prefix(n); }
+MemArena::remnant_span<void>(size_t n) {
+ return this->require(n).remnant().prefix(n);
+}
inline MemSpan<void>
-MemArena::remnant(size_t n, size_t align) { return this->require(n, align).remnant().prefix(n); }
+MemArena::remnant(size_t n, size_t align) {
+ return this->require(n, align).remnant().prefix(n);
+}
inline size_t
MemArena::size() const {
@@ -693,7 +698,11 @@ FixedArena<T>::clear() {
_list._next = nullptr;
}
-template < typename T > MemArena & FixedArena<T>::arena() { return _arena; }
+template <typename T>
+MemArena &
+FixedArena<T>::arena() {
+ return _arena;
+}
/// @endcond INTERNAL_DETAIL
diff --git a/code/include/swoc/MemSpan.h b/code/include/swoc/MemSpan.h
index 53d7a3f..02c170c 100644
--- a/code/include/swoc/MemSpan.h
+++ b/code/include/swoc/MemSpan.h
@@ -55,8 +55,8 @@ protected:
size_t _count = 0; ///< Number of elements.
public:
- using value_type = T; ///< Element type for span.
- using iterator = T *; ///< Iterator.
+ using value_type = T; ///< Element type for span.
+ using iterator = T *; ///< Iterator.
using const_iterator = T const *; ///< Constant iterator.
/// Default constructor (empty buffer).
@@ -65,7 +65,7 @@ public:
/// Copy constructor.
constexpr MemSpan(self_type const &that) = default;
/// Copy constructor.
- constexpr MemSpan(self_type & that) = default;
+ constexpr MemSpan(self_type &that) = default;
/** Construct from a first element @a start and a @a count of elements.
*
@@ -95,21 +95,17 @@ public:
*
* @note Because the elements in a constant array are constant the span value type must be constant.
*/
- template < auto N, typename U
- , typename META = std::enable_if_t<
- std::conjunction_v<
- std::is_const<T>
- , std::is_same<std::remove_const_t<U>, std::remove_const_t<T>>
- >
- >
- > constexpr MemSpan(std::array<U, N> const& a);
+ template <auto N, typename U,
+ typename META =
+ std::enable_if_t<std::conjunction_v<std::is_const<T>, std::is_same<std::remove_const_t<U>, std::remove_const_t<T>>>>>
+ constexpr MemSpan(std::array<U, N> const &a);
/** Construct from a @c std::array.
*
* @tparam N Array size.
* @param a Array instance.
*/
- template <auto N> constexpr MemSpan(std::array<T, N> & a);
+ template <auto N> constexpr MemSpan(std::array<T, N> &a);
/** Construct a span of constant values from a span of non-constant.
*
@@ -119,14 +115,9 @@ public:
*
* This enables the standard conversion from non-const to const.
*/
- template < typename U
- , typename META = std::enable_if_t<
- std::conjunction_v<
- std::is_const<T>
- , std::is_same<U, std::remove_const_t<T>>
- >>>
- constexpr MemSpan(MemSpan<U> const& that) : _ptr(that.data()), _count(that.count()) {}
-
+ template <typename U,
+ typename META = std::enable_if_t<std::conjunction_v<std::is_const<T>, std::is_same<U, std::remove_const_t<T>>>>>
+ constexpr MemSpan(MemSpan<U> const &that) : _ptr(that.data()), _count(that.count()) {}
/** Construct from any vector like container.
*
@@ -141,13 +132,10 @@ public:
* constructing from @c std::string. Without this variant it's not possible to construct a @c char
* span vs. a @c char @c const.
*/
- template < typename C
- , typename = std::enable_if_t<
- std::is_convertible_v<decltype(std::declval<C>().data()), T *> &&
- std::is_convertible_v<decltype(std::declval<C>().size()), size_t>
- , void
- >
- > constexpr MemSpan(C & c);
+ template <typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), T *> &&
+ std::is_convertible_v<decltype(std::declval<C>().size()), size_t>,
+ void>>
+ constexpr MemSpan(C &c);
/** Construct from any vector like container.
*
@@ -160,13 +148,10 @@ public:
* @note Because the container is passed as a constant reference, this may cause the span type to
* also be a constant element type.
*/
- template < typename C
- , typename = std::enable_if_t<
- std::is_convertible_v<decltype(std::declval<C>().data()), T *> &&
- std::is_convertible_v<decltype(std::declval<C>().size()), size_t>
- , void
- >
- > constexpr MemSpan(C const & c);
+ template <typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), T *> &&
+ std::is_convertible_v<decltype(std::declval<C>().size()), size_t>,
+ void>>
+ constexpr MemSpan(C const &c);
/** Construct from nullptr.
This implicitly makes the length 0.
@@ -235,7 +220,7 @@ public:
constexpr size_t data_size() const;
/// @return Pointer to memory in the span.
- T * data() const;
+ T *data() const;
/// @return Pointer to immediate after memory in the span.
constexpr T *data_end() const;
@@ -268,7 +253,7 @@ public:
* if no type is specified, the default is @c void or @c void @c const according to whether
* @a value_type is @c const.
*/
- template <typename U = std::conditional_t<std::is_const_v<T>, void const, void> > MemSpan<U> rebind() const;
+ template <typename U = std::conditional_t<std::is_const_v<T>, void const, void>> MemSpan<U> rebind() const;
/// Set the span.
/// This is faster but equivalent to constructing a new span with the same
@@ -379,7 +364,7 @@ public:
* For each element in the span, construct an instance of the span type using the @a args. If the
* instances need destruction this must be done explicitly.
*/
- template <typename... Args> self_type & make(Args &&... args);
+ template <typename... Args> self_type &make(Args &&...args);
/// Destruct all elements in the span.
void destroy();
@@ -407,8 +392,8 @@ public:
using value_type = void const; /// Export base type.
protected:
- void *_ptr = nullptr; ///< Pointer to base of memory chunk.
- size_t _size = 0; ///< Number of bytes in the chunk.
+ void *_ptr = nullptr; ///< Pointer to base of memory chunk.
+ size_t _size = 0; ///< Number of bytes in the chunk.
public:
/// Default constructor (empty buffer).
@@ -418,7 +403,7 @@ public:
constexpr MemSpan(self_type const &that) = default;
/// Copy assignment
- constexpr self_type & operator = (self_type const& that) = default;
+ constexpr self_type &operator=(self_type const &that) = default;
/** Construct to cover an array.
*
@@ -428,7 +413,7 @@ public:
template <auto N, typename U> constexpr MemSpan(U (&a)[N]);
/// Special constructor for @c void
- constexpr MemSpan(MemSpan<void> const& that);
+ constexpr MemSpan(MemSpan<void> const &that);
/** Cross type copy constructor.
*
@@ -462,12 +447,8 @@ public:
* The container type must have the methods @c data and @c size which must return values convertible
* to @c void* and @c size_t respectively.
*/
- template < typename C
- , typename = std::enable_if_t<
- std::is_convertible_v<decltype(std::declval<C>().size()), size_t>
- , void
- >
- > constexpr MemSpan(C const& c);
+ template <typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().size()), size_t>, void>>
+ constexpr MemSpan(C const &c);
/** Construct from nullptr.
This implicitly makes the length 0.
@@ -566,7 +547,7 @@ public:
*
* @note This throws if the size is not a match for @a U.
*/
- template <typename U> U const * as_ptr() const;
+ template <typename U> U const *as_ptr() const;
/// Clear the span (become an empty span).
self_type &clear();
@@ -664,15 +645,15 @@ public:
* @note @a obj_size should be a multiple of @a alignment. This happens naturally if @c sizeof is used.
*/
self_type align(size_t alignment, size_t obj_size) const;
-
};
template <> class MemSpan<void> : public MemSpan<void const> {
- using self_type = MemSpan;
+ using self_type = MemSpan;
using super_type = MemSpan<void const>;
template <typename U> friend class MemSpan;
+
public:
- using value_type = void;
+ using value_type = void;
using pointer_type = value_type *;
/// Default constructor (empty buffer).
@@ -682,7 +663,7 @@ public:
constexpr MemSpan(self_type const &that) = default;
/// Copy assignment
- constexpr self_type & operator = (self_type const& that) = default;
+ constexpr self_type &operator=(self_type const &that) = default;
/** Cross type copy constructor.
*
@@ -739,13 +720,10 @@ public:
* The container type must have the methods @c data and @c size which must return values convertible
* to @c void* and @c size_t respectively.
*/
- template < typename C
- , typename = std::enable_if_t<
- ! std::is_const_v<decltype(std::declval<C>().data()[0])> &&
- std::is_convertible_v<decltype(std::declval<C>().size()), size_t>
- , void
- >
- > constexpr MemSpan(C const& c);
+ template <typename C, typename = std::enable_if_t<!std::is_const_v<decltype(std::declval<C>().data()[0])> &&
+ std::is_convertible_v<decltype(std::declval<C>().size()), size_t>,
+ void>>
+ constexpr MemSpan(C const &c);
/** Update the span.
*
@@ -763,7 +741,7 @@ public:
*/
self_type &assign(value_type *first, value_type const *last);
- /// @return An instance that contains the leading @a n bytes of @a this.
+ /// @return An instance that contains the leading @a n bytes of @a this.
self_type prefix(size_t n) const;
/** Shrink the span by removing @a n leading bytes.
@@ -782,7 +760,6 @@ public:
*/
self_type clip_prefix(size_t n);
-
/** Get the trailing segment of @a n bytes.
*
* @param n Number of bytes to retrieve.
@@ -866,7 +843,7 @@ public:
*
* @note This throws if the size is not a match for @a U.
*/
- template <typename U> U * as_ptr() const;
+ template <typename U> U *as_ptr() const;
/// Clear the span (become an empty span).
self_type &clear();
@@ -881,10 +858,9 @@ protected:
* method implementations to return a @c const span as @c self_type without explicit casting.
* In such cases the original span was not @c const and so there is no violation.
*/
- MemSpan(super_type const& super) : super_type(super) {}
+ MemSpan(super_type const &super) : super_type(super) {}
};
-
// -- Implementation --
namespace detail {
@@ -906,7 +882,7 @@ ptr_add(void *ptr, size_t count) {
}
inline void const *
-ptr_add(void const * ptr, size_t count) {
+ptr_add(void const *ptr, size_t count) {
return static_cast<char const *>(ptr) + count;
}
@@ -926,9 +902,8 @@ ptr_add(void const * ptr, size_t count) {
*/
template <typename T, typename U> struct is_span_compatible {
/// @c true if the size of @a T is an integral multiple of the size of @a U or vice versa.
- static constexpr bool value =
- (std::ratio<sizeof(T), sizeof(U)>::num == 1 || std::ratio<sizeof(U), sizeof(T)>::num == 1) &&
- (std::is_const_v<U> || ! std::is_const_v<T>); // can't lose constancy.
+ static constexpr bool value = (std::ratio<sizeof(T), sizeof(U)>::num == 1 || std::ratio<sizeof(U), sizeof(T)>::num == 1) &&
+ (std::is_const_v<U> || !std::is_const_v<T>); // can't lose constancy.
/** Compute the new size in units of @c sizeof(U).
*
* @param size Size in bytes.
@@ -953,7 +928,7 @@ is_span_compatible<T, U>::count(size_t size) {
// Must specialize for rebinding to @c void because @c sizeof doesn't work. Rebinding from @c void
// is handled by the @c MemSpan<void>::rebind specialization and doesn't use this mechanism.
template <typename T> struct is_span_compatible<T, void> {
- static constexpr bool value = ! std::is_const_v<T>;
+ static constexpr bool value = !std::is_const_v<T>;
static size_t count(size_t size);
};
@@ -1064,9 +1039,10 @@ memset(MemSpan<T> const &dst, T const &value) {
* If @a D and @a S are size 1 and instances of @a S can convert to @a D this directly calls @c memset.
* This handles the various synonyms for a single byte, such as @c char, @c unsigned @c char, @c uint8_t, etc.
*/
-template < typename D, typename S >
-auto memset(MemSpan<D> const& dst, S c) -> std::enable_if_t<sizeof(D) == 1 && sizeof(S) == 1 && std::is_convertible_v<S,D>, MemSpan<D>>
-{
+template <typename D, typename S>
+auto
+memset(MemSpan<D> const &dst, S c)
+ -> std::enable_if_t<sizeof(D) == 1 && sizeof(S) == 1 && std::is_convertible_v<S, D>, MemSpan<D>> {
D d = c;
std::memset(dst.data(), d, dst.size());
return dst;
@@ -1092,7 +1068,7 @@ template <typename T> constexpr MemSpan<T>::MemSpan(T *begin, T *end) : _ptr{beg
template <typename T> template <auto N> constexpr MemSpan<T>::MemSpan(T (&a)[N]) : _ptr{a}, _count{N} {
// Magic for string literals to drop the trailing nul terminator, which is almost always what is expected.
if constexpr (N > 0 && std::is_same_v<char const, T>) {
- if (a[N-1] == 0) {
+ if (a[N - 1] == 0) {
_count -= 1;
}
}
@@ -1100,10 +1076,14 @@ template <typename T> template <auto N> constexpr MemSpan<T>::MemSpan(T (&a)[N])
template <typename T> constexpr MemSpan<T>::MemSpan(std::nullptr_t) {}
-template <typename T> template <auto N, typename U, typename META> constexpr MemSpan<T>::MemSpan(std::array<U,N> const& a) : _ptr{a.data()} , _count{a.size()} {}
-template <typename T> template <auto N> constexpr MemSpan<T>::MemSpan(std::array<T,N> & a) : _ptr{a.data()} , _count{a.size()} {}
-template <typename T> template <typename C, typename> constexpr MemSpan<T>::MemSpan(C & c) : _ptr(c.data()), _count(c.size()) {}
-template <typename T> template <typename C, typename> constexpr MemSpan<T>::MemSpan(C const& c) : _ptr(c.data()), _count(c.size()) {}
+template <typename T>
+template <auto N, typename U, typename META>
+constexpr MemSpan<T>::MemSpan(std::array<U, N> const &a) : _ptr{a.data()}, _count{a.size()} {}
+template <typename T> template <auto N> constexpr MemSpan<T>::MemSpan(std::array<T, N> &a) : _ptr{a.data()}, _count{a.size()} {}
+template <typename T> template <typename C, typename> constexpr MemSpan<T>::MemSpan(C &c) : _ptr(c.data()), _count(c.size()) {}
+template <typename T>
+template <typename C, typename>
+constexpr MemSpan<T>::MemSpan(C const &c) : _ptr(c.data()), _count(c.size()) {}
template <typename T>
MemSpan<T> &
@@ -1157,14 +1137,14 @@ template <typename T> MemSpan<T>::operator bool() const {
return _count != 0;
}
-template <typename T> constexpr
-bool
+template <typename T>
+constexpr bool
MemSpan<T>::empty() const {
return _count == 0;
}
-template <typename T> constexpr
-T *
+template <typename T>
+constexpr T *
MemSpan<T>::begin() const {
return _ptr;
}
@@ -1175,14 +1155,14 @@ MemSpan<T>::data() const {
return _ptr;
}
-template <typename T> constexpr
-T *
+template <typename T>
+constexpr T *
MemSpan<T>::data_end() const {
return _ptr + _count;
}
-template <typename T> constexpr
-T *
+template <typename T>
+constexpr T *
MemSpan<T>::end() const {
return _ptr + _count;
}
@@ -1193,21 +1173,21 @@ MemSpan<T>::operator[](size_t idx) const {
return _ptr[idx];
}
-template <typename T> constexpr
-size_t
+template <typename T>
+constexpr size_t
MemSpan<T>::size() const {
return _count;
}
-template <typename T> constexpr
- size_t
- MemSpan<T>::count() const {
+template <typename T>
+constexpr size_t
+MemSpan<T>::count() const {
return _count;
}
-template <typename T> constexpr
- size_t
- MemSpan<T>::length() const {
+template <typename T>
+constexpr size_t
+MemSpan<T>::length() const {
return _count;
}
@@ -1223,14 +1203,14 @@ MemSpan<T>::contains(T const *ptr) const {
return _ptr <= ptr && ptr < _ptr + _count;
}
-template <typename T> constexpr
-auto
+template <typename T>
+constexpr auto
MemSpan<T>::prefix(size_t count) const -> self_type {
return {_ptr, std::min(count, _count)};
}
-template <typename T> constexpr
-auto
+template <typename T>
+constexpr auto
MemSpan<T>::first(size_t count) const -> self_type {
return this->prefix(count);
}
@@ -1238,14 +1218,14 @@ MemSpan<T>::first(size_t count) const -> self_type {
template <typename T>
auto
MemSpan<T>::remove_prefix(size_t count) -> self_type & {
- count = std::min(_count, count);
+ count = std::min(_count, count);
_count -= count;
- _ptr += count;
+ _ptr += count;
return *this;
}
-template <typename T> constexpr
-auto
+template <typename T>
+constexpr auto
MemSpan<T>::suffix(size_t count) const -> self_type {
count = std::min(_count, count);
return {(_ptr + _count) - count, count};
@@ -1269,11 +1249,11 @@ auto
MemSpan<T>::clip_prefix(size_t count) -> self_type {
if (count >= _count) {
auto zret = *this;
- _count = 0;
+ _count = 0;
return zret;
}
- self_type zret { _ptr, count };
- _ptr += count;
+ self_type zret{_ptr, count};
+ _ptr += count;
_count -= count;
return zret;
}
@@ -1283,11 +1263,11 @@ auto
MemSpan<T>::clip_suffix(size_t count) -> self_type {
if (count >= _count) {
auto zret = *this;
- _count = 0;
+ _count = 0;
return zret;
}
_count -= count;
- return { _ptr + _count , count };
+ return {_ptr + _count, count};
}
template <typename T>
@@ -1322,9 +1302,10 @@ template <typename T>
template <typename U>
MemSpan<U>
MemSpan<T>::rebind() const {
- static_assert(detail::is_span_compatible<T, U>::value,
- "MemSpan only allows rebinding between types where the sizes are such that one is an integral multiple of the other.");
- using VOID_PTR = std::conditional_t<std::is_const_v<U>, const void *, void*>;
+ static_assert(
+ detail::is_span_compatible<T, U>::value,
+ "MemSpan only allows rebinding between types where the sizes are such that one is an integral multiple of the other.");
+ using VOID_PTR = std::conditional_t<std::is_const_v<U>, const void *, void *>;
return {static_cast<U *>(static_cast<VOID_PTR>(_ptr)), detail::is_span_compatible<T, U>::count(this->data_size())};
}
@@ -1332,7 +1313,7 @@ template <typename T>
template <typename... Args>
auto
MemSpan<T>::make(Args &&...args) -> self_type & {
- for ( T * elt = this->data(), * limit = this->data_end() ; elt < limit ; ++elt ) {
+ for (T *elt = this->data(), *limit = this->data_end(); elt < limit; ++elt) {
new (elt) T(std::forward<Args>(args)...);
}
return *this;
@@ -1341,44 +1322,47 @@ MemSpan<T>::make(Args &&...args) -> self_type & {
template <typename T>
void
MemSpan<T>::destroy() {
- for ( T * elt = this->data(), * limit = this->data_end() ; elt < limit ; ++elt ) {
+ for (T *elt = this->data(), *limit = this->data_end(); elt < limit; ++elt) {
std::destroy_at(elt);
}
}
// --- void specializations ---
-template <typename U> constexpr MemSpan<void const>::MemSpan(MemSpan<U> const &that) : _ptr(const_cast<std::remove_const_t<U> *>(that._ptr)), _size(sizeof(U) * that.size()) {}
-template <typename U> constexpr MemSpan<void>::MemSpan(MemSpan<U> const &that) : super_type(that) { static_assert(!std::is_const_v<U>, "MemSpan<void> does not support constant memory."); }
+template <typename U>
+constexpr MemSpan<void const>::MemSpan(MemSpan<U> const &that)
+ : _ptr(const_cast<std::remove_const_t<U> *>(that._ptr)), _size(sizeof(U) * that.size()) {}
+template <typename U> constexpr MemSpan<void>::MemSpan(MemSpan<U> const &that) : super_type(that) {
+ static_assert(!std::is_const_v<U>, "MemSpan<void> does not support constant memory.");
+}
inline constexpr MemSpan<void const>::MemSpan(MemSpan<void> const &that) : _ptr(that._ptr), _size(that.size()) {}
-inline constexpr MemSpan<void const>::MemSpan(value_type *ptr, size_t n) : _ptr{const_cast<void*>(ptr)}, _size{n} {}
+inline constexpr MemSpan<void const>::MemSpan(value_type *ptr, size_t n) : _ptr{const_cast<void *>(ptr)}, _size{n} {}
inline constexpr MemSpan<void>::MemSpan(value_type *ptr, size_t n) : super_type(ptr, n) {}
-inline MemSpan<void const>::MemSpan(value_type *begin, value_type *end) : _ptr{const_cast<void*>(begin)}, _size{detail::ptr_distance(begin, end)} {}
-inline MemSpan<void >::MemSpan(value_type *begin, value_type *end) : super_type(begin, end) {}
+inline MemSpan<void const>::MemSpan(value_type *begin, value_type *end)
+ : _ptr{const_cast<void *>(begin)}, _size{detail::ptr_distance(begin, end)} {}
+inline MemSpan<void>::MemSpan(value_type *begin, value_type *end) : super_type(begin, end) {}
template <auto N, typename U>
-constexpr MemSpan<void const>::MemSpan(U (&a)[N]) : _ptr(const_cast<std::remove_const_t<U>*>(a)), _size(N * sizeof(U)) {
+constexpr MemSpan<void const>::MemSpan(U (&a)[N]) : _ptr(const_cast<std::remove_const_t<U> *>(a)), _size(N * sizeof(U)) {
// Magic for string literals to drop the trailing nul terminator, which is almost always what is expected.
if constexpr (N > 0 && std::is_same_v<char const, U>) {
- if (a[N-1] == 0) {
+ if (a[N - 1] == 0) {
_size -= 1;
}
}
}
-template <auto N, typename U>
-constexpr MemSpan<void>::MemSpan(U (&a)[N]) : super_type(a) {
+template <auto N, typename U> constexpr MemSpan<void>::MemSpan(U (&a)[N]) : super_type(a) {
static_assert(!std::is_const_v<U>, "Error: constructing non-constant view with constant data.");
}
template <typename C, typename>
constexpr MemSpan<void const>::MemSpan(C const &c)
- : _ptr(const_cast<std::remove_const_t<std::remove_reference_t<decltype(*(std::declval<C>().data()))>> *>(c.data()))
- , _size(c.size() * sizeof(*(std::declval<C>().data()))) {}
-template <typename C, typename>
-constexpr MemSpan<void>::MemSpan(C const &c) : super_type(c) {}
+ : _ptr(const_cast<std::remove_const_t<std::remove_reference_t<decltype(*(std::declval<C>().data()))>> *>(c.data())),
+ _size(c.size() * sizeof(*(std::declval<C>().data()))) {}
+template <typename C, typename> constexpr MemSpan<void>::MemSpan(C const &c) : super_type(c) {}
inline constexpr MemSpan<void const>::MemSpan(std::nullptr_t) {}
inline constexpr MemSpan<void>::MemSpan(std::nullptr_t) {}
@@ -1430,27 +1414,27 @@ MemSpan<void const>::operator=(MemSpan<void> const &that) -> self_type & {
template <typename U>
auto
MemSpan<void>::operator=(MemSpan<U> const &that) -> self_type & {
- static_assert(! std::is_const_v<U>, "Cannot assign constant pointer to MemSpan<void>");
+ static_assert(!std::is_const_v<U>, "Cannot assign constant pointer to MemSpan<void>");
this->super_type::operator=(that);
return *this;
}
inline auto
MemSpan<void const>::assign(value_type *ptr, size_t n) -> self_type & {
- _ptr = const_cast<void*>(ptr);
+ _ptr = const_cast<void *>(ptr);
_size = n;
return *this;
}
inline auto
-MemSpan<void>::assign(value_type * ptr, size_t n) -> self_type & {
+MemSpan<void>::assign(value_type *ptr, size_t n) -> self_type & {
super_type::assign(ptr, n);
return *this;
}
inline auto
MemSpan<void const>::assign(value_type *first, value_type const *last) -> self_type & {
- _ptr = const_cast<void*>(first);
+ _ptr = const_cast<void *>(first);
_size = detail::ptr_distance(first, last);
return *this;
}
@@ -1531,9 +1515,9 @@ MemSpan<void>::prefix(size_t n) const -> self_type {
inline auto
MemSpan<void const>::remove_prefix(size_t n) -> self_type & {
- n = std::min(_size, n);
+ n = std::min(_size, n);
_size -= n;
- _ptr = detail::ptr_add(_ptr, n);
+ _ptr = detail::ptr_add(_ptr, n);
return *this;
}
@@ -1571,31 +1555,35 @@ inline auto
MemSpan<void const>::clip_prefix(size_t n) -> self_type {
if (n >= _size) {
auto zret = *this;
- _size = 0;
+ _size = 0;
return zret;
}
- self_type zret { _ptr, n };
- _ptr = detail::ptr_add(_ptr, n);
+ self_type zret{_ptr, n};
+ _ptr = detail::ptr_add(_ptr, n);
_size -= n;
return zret;
}
inline auto
-MemSpan<void>::clip_prefix(size_t n) -> self_type { return super_type::clip_prefix(n); }
+MemSpan<void>::clip_prefix(size_t n) -> self_type {
+ return super_type::clip_prefix(n);
+}
inline auto
MemSpan<void const>::clip_suffix(size_t n) -> self_type {
if (n >= _size) {
auto zret = *this;
- _size = 0;
+ _size = 0;
return zret;
}
_size -= n;
- return { detail::ptr_add(_ptr, _size) , n };
+ return {detail::ptr_add(_ptr, _size), n};
}
inline auto
-MemSpan<void>::clip_suffix(size_t n) -> self_type { return super_type::clip_suffix(n); }
+MemSpan<void>::clip_suffix(size_t n) -> self_type {
+ return super_type::clip_suffix(n);
+}
inline constexpr auto
MemSpan<void const>::subspan(size_t offset, size_t n) const -> self_type {
@@ -1607,60 +1595,66 @@ MemSpan<void>::subspan(size_t offset, size_t n) const -> self_type {
return offset <= _size ? self_type{detail::ptr_add(this->data(), offset), std::min(n, _size - offset)} : self_type{};
}
-template <typename T>
-constexpr auto
-MemSpan<T>::restrict(size_t n) -> self_type & {
+template <typename T> constexpr auto MemSpan<T>::restrict(size_t n) -> self_type & {
_count = std::min(_count, n);
return *this;
}
-template <typename T> auto
-MemSpan<void const>::align() const -> self_type { return this->align(alignof(T), sizeof(T)); }
+template <typename T>
+auto
+MemSpan<void const>::align() const -> self_type {
+ return this->align(alignof(T), sizeof(T));
+}
-template <typename T> auto
-MemSpan<void>::align() const -> self_type { return this->align(alignof(T), sizeof(T)); }
+template <typename T>
+auto
+MemSpan<void>::align() const -> self_type {
+ return this->align(alignof(T), sizeof(T));
+}
inline auto
MemSpan<void const>::align(size_t alignment) const -> self_type {
- auto p = uintptr_t(_ptr);
+ auto p = uintptr_t(_ptr);
auto padding = p & (alignment - 1);
- size_t size = 0;
+ size_t size = 0;
if (_size > padding) { // if there's not enough to pad, result is zero size.
size = _size - padding;
}
- return { reinterpret_cast<void*>(p + padding), size };
+ return {reinterpret_cast<void *>(p + padding), size};
}
inline auto
MemSpan<void>::align(size_t alignment) const -> self_type {
- auto && [ ptr, size ] = super_type::align(alignment);
- return { ptr, size };
+ auto &&[ptr, size] = super_type::align(alignment);
+ return {ptr, size};
}
inline auto
MemSpan<void const>::align(size_t alignment, size_t obj_size) const -> self_type {
- auto p = uintptr_t(_ptr);
+ auto p = uintptr_t(_ptr);
auto padding = p & (alignment - 1);
- size_t size = 0;
+ size_t size = 0;
if (_size > padding) { // if there's not enough to pad, result is zero size.
- size = ((_size - padding) / obj_size ) * obj_size;
+ size = ((_size - padding) / obj_size) * obj_size;
}
- return { reinterpret_cast<void*>(p + padding), size };
+ return {reinterpret_cast<void *>(p + padding), size};
}
inline auto
MemSpan<void>::align(size_t alignment, size_t obj_size) const -> self_type {
- auto && [ ptr, n ] = super_type::align(alignment, obj_size);
- return { ptr, n };
+ auto &&[ptr, n] = super_type::align(alignment, obj_size);
+ return {ptr, n};
}
-template < typename U > MemSpan<U>
+template <typename U>
+MemSpan<U>
MemSpan<void const>::rebind() const {
static_assert(std::is_const_v<U>, "Cannot rebind MemSpan<const void> to non-const type.");
return {static_cast<U *>(_ptr), detail::is_span_compatible<value_type, U>::count(_size)};
}
-template < typename U > MemSpan<U>
+template <typename U>
+MemSpan<U>
MemSpan<void>::rebind() const {
return {static_cast<U *>(_ptr), detail::is_span_compatible<value_type, U>::count(_size)};
}
@@ -1681,10 +1675,11 @@ MemSpan<void>::rebind() const -> self_type {
template <>
inline auto
MemSpan<void>::rebind() const -> MemSpan<void const> {
- return { _ptr, _size };
+ return {_ptr, _size};
}
-template <typename U> U *
+template <typename U>
+U *
MemSpan<void>::as_ptr() const {
if (_size != sizeof(U)) {
throw std::invalid_argument("MemSpan::as size is not compatible with target type.");
@@ -1692,7 +1687,8 @@ MemSpan<void>::as_ptr() const {
return static_cast<U *>(_ptr);
}
-template <typename U> U const *
+template <typename U>
+U const *
MemSpan<void const>::as_ptr() const {
if (_size != sizeof(U)) {
throw std::invalid_argument("MemSpan::as size is not compatible with target type.");
@@ -1701,24 +1697,27 @@ MemSpan<void const>::as_ptr() const {
}
/// Deduction guides
-template<typename T, size_t N> MemSpan(std::array<T,N> &) -> MemSpan<T>;
-template<typename T, size_t N> MemSpan(std::array<T,N> const &) -> MemSpan<T const>;
-template<size_t N> MemSpan(char (&)[N]) -> MemSpan<char>;
-template<size_t N> MemSpan(char const (&)[N]) -> MemSpan<char const>;
-template<typename T> MemSpan(std::vector<T> &) -> MemSpan<T>;
-template<typename T> MemSpan(std::vector<T> const&) -> MemSpan<T const>;
-MemSpan(std::string_view const&) -> MemSpan<char const>;
+template <typename T, size_t N> MemSpan(std::array<T, N> &) -> MemSpan<T>;
+template <typename T, size_t N> MemSpan(std::array<T, N> const &) -> MemSpan<T const>;
+template <size_t N> MemSpan(char (&)[N]) -> MemSpan<char>;
+template <size_t N> MemSpan(char const (&)[N]) -> MemSpan<char const>;
+template <typename T> MemSpan(std::vector<T> &) -> MemSpan<T>;
+template <typename T> MemSpan(std::vector<T> const &) -> MemSpan<T const>;
+MemSpan(std::string_view const &) -> MemSpan<char const>;
MemSpan(std::string &) -> MemSpan<char>;
-MemSpan(std::string const&) -> MemSpan<char const>;
+MemSpan(std::string const &) -> MemSpan<char const>;
namespace detail {
struct malloc_liberator {
- void operator()(void * ptr) { ::free(ptr); }
+ void
+ operator()(void *ptr) {
+ ::free(ptr);
+ }
};
} // namespace detail.
/// A variant of @c unique_ptr that handles memory from @c malloc.
-template<typename T> using unique_malloc = std::unique_ptr<T, detail::malloc_liberator>;
+template <typename T> using unique_malloc = std::unique_ptr<T, detail::malloc_liberator>;
}} // namespace swoc::SWOC_VERSION_NS
/// @cond NO_DOXYGEN
diff --git a/code/include/swoc/Scalar.h b/code/include/swoc/Scalar.h
index 640e6b9..339daf3 100644
--- a/code/include/swoc/Scalar.h
+++ b/code/include/swoc/Scalar.h
@@ -123,7 +123,9 @@ template <typename C> struct scalar_unit_round_down_t {
template <intmax_t N, typename C, typename T> struct scalar_round_up_t {
C _n;
- template <intmax_t S, typename I> constexpr operator Scalar<S, I, T>() const {
+ template <intmax_t S, typename I>
+ constexpr
+ operator Scalar<S, I, T>() const {
return Scalar<S, I, T>(scale_conversion_round_up<S, N>(_n));
}
};
@@ -132,7 +134,9 @@ template <intmax_t N, typename C, typename T> struct scalar_round_up_t {
template <intmax_t N, typename C, typename T> struct scalar_round_down_t {
C _n;
- template <intmax_t S, typename I> constexpr operator Scalar<S, I, T>() const {
+ template <intmax_t S, typename I>
+ constexpr
+ operator Scalar<S, I, T>() const {
return Scalar<S, I, T>(scale_conversion_round_down<S, N>(_n));
}
};
@@ -456,7 +460,7 @@ Scalar<N, C, T>::operator=(self_type const &that) -> self_type & {
template <intmax_t N, typename C, typename T>
inline auto
-Scalar<N, C, T>::operator=(detail::scalar_round_up_t<N, C, T> v) -> self_type &{
+Scalar<N, C, T>::operator=(detail::scalar_round_up_t<N, C, T> v) -> self_type & {
_n = v._n;
return *this;
}
diff --git a/code/include/swoc/TextView.h b/code/include/swoc/TextView.h
index 77894e9..25209ff 100644
--- a/code/include/swoc/TextView.h
+++ b/code/include/swoc/TextView.h
@@ -28,8 +28,8 @@
// assign, the error message is too vague for me to be sure - it doesn't even provide the location of
// the method invocation. I've been using g++ 12 for development and I don't see that error.
#if __GNUC__ == 11
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Warray-bounds"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
namespace swoc { inline namespace SWOC_VERSION_NS {
@@ -130,7 +130,11 @@ public:
* are handled by a different constructor so this only disables constructing from two char arrays
* which IMHO makes no sense and should be forbidden.
*/
- template < typename T > explicit TextView(T first, std::enable_if_t<!std::is_array_v<T> && std::is_pointer_v<T> && std::is_convertible_v<T, char const *>, T> last) noexcept : super_type(first, last - first) {}
+ template <typename T>
+ explicit TextView(
+ T first,
+ std::enable_if_t<!std::is_array_v<T> && std::is_pointer_v<T> && std::is_convertible_v<T, char const *>, T> last) noexcept
+ : super_type(first, last - first) {}
/** Construct from any character container following STL standards.
*
@@ -140,13 +144,10 @@ public:
* The container type must have the methods @c data and @c size which must return values convertible
* to @c char @c const @c * and @c size_t respectively.
*/
- template < typename C
- , typename = std::enable_if_t<
- std::is_convertible_v<decltype(std::declval<C>().data()), char const*> &&
- std::is_convertible_v<decltype(std::declval<C>().size()), size_t>
- , void
- >
- > constexpr TextView(C const& c);
+ template <typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), char const *> &&
+ std::is_convertible_v<decltype(std::declval<C>().size()), size_t>,
+ void>>
+ constexpr TextView(C const &c);
/** Construct from literal string or array.
@@ -168,7 +169,7 @@ public:
*
* @internal @a src a reference because it is otherwise ambiguous with the literal constructor.
*/
- TextView(char * & src) : super_type(src, src ? strlen(src) : 0) {}
+ TextView(char *&src) : super_type(src, src ? strlen(src) : 0) {}
/** Construct from a const C-string.
*
@@ -178,7 +179,7 @@ public:
*
* @internal @a src a reference because it is otherwise ambiguous with the literal constructor.
*/
- TextView(char const * & src) : super_type(src, src ? strlen(src) : 0) {}
+ TextView(char const *&src) : super_type(src, src ? strlen(src) : 0) {}
/** Construct from nullptr.
This implicitly makes the length 0.
@@ -200,7 +201,7 @@ public:
/// Assign from C-string @a s.
self_type &operator=(char *&s);
/// Assign from C-string @a s.
- self_type &operator=(char const * & s);
+ self_type &operator=(char const *&s);
/// Assign from a @c std::string.
self_type &operator=(const std::string &s);
@@ -212,7 +213,7 @@ public:
*
* @note @c c_str must be a null terminated string. The null byte is not included in the view.
*/
- self_type &assign(char * & c_str);
+ self_type &assign(char *&c_str);
/** Assign a view of the @a c_str
*
@@ -221,7 +222,7 @@ public:
*
* @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);
+ self_type &assign(char const *&c_str);
/** Assign from a pointer and size.
*
@@ -254,7 +255,7 @@ public:
* @endcode
* The last character in @a tv will be 'g'.
*/
- template <size_t N> self_type & assign(const char (&s)[N]) noexcept;
+ template <size_t N> self_type &assign(const char (&s)[N]) noexcept;
/** Assign from any character container following STL standards.
*
@@ -264,13 +265,11 @@ public:
* The container type must have the methods @c data and @c size which must return values convertible
* to @c char @c const @c * and @c size_t respectively.
*/
- template < typename C
- , typename = std::enable_if_t<
- std::is_convertible_v<decltype(std::declval<C>().data()), char const*> &&
- std::is_convertible_v<decltype(std::declval<C>().size()), size_t>
- , void
- >
- > constexpr self_type & assign(C const& c) {
+ template <typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), char const *> &&
+ std::is_convertible_v<decltype(std::declval<C>().size()), size_t>,
+ void>>
+ constexpr self_type &
+ assign(C const &c) {
return this->assign(c.data(), c.size());
}
@@ -915,7 +914,7 @@ public:
struct CaselessEqual {
/// @return @c true if the view contants are equal when compared without regard to case.
bool
- operator()(self_type const& lhs, self_type const& rhs) const noexcept {
+ operator()(self_type const &lhs, self_type const &rhs) const noexcept {
return lhs.size() == rhs.size() && 0 == strcasecmp(lhs, rhs);
}
};
@@ -1009,9 +1008,9 @@ template <int RADIX>
uintmax_t
svto_radix(TextView &src) {
static_assert(0 < RADIX && RADIX <= 36, "Radix must be in the range 1..36");
- static constexpr auto MAX = std::numeric_limits<uintmax_t>::max();
+ static constexpr auto MAX = std::numeric_limits<uintmax_t>::max();
static constexpr auto OVERFLOW_LIMIT = MAX / RADIX;
- uintmax_t zret = 0;
+ uintmax_t zret = 0;
int8_t v;
while (src.size() && (0 <= (v = swoc::svtoi_convert[uint8_t(*src)])) && v < RADIX) {
// Tweaked for performance - need to check range after @a RADIX multiply.
@@ -1112,7 +1111,7 @@ TextView::operator++(int) -> self_type {
}
inline auto
-TextView::operator+=(size_t n) -> self_type &{
+TextView::operator+=(size_t n) -> self_type & {
this->remove_prefix(n);
return *this;
}
@@ -1148,12 +1147,12 @@ TextView::operator=(const std::string &s) -> self_type & {
}
inline auto
-TextView::assign(char * & c_str) -> self_type & {
+TextView::assign(char *&c_str) -> self_type & {
return this->assign(c_str, strlen(c_str));
}
inline auto
-TextView::assign(char const * & c_str) -> self_type & {
+TextView::assign(char const *&c_str) -> self_type & {
return this->assign(c_str, strlen(c_str));
}
@@ -1165,7 +1164,7 @@ TextView::assign(const std::string &s) -> self_type & {
inline TextView &
TextView::assign(char const *ptr, size_t n) {
- *this = super_type(ptr, n == npos ? ( ptr ? ::strlen(ptr) : 0) : n);
+ *this = super_type(ptr, n == npos ? (ptr ? ::strlen(ptr) : 0) : n);
return *this;
}
@@ -1434,7 +1433,7 @@ TextView::take_suffix_at(std::string_view const &delimiters) {
template <typename F>
TextView::self_type
-TextView::take_suffix_if(F const &pred){
+TextView::take_suffix_if(F const &pred) {
return this->take_suffix_at(this->rfind_if(pred));
}
@@ -1562,12 +1561,12 @@ TextView::trim_if(F const &pred) {
}
constexpr inline auto
-TextView::data() const noexcept -> value_type const* {
+TextView::data() const noexcept -> value_type const * {
return super_type::data();
}
constexpr inline auto
-TextView::data_end() const noexcept -> value_type const* {
+TextView::data_end() const noexcept -> value_type const * {
return this->data() + this->size();
}
@@ -1723,7 +1722,7 @@ extern template std::ostream &TextView::stream_write(std::ostream &, const TextV
* an issue.
*/
template <typename X, typename V> class TransformView {
- using self_type = TransformView; ///< Self reference type.
+ using self_type = TransformView; ///< Self reference type.
using source_iterator = decltype(V{}.begin());
public:
@@ -1777,9 +1776,15 @@ public:
explicit operator bool() const;
/// Iterator to first transformed character.
- iterator begin() const { return *this; }
+ iterator
+ begin() const {
+ return *this;
+ }
/// Iterator past last transformed character.
- iterator end() const { return self_type{_xf, _limit}; }
+ iterator
+ end() const {
+ return self_type{_xf, _limit};
+ }
protected:
transform_type _xf; ///< Per character transform functor.
@@ -1787,7 +1792,7 @@ protected:
source_iterator _limit; ///< End of source view.
/// Special constructor for making an empty instance to serve as the @c end iterator.
- TransformView(transform_type && xf, source_iterator && limit) : _xf(xf), _spot(limit), _limit(limit) {}
+ TransformView(transform_type &&xf, source_iterator &&limit) : _xf(xf), _spot(limit), _limit(limit) {}
};
template <typename X, typename V>
@@ -1899,7 +1904,7 @@ public:
value_type operator*() const;
/// Move to next element.
- self_type & operator++();
+ self_type &operator++();
/// Move to next element.
self_type operator++(int);
@@ -1920,7 +1925,7 @@ protected:
source_iterator _limit; ///< End marker.
/// Special constructor for making an empty instance to serve as the @c end iterator.
- explicit TransformView(source_iterator && limit) : _spot(limit), _limit(limit) {}
+ explicit TransformView(source_iterator &&limit) : _spot(limit), _limit(limit) {}
};
template <typename V>
@@ -1962,16 +1967,21 @@ TransformView<void, V>::empty() const {
return _spot == _limit;
}
-template <typename V>
-TransformView<void, V>::operator bool() const {
+template <typename V> TransformView<void, V>::operator bool() const {
return _spot != _limit;
}
template <typename V>
-auto TransformView<void, V>::begin() const -> self_type { return *this; }
+auto
+TransformView<void, V>::begin() const -> self_type {
+ return *this;
+}
template <typename V>
-auto TransformView<void, V>::end() const -> self_type { return self_type{_limit}; }
+auto
+TransformView<void, V>::end() const -> self_type {
+ return self_type{_limit};
+}
/// @cond INTERNAL_DETAIL
// Capture @c void transforms and make them identity transforms.
@@ -1999,7 +2009,8 @@ namespace literals {
* rather bizarre to me, but there it is. Update: this depends on the version of the compiler,
* so hopefully someday this can be removed.
*/
-constexpr std::string_view operator"" _sv(const char *s, size_t n) {
+constexpr std::string_view
+operator"" _sv(const char *s, size_t n) {
return {s, n};
}
@@ -2013,7 +2024,8 @@ constexpr std::string_view operator"" _sv(const char *s, size_t n) {
* rather bizarre to me, but there it is. Update: this depends on the version of the compiler,
* so hopefully someday this can be removed.
*/
-constexpr swoc::TextView operator"" _tv(const char *s, size_t n) {
+constexpr swoc::TextView
+operator"" _tv(const char *s, size_t n) {
return {s, n};
}
} // namespace literals
@@ -2048,12 +2060,15 @@ template <typename X, typename V> struct iterator_traits<swoc::TransformView<X,
template <> struct hash<swoc::TextView> {
static constexpr hash<string_view> super_hash{};
- size_t operator()(swoc::TextView const& s) const { return super_hash(s); }
+ size_t
+ operator()(swoc::TextView const &s) const {
+ return super_hash(s);
+ }
};
/// @endcond
} // namespace std
#if __GNUC__ == 11
-# pragma GCC diagnostic pop
+#pragma GCC diagnostic pop
#endif
diff --git a/code/include/swoc/Vectray.h b/code/include/swoc/Vectray.h
index d32fc95..e2e6485 100644
--- a/code/include/swoc/Vectray.h
+++ b/code/include/swoc/Vectray.h
@@ -33,29 +33,28 @@ namespace swoc { inline namespace SWOC_VERSION_NS {
*
* The interface is designed to mimic that of @c std::vector.
*/
-template < typename T, size_t N, class A = std::allocator<T> >
-class Vectray {
- using self_type = Vectray; ///< Self reference type.
+template <typename T, size_t N, class A = std::allocator<T>> class Vectray {
+ using self_type = Vectray; ///< Self reference type.
using vector_type = std::vector<T, A>; ///< Internal dynamic storage type.
-public: // STL compliance types.
- using value_type = T; ///< Element type for container.
- using reference = std::remove_reference<T>&; ///< Reference to element.
- using const_reference = std::remove_reference<T> const&; ///< Reference to constant element.
- using pointer = std::remove_reference<T>*; ///< Pointer to element.
- using const_pointer = std::remove_reference<T> const*; ///< Pointer to constant element.
- using allocator_type = A; ///< Dynamic storage allocator.
- using size_type = typename vector_type::size_type; ///< Type for element count.
- using difference_type = typename vector_type::difference_type; ///< Iterator difference.
- using iterator = typename swoc::MemSpan<T>::iterator; ///< Element iteration.
- using const_iterator = typename swoc::MemSpan<const T>::iterator; ///< Constant element iteration.
+public: // STL compliance types.
+ using value_type = T; ///< Element type for container.
+ using reference = std::remove_reference<T> &; ///< Reference to element.
+ using const_reference = std::remove_reference<T> const &; ///< Reference to constant element.
+ using pointer = std::remove_reference<T> *; ///< Pointer to element.
+ using const_pointer = std::remove_reference<T> const *; ///< Pointer to constant element.
+ using allocator_type = A; ///< Dynamic storage allocator.
+ using size_type = typename vector_type::size_type; ///< Type for element count.
+ using difference_type = typename vector_type::difference_type; ///< Iterator difference.
+ using iterator = typename swoc::MemSpan<T>::iterator; ///< Element iteration.
+ using const_iterator = typename swoc::MemSpan<const T>::iterator; ///< Constant element iteration.
// Need to add reverse iterators - @c reverse_iterator and @c const_reverse_iterator
/// Internal (fixed) storage.
struct FixedStore {
std::array<std::byte, sizeof(T) * N> _raw; ///< Raw memory for element storage.
- size_t _count = 0; ///< Number of valid elements.
- allocator_type _a; ///< Allocator instance - used for construction.
+ size_t _count = 0; ///< Number of valid elements.
+ allocator_type _a; ///< Allocator instance - used for construction.
FixedStore() = default; ///< Default construct - empty.
@@ -63,7 +62,7 @@ public: // STL compliance types.
*
* @param a Allocator.
*/
- explicit FixedStore(allocator_type const& a) : _a(a) {}
+ explicit FixedStore(allocator_type const &a) : _a(a) {}
~FixedStore();
@@ -71,10 +70,10 @@ public: // STL compliance types.
MemSpan<T> span();
/// @return A pointer to the data.
- T * data();
+ T *data();
/// @return A pointer to the data.
- T const * data() const;
+ T const *data() const;
};
using DynamicStore = vector_type; ///< Dynamic (heap) storage.
@@ -92,84 +91,88 @@ public:
~Vectray() = default;
/// Construct empty instance with allocator.
- constexpr explicit Vectray(allocator_type const& a) : _store(std::in_place_type_t<FixedStore>{}, a) {}
+ constexpr explicit Vectray(allocator_type const &a) : _store(std::in_place_type_t<FixedStore>{}, a) {}
/** 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{});
+ explicit Vectray(size_type n, allocator_type const &alloc = allocator_type{});
/// Move constructor for difference static sized instance.
- template < size_t M > Vectray(Vectray<T, M, A> && that);
+ template <size_t M> Vectray(Vectray<T, M, A> &&that);
/// Move constructor.
- Vectray(self_type && that, allocator_type const& a);
+ Vectray(self_type &&that, allocator_type const &a);
/// @return The number of elements in the container.
size_type size() const;
/// @return A pointer to the data.
- T * data();
+ T *data();
/// @return A pointer to the data.
- T const * data() const;
+ T const *data() const;
/// @return @c true if no valid elements, @c false if at least one valid element.
bool empty() const;
/// Implicitly convert to a @c MemSpan.
- operator span () { return this->items(); }
+ operator span() { return this->items(); }
/// Implicitly convert to a @c MemSpan.
- operator const_span () const { return this->items(); }
+ operator const_span() const { return this->items(); }
/** 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;
/// @return A reference to the first element.
- T const& front() const {
+ T const &
+ front() const {
return (*this)[0];
}
/// @return A reference to the first element.
- T & front() {
+ T &
+ front() {
return (*this)[0];
}
/// @return A reference to the last element.
- T const& back() const {
- return (*this)[this->size()-1];
+ T const &
+ back() const {
+ return (*this)[this->size() - 1];
}
/// @return A reference to the last element.
- T & back() {
- return (*this)[this->size()-1];
+ T &
+ back() {
+ return (*this)[this->size() - 1];
}
/** Append an element by copy.
*
* @param t Element to add.
* @return @a this.
*/
- self_type& push_back(T const& t);
+ self_type &push_back(T const &t);
/** Append an element by move.
*
* @param t Element to add.
* @return @a this.
*/
- self_type& push_back(T && t);
+ self_type &push_back(T &&t);
/** Append an element by direct construction.
*
@@ -177,13 +180,13 @@ public:
* @param args Constructor arguments.
* @return @a this
*/
- template < typename ... Args> self_type & emplace_back(Args && ... args);
+ 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();
+ self_type &pop_back();
/// Iterator for first element.
const_iterator begin() const;
@@ -205,7 +208,7 @@ protected:
/// @note This is constructed as fixed but can change to dynamic. It can never change back.
std::variant<FixedStore, DynamicStore> _store;
- static constexpr auto FIXED = 0; ///< Variant index for fixed storage.
+ static constexpr auto FIXED = 0; ///< Variant index for fixed storage.
static constexpr auto DYNAMIC = 1; ///< Variant index for dynamic storage.
/// Get the span of the valid items.
@@ -216,7 +219,6 @@ protected:
/// 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.
@@ -228,11 +230,9 @@ protected:
// --- Implementation ---
-template<typename T, size_t N, typename A>
-Vectray<T,N,A>::Vectray() {}
+template <typename T, size_t N, typename A> Vectray<T, N, A>::Vectray() {}
-template<typename T, size_t N, class A>
-Vectray<T, N, A>::Vectray(Vectray::size_type n, allocator_type const& alloc) : Vectray() {
+template <typename T, size_t N, class A> Vectray<T, N, A>::Vectray(Vectray::size_type n, allocator_type const &alloc) : Vectray() {
this->reserve(n);
while (n-- > 0) {
this->emplace_back();
@@ -246,9 +246,8 @@ template <typename T, size_t N, class A> template <size_t M> Vectray<T, N, A>::V
} else {
auto span = std::get<FIXED>(that._store).span();
if (span.size() > N) {
-
} else {
- for ( auto && item : span ) {
+ for (auto &&item : span) {
this->template emplace_back(std::move(item));
}
}
@@ -256,79 +255,81 @@ template <typename T, size_t N, class A> template <size_t M> Vectray<T, N, A>::V
}
template <typename T, size_t N, class A> Vectray<T, N, A>::FixedStore::~FixedStore() {
- for ( auto & item : this->span() ) {
+ for (auto &item : this->span()) {
std::destroy_at(std::addressof(item));
}
}
-template<typename T, size_t N, class A>
-MemSpan<T> Vectray<T, N, A>::FixedStore::span() {
+template <typename T, size_t N, class A>
+MemSpan<T>
+Vectray<T, N, A>::FixedStore::span() {
return MemSpan<std::byte>(_raw).template rebind<T>();
}
-template<typename T, size_t N, class A>
-T * Vectray<T, N, A>::FixedStore::data() {
- return reinterpret_cast<T*>(_raw.data());
+template <typename T, size_t N, class A>
+T *
+Vectray<T, N, A>::FixedStore::data() {
+ return reinterpret_cast<T *>(_raw.data());
}
-template<typename T, size_t N, class A>
-T const * Vectray<T, N, A>::FixedStore::data() const {
- return reinterpret_cast<T*>(_raw.data());
+template <typename T, size_t N, class A>
+T const *
+Vectray<T, N, A>::FixedStore::data() const {
+ return reinterpret_cast<T *>(_raw.data());
}
-template<typename T, size_t N, typename A>
-T& Vectray<T,N,A>::operator[](size_type idx) {
+template <typename T, size_t N, typename A>
+T &
+Vectray<T, N, A>::operator[](size_type idx) {
return this->items()[idx];
}
-template<typename T, size_t N, typename A>
-T const& Vectray<T,N,A>::operator[](size_type idx) const {
+template <typename T, size_t N, typename A>
+T const &
+Vectray<T, N, A>::operator[](size_type idx) const {
return this->items[idx];
}
-template<typename T, size_t N, typename A>
-auto Vectray<T,N,A>::push_back(const T& t) -> self_type& {
- std::visit(swoc::meta::vary{
- [&](FixedStore& fs) -> void {
- if (fs._count < N) {
- new(reinterpret_cast<T*>(fs._raw.data()) + fs._count++) T(t); // A::traits ?
- } else {
- this->transfer();
- std::get<DYNAMIC>(_store).push_back(t);
- }
- }
- , [&](DynamicStore& ds) -> void {
- ds.push_back(t);
- }
- }, _store);
+template <typename T, size_t N, typename A>
+auto
+Vectray<T, N, A>::push_back(const T &t) -> self_type & {
+ std::visit(swoc::meta::vary{[&](FixedStore &fs) -> void {
+ if (fs._count < N) {
+ new (reinterpret_cast<T *>(fs._raw.data()) + fs._count++) T(t); // A::traits ?
+ } else {
+ this->transfer();
+ std::get<DYNAMIC>(_store).push_back(t);
+ }
+ },
+ [&](DynamicStore &ds) -> void { ds.push_back(t); }},
+ _store);
return *this;
}
-template<typename T, size_t N, typename A>
-auto Vectray<T,N,A>::push_back(T && t) -> self_type& {
- std::visit(swoc::meta::vary{
- [&](FixedStore& fs) -> void {
- if (fs._count < N) {
- new(reinterpret_cast<T*>(fs._raw.data()) + fs._count++) T(std::move(t)); // A::traits ?
- } else {
- this->transfer();
- std::get<DYNAMIC>(_store).push_back(std::move(t));
- }
- }
- , [&](DynamicStore& ds) -> void {
- ds.push_back(std::move(t));
- }
- }, _store);
+template <typename T, size_t N, typename A>
+auto
+Vectray<T, N, A>::push_back(T &&t) -> self_type & {
+ std::visit(swoc::meta::vary{[&](FixedStore &fs) -> void {
+ if (fs._count < N) {
+ new (reinterpret_cast<T *>(fs._raw.data()) + fs._count++) T(std::move(t)); // A::traits ?
+ } else {
+ this->transfer();
+ std::get<DYNAMIC>(_store).push_back(std::move(t));
+ }
+ },
+ [&](DynamicStore &ds) -> void { ds.push_back(std::move(t)); }},
+ _store);
return *this;
}
-template<typename T, size_t N, class A>
-template<typename... Args>
-typename Vectray<T,N,A>::self_type & Vectray<T, N, A>::emplace_back(Args && ... args) {
+template <typename T, size_t N, class A>
+template <typename... Args>
+typename Vectray<T, N, A>::self_type &
+Vectray<T, N, A>::emplace_back(Args &&...args) {
if (_store.index() == FIXED) {
- auto& fs{std::get<FIXED>(_store)};
+ auto &fs{std::get<FIXED>(_store)};
if (fs._count < N) {
- new(reinterpret_cast<T*>(fs._raw.data()) + fs._count++) T(std::forward<Args>(args)...); // A::traits ?
+ new (reinterpret_cast<T *>(fs._raw.data()) + fs._count++) T(std::forward<Args>(args)...); // A::traits ?
return *this;
}
this->transfer(); // transfer to dynamic and fall through to add item.
@@ -337,91 +338,102 @@ typename Vectray<T,N,A>::self_type & Vectray<T, N, A>::emplace_back(Args && ...
return *this;
}
-template<typename T, size_t N, class A>
-auto Vectray<T, N, A>::pop_back() -> self_type & {
- std::visit(swoc::meta::vary{
- [&](FixedStore& fs) -> void { std::destroy_at(fs.span()[--fs._count]); }
- , [&](DynamicStore& ds) -> void { ds.pop_back(); }
- }, _store);
+template <typename T, size_t N, class A>
+auto
+Vectray<T, N, A>::pop_back() -> self_type & {
+ std::visit(swoc::meta::vary{[&](FixedStore &fs) -> void { std::destroy_at(fs.span()[--fs._count]); },
+ [&](DynamicStore &ds) -> void { ds.pop_back(); }},
+ _store);
return *this;
}
-template<typename T, size_t N, typename A>
-auto Vectray<T,N,A>::size() const -> size_type {
- return std::visit(swoc::meta::vary{
- [](FixedStore const& fs) { return fs._count; }
- , [](DynamicStore const& ds) { return ds.size(); }
- }, _store);
+template <typename T, size_t N, typename A>
+auto
+Vectray<T, N, A>::size() const -> size_type {
+ return std::visit(
+ swoc::meta::vary{[](FixedStore const &fs) { return fs._count; }, [](DynamicStore const &ds) { return ds.size(); }}, _store);
}
-template<typename T, size_t N, typename A>
-bool Vectray<T,N,A>::empty() const {
- return std::visit(swoc::meta::vary{
- [](FixedStore const& fs) { return fs._count == 0; }
- , [](DynamicStore const& ds) { return ds.empty(); }
- }, _store);
+template <typename T, size_t N, typename A>
+bool
+Vectray<T, N, A>::empty() const {
+ return std::visit(
+ swoc::meta::vary{[](FixedStore const &fs) { return fs._count == 0; }, [](DynamicStore const &ds) { return ds.empty(); }},
+ _store);
}
// --- iterators
-template<typename T, size_t N, typename A>
-auto Vectray<T,N,A>::begin() const -> const_iterator { return this->items().begin(); }
+template <typename T, size_t N, typename A>
+auto
+Vectray<T, N, A>::begin() const -> const_iterator {
+ return this->items().begin();
+}
-template<typename T, size_t N, typename A>
-auto Vectray<T,N,A>::end() const -> const_iterator { return this->items().end(); }
+template <typename T, size_t N, typename A>
+auto
+Vectray<T, N, A>::end() const -> const_iterator {
+ return this->items().end();
+}
-template<typename T, size_t N, typename A>
-auto Vectray<T,N,A>::begin() -> iterator { return this->items().begin(); }
+template <typename T, size_t N, typename A>
+auto
+Vectray<T, N, A>::begin() -> iterator {
+ return this->items().begin();
+}
-template<typename T, size_t N, typename A>
-auto Vectray<T,N,A>::end() -> iterator { return this->items().end(); }
+template <typename T, size_t N, typename A>
+auto
+Vectray<T, N, A>::end() -> iterator {
+ return this->items().end();
+}
// --- iterators
-template<typename T, size_t N, class A>
-void Vectray<T, N, A>::transfer(size_type rN) {
+template <typename T, size_t N, class A>
+void
+Vectray<T, N, A>::transfer(size_type rN) {
DynamicStore tmp{std::get<FIXED>(_store)._a};
tmp.reserve(rN);
- for (auto&& item : this->items()) {
+ for (auto &&item : this->items()) {
tmp.emplace_back(std::move(item)); // move if supported, copy if not.
}
// Fixed elements destroyed here, by variant.
_store = std::move(tmp);
}
-template<typename T, size_t N, class A>
-auto Vectray<T, N, A>::items() const -> const_span {
- return std::visit(swoc::meta::vary{
- [](FixedStore const& fs) { fs.span(); }
- , [](DynamicStore const& ds) { return const_span(ds.data(), ds.size()); }
- }, _store);
+template <typename T, size_t N, class A>
+auto
+Vectray<T, N, A>::items() const -> const_span {
+ return std::visit(swoc::meta::vary{[](FixedStore const &fs) { fs.span(); },
+ [](DynamicStore const &ds) { return const_span(ds.data(), ds.size()); }},
+ _store);
}
-template<typename T, size_t N, class A>
-T * Vectray<T, N, A>::data() {
- return std::visit(swoc::meta::vary{
- [](FixedStore const& fs) { fs.data(); }
- , [](DynamicStore const& ds) { return ds.data(); }
- }, _store);
+template <typename T, size_t N, class A>
+T *
+Vectray<T, N, A>::data() {
+ return std::visit(swoc::meta::vary{[](FixedStore const &fs) { fs.data(); }, [](DynamicStore const &ds) { return ds.data(); }},
+ _store);
}
-template<typename T, size_t N, class A>
-T const * Vectray<T, N, A>::data() const {
- return std::visit(swoc::meta::vary{
- [](FixedStore const& fs) { fs.data(); }
- , [](DynamicStore const& ds) { return ds.data(); }
- }, _store);
+template <typename T, size_t N, class A>
+T const *
+Vectray<T, N, A>::data() const {
+ return std::visit(swoc::meta::vary{[](FixedStore const &fs) { fs.data(); }, [](DynamicStore const &ds) { return ds.data(); }},
+ _store);
}
-template<typename T, size_t N, class A>
-auto Vectray<T, N, A>::items() -> span {
- return std::visit(swoc::meta::vary{
- [](FixedStore & fs) { return fs.span(); }
- , [](DynamicStore & ds) { return span(ds.data(), ds.size()); }
- }, _store);
+template <typename T, size_t N, class A>
+auto
+Vectray<T, N, A>::items() -> span {
+ return std::visit(
+ swoc::meta::vary{[](FixedStore &fs) { return fs.span(); }, [](DynamicStore &ds) { return span(ds.data(), ds.size()); }},
+ _store);
}
-template<typename T, size_t N, class A>
-void Vectray<T, N, A>::reserve(Vectray::size_type n) {
+template <typename T, size_t N, class A>
+void
+Vectray<T, N, A>::reserve(Vectray::size_type n) {
if (DYNAMIC == _store.index()) {
std::get<DYNAMIC>(_store).reserve(n);
} else if (n > N) {
@@ -429,5 +441,4 @@ void Vectray<T, N, A>::reserve(Vectray::size_type n) {
}
}
-}} // namespace swoc
-
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/include/swoc/bwf_base.h b/code/include/swoc/bwf_base.h
index 58f8152..d5c426d 100644
--- a/code/include/swoc/bwf_base.h
+++ b/code/include/swoc/bwf_base.h
@@ -118,7 +118,7 @@ protected:
static constexpr uint8_t UPPER_TYPE_CHAR = 0x20; ///< Upper case flag.
static constexpr uint8_t NUMERIC_TYPE_CHAR = 0x40; ///< Numeric output.
static constexpr uint8_t SIGN_CHAR = 0x80; ///< Is sign character.
- } _prop; ///< Character property map.
+ } _prop; ///< Character property map.
};
/** Format string support.
@@ -141,9 +141,9 @@ struct Format {
Format(TextView fmt);
/// Move constructor.
- Format(self_type && that) = default;
+ Format(self_type &&that) = default;
/// No copy
- Format(self_type const&) = delete;
+ Format(self_type const &) = delete;
/// Extraction support for TextView.
struct TextViewExtractor {
@@ -180,7 +180,7 @@ struct Format {
/// Extraction support for pre-parsed format strings.
struct FormatExtractor {
MemSpan<Spec const> _fmt; ///< Parsed format string.
- int _idx = 0; ///< Element index.
+ int _idx = 0; ///< Element index.
/// @return @c true if more format string, @c false if none.
explicit operator bool() const;
@@ -202,13 +202,25 @@ struct Format {
using Container = std::vector<Spec>;
Container _items; ///< Items from format string.
- using iterator = Container::iterator;
+ using iterator = Container::iterator;
using const_iterator = Container::const_iterator;
- iterator begin() { return _items.begin(); }
- iterator end() { return _items.end(); }
- const_iterator begin() const { return _items.begin(); }
- const_iterator end() const { return _items.end(); }
+ iterator
+ begin() {
+ return _items.begin();
+ }
+ iterator
+ end() {
+ return _items.end();
+ }
+ const_iterator
+ begin() const {
+ return _items.begin();
+ }
+ const_iterator
+ end() const {
+ return _items.end();
+ }
};
// Name binding - support for having format specifier names.
@@ -282,12 +294,13 @@ template <typename F> class NameMap {
public:
/// Signature for generators.
using Generator = std::function<F>;
+
protected:
using Map = std::unordered_map<std::string_view, Generator>;
+
private:
using self_type = NameMap; ///< self reference type.
public:
-
/// Construct an empty container.
NameMap();
@@ -905,13 +918,13 @@ BufferWriter::print_nfv(Binding &&names, Extractor &&ex, bwf::ArgPack const &arg
template <typename... Args>
BufferWriter &
-BufferWriter::print(const TextView &fmt, Args &&... args) {
+BufferWriter::print(const TextView &fmt, Args &&...args) {
return this->print_nfv(bwf::Global_Names.bind(), bwf::Format::bind(fmt), bwf::ArgTuple{std::forward_as_tuple(args...)});
}
template <typename... Args>
BufferWriter &
-BufferWriter::print(bwf::Format const &fmt, Args &&... args) {
+BufferWriter::print(bwf::Format const &fmt, Args &&...args) {
return this->print_nfv(bwf::Global_Names.bind(), fmt.bind(), bwf::ArgTuple{std::forward_as_tuple(args...)});
}
@@ -993,7 +1006,8 @@ BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, MemSpan<void cons
* @internal Overload to avoid unfortunate ambiguities when constructing the span from other spans.
* in particular @c MemSpan<char> vs. @c TextView.
*/
-inline BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, MemSpan<void> const &span) {
+inline BufferWriter &
+bwformat(BufferWriter &w, bwf::Spec const &spec, MemSpan<void> const &span) {
return bwformat(w, spec, span.rebind<void const>());
}
@@ -1056,8 +1070,7 @@ bwformat(BufferWriter &w, bwf::Spec const &, TransformView<X, V> &&view) {
template <typename F>
auto
bwformat(BufferWriter &w, bwf::Spec const &spec, F &&f) ->
- typename std::enable_if<std::is_floating_point_v<typename std::remove_reference_t<F>>, BufferWriter &>::type
-{
+ typename std::enable_if<std::is_floating_point_v<typename std::remove_reference_t<F>>, BufferWriter &>::type {
return f < 0 ? bwf::Format_Float(w, spec, -f, true) : bwf::Format_Float(w, spec, f, false);
}
@@ -1136,10 +1149,8 @@ template <typename... Args>
std::string &
bwprint_v(std::string &s, TextView fmt, std::tuple<Args...> const &args) {
auto const len = s.size(); // remember initial size
- auto printer = [&]() {
- return FixedBufferWriter(s.data(), s.capacity()).print_v(fmt, args).extent();
- };
- size_t n = printer();
+ auto printer = [&]() { return FixedBufferWriter(s.data(), s.capacity()).print_v(fmt, args).extent(); };
+ size_t n = printer();
s.resize(n); // always need to resize - if shorter, must clip pre-existing text.
if (n > len) { // dropped data, try again.
printer();
@@ -1165,7 +1176,7 @@ bwprint_v(std::string &s, TextView fmt, std::tuple<Args...> const &args) {
*/
template <typename... Args>
std::string &
-bwprint(std::string &s, TextView fmt, Args &&... args) {
+bwprint(std::string &s, TextView fmt, Args &&...args) {
return bwprint_v(s, fmt, std::forward_as_tuple(args...));
}
@@ -1183,17 +1194,15 @@ bwprint(std::string &s, TextView fmt, Args &&... args) {
*/
template <typename... Args>
std::string &
-bwappend(std::string &s, TextView fmt, Args &&... args) {
- auto const len = s.length(); // Text to preserve.
+bwappend(std::string &s, TextView fmt, Args &&...args) {
+ auto const len = s.length(); // Text to preserve.
auto const capacity = s.capacity(); // Working space.
- auto printer = [&]() {
- return FixedBufferWriter(s.data()+len, s.capacity()-len).print(fmt, args...).extent();
- };
+ auto printer = [&]() { return FixedBufferWriter(s.data() + len, s.capacity() - len).print(fmt, args...).extent(); };
// Resize first, otherwise capacity past @a len is cleared on @c resize.
s.resize(capacity);
auto n = printer() + len; // Get the final length.
- s.resize(n); // Adjust to correct string length.
- if (n > capacity) { // dropped data, write it again.
+ s.resize(n); // Adjust to correct string length.
+ if (n > capacity) { // dropped data, write it again.
printer();
}
return s;
@@ -1202,7 +1211,7 @@ bwappend(std::string &s, TextView fmt, Args &&... args) {
/// @cond COVARY
template <typename... Args>
auto
-FixedBufferWriter::print(TextView fmt, Args &&... args) -> self_type & {
+FixedBufferWriter::print(TextView fmt, Args &&...args) -> self_type & {
return static_cast<self_type &>(this->super_type::print_v(fmt, std::forward_as_tuple(args...)));
}
@@ -1214,7 +1223,7 @@ FixedBufferWriter::print_v(TextView fmt, std::tuple<Args...> const &args) -> sel
template <typename... Args>
auto
-FixedBufferWriter::print(bwf::Format const &fmt, Args &&... args) -> self_type & {
+FixedBufferWriter::print(bwf::Format const &fmt, Args &&...args) -> self_type & {
return static_cast<self_type &>(this->super_type::print_v(fmt, std::forward_as_tuple(args...)));
}
@@ -1315,7 +1324,8 @@ BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::HexDump cons
*
* This treats @a ww as a view and prints it as text.
*/
-inline BufferWriter &bwformat(BufferWriter &w, bwf::Spec const& spec, BufferWriter const& ww) {
+inline BufferWriter &
+bwformat(BufferWriter &w, bwf::Spec const &spec, BufferWriter const &ww) {
return bwformat(w, spec, TextView(ww));
}
@@ -1327,7 +1337,7 @@ BufferWriter::format(bwf::Spec const &spec, T const &t) {
template <typename T>
BufferWriter &
-BufferWriter::format(bwf::Spec const &spec, T && t) {
+BufferWriter::format(bwf::Spec const &spec, T &&t) {
return bwformat(*this, spec, t);
}
diff --git a/code/include/swoc/bwf_ex.h b/code/include/swoc/bwf_ex.h
index 47fc0b4..3e0af20 100644
--- a/code/include/swoc/bwf_ex.h
+++ b/code/include/swoc/bwf_ex.h
@@ -45,7 +45,7 @@ struct Errno {
struct Date {
/// Default format
static constexpr std::string_view DEFAULT_FORMAT{"%Y %b %d %H:%M:%S"_sv};
- time_t _epoch; ///< The time.
+ time_t _epoch; ///< The time.
std::string_view _fmt; ///< Data format.
/** Constructor.
@@ -83,7 +83,7 @@ FirstOfConverter(T &&t) {
/// All arguments must be convertible to @c std::string_view.
template <typename... Args>
std::string_view
-FirstOf(Args &&... args) {
+FirstOf(Args &&...args) {
std::array<std::string_view, sizeof...(args)> strings{{detail::FirstOfConverter(args)...}};
for (auto &s : strings) {
if (!s.empty())
@@ -143,7 +143,7 @@ SubText<Args...>::operator!() const {
*/
template <typename... Args>
SubText<Args...>
-If(bool flag, TextView const &fmt, Args &&... args) {
+If(bool flag, TextView const &fmt, Args &&...args) {
return SubText<Args...>(flag ? fmt : TextView{}, std::forward_as_tuple(args...));
}
@@ -220,7 +220,7 @@ Optional(TextView fmt, ARG &&arg) {
* @endcode
*/
struct UnHex {
- UnHex(MemSpan<void const> const& span) : _span(span) {}
+ UnHex(MemSpan<void const> const &span) : _span(span) {}
MemSpan<void const> _span; ///< Source span.
};
} // namespace bwf
@@ -254,7 +254,7 @@ BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::Errno const
*/
BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::Date const &date);
-BufferWriter &bwformat(BufferWriter &w, bwf::Spec const& spec, bwf::UnHex const& obj);
+BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::UnHex const &obj);
/** Output a nested formatted string.
*
diff --git a/code/include/swoc/bwf_fwd.h b/code/include/swoc/bwf_fwd.h
index 4cfcf81..e9039a6 100644
--- a/code/include/swoc/bwf_fwd.h
+++ b/code/include/swoc/bwf_fwd.h
@@ -17,11 +17,9 @@ class BufferWriter;
class FixedBufferWriter;
template <std::size_t N> class LocalBufferWriter;
-template <typename... Args>
-std::string & bwprint_v(std::string &s, TextView fmt, std::tuple<Args...> const &args);
+template <typename... Args> std::string &bwprint_v(std::string &s, TextView fmt, std::tuple<Args...> const &args);
-template <typename... Args>
-std::string & bwprint(std::string &s, TextView fmt, Args &&... args);
+template <typename... Args> std::string &bwprint(std::string &s, TextView fmt, Args &&...args);
namespace bwf {
struct Spec;
@@ -29,4 +27,4 @@ struct Format;
class NameBinding;
class ArgPack;
} // namespace bwf
-}} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/include/swoc/bwf_ip.h b/code/include/swoc/bwf_ip.h
index 82ab7af..9b70fb2 100644
--- a/code/include/swoc/bwf_ip.h
+++ b/code/include/swoc/bwf_ip.h
@@ -26,11 +26,13 @@ BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, sockaddr const *a
/// codes are handled so it's ugly to split the code base on family. Instead we depend on
/// @a sa_family being set correctly.
-inline BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, sockaddr_in const *addr) {
- return bwformat(w,spec,reinterpret_cast<sockaddr const*>(addr));
+inline BufferWriter &
+bwformat(BufferWriter &w, bwf::Spec const &spec, sockaddr_in const *addr) {
+ return bwformat(w, spec, reinterpret_cast<sockaddr const *>(addr));
}
-inline BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, sockaddr_in6 const *addr) {
- return bwformat(w,spec,reinterpret_cast<sockaddr const*>(addr));
+inline BufferWriter &
+bwformat(BufferWriter &w, bwf::Spec const &spec, sockaddr_in6 const *addr) {
+ return bwformat(w, spec, reinterpret_cast<sockaddr const *>(addr));
}
/// @}
diff --git a/code/include/swoc/bwf_std.h b/code/include/swoc/bwf_std.h
index 24bd000..bf26ecf 100644
--- a/code/include/swoc/bwf_std.h
+++ b/code/include/swoc/bwf_std.h
@@ -37,22 +37,20 @@ bwformat(BufferWriter &w, bwf::Spec const & /* spec */, std::bitset<N> const &bi
template <typename Rep, typename Period>
BufferWriter &
-bwformat(BufferWriter &w, bwf::Spec const &spec, std::chrono::duration<Rep, Period> const &d)
-{
+bwformat(BufferWriter &w, bwf::Spec const &spec, std::chrono::duration<Rep, Period> const &d) {
return bwformat(w, spec, d.count());
}
template <typename Clock, typename Duration>
BufferWriter &
-bwformat(BufferWriter &w, bwf::Spec const &spec, std::chrono::time_point<Clock, Duration> const &t)
-{
+bwformat(BufferWriter &w, bwf::Spec const &spec, std::chrono::time_point<Clock, Duration> const &t) {
return bwformat(w, spec, t.time_since_epoch());
}
inline BufferWriter &
-bwformat(BufferWriter &w, bwf::Spec const& spec, std::exception const& e) {
+bwformat(BufferWriter &w, bwf::Spec const &spec, std::exception const &e) {
w.write("Exception - "_tv);
return bwformat(w, spec, e.what());
}
-}} // end namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/include/swoc/swoc_file.h b/code/include/swoc/swoc_file.h
index 91a25bc..3ce23c6 100644
--- a/code/include/swoc/swoc_file.h
+++ b/code/include/swoc/swoc_file.h
@@ -24,8 +24,16 @@ namespace file {
using file_time_type = std::chrono::system_clock::time_point;
enum class file_type : signed char {
- none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3,
- block = 4, character = 5, fifo = 6, socket = 7, unknown = 8
+ none = 0,
+ not_found = -1,
+ regular = 1,
+ directory = 2,
+ symlink = 3,
+ block = 4,
+ character = 5,
+ fifo = 6,
+ socket = 7,
+ unknown = 8
};
/// Invalid file descriptor.
@@ -52,16 +60,26 @@ struct unique_fd {
*
* Ownership is from from @Wa that to @a this.
*/
- unique_fd(self_type && that) : _fd(that._fd) { that._fd = NO_FD; }
+ unique_fd(self_type &&that) : _fd(that._fd) { that._fd = NO_FD; }
/// Close the file dscriptor.
- ~unique_fd() { if (_fd != NO_FD) { ::close(_fd); _fd = NO_FD; }; }
+ ~unique_fd() {
+ if (_fd != NO_FD) {
+ ::close(_fd);
+ _fd = NO_FD;
+ };
+ }
/** Release ownership of the file descriptor.
*
* @return The file descriptor.
*/
- int release() { auto zret = _fd; _fd = NO_FD; return zret; }
+ int
+ release() {
+ auto zret = _fd;
+ _fd = NO_FD;
+ return zret;
+ }
/// Implicitly convert to file descriptor.
operator int() const { return _fd; }
@@ -95,7 +113,7 @@ public:
path(std::string_view src);
/// Construct with a copy of @a p.
- path(std::string const& p);
+ path(std::string const &p);
/// Move from an existing string
path(std::string &&that);
@@ -162,7 +180,7 @@ public:
* @param n Number of bytes to reserve.
* @return @a this.
*/
- self_type & reserve(size_t n);
+ self_type &reserve(size_t n);
/// A view of the path.
swoc::TextView view() const;
@@ -288,8 +306,8 @@ bool create_directories(const path &p, std::error_code &ec, mode_t mode = 0775)
* @param to Destination file.
* @param ec Error code return.
* @return @c true if @a from was copied, @c false on error.
-*
-* @note Not fully implemented.
+ *
+ * @note Not fully implemented.
*/
bool copy(const path &from, const path &to, std::error_code &ec);
@@ -319,7 +337,7 @@ file_time_type last_write_time(file_status const &fs);
* @param p Path to target.
* @return Time of last modification, or @c file_time_type::min() on error.
*/
-file_time_type last_write_time(path const& p, std::error_code &ec);
+file_time_type last_write_time(path const &p, std::error_code &ec);
/// @return The access time for @a fs.
file_time_type access_time(file_status const &fs);
@@ -446,9 +464,15 @@ operator/(path &&lhs, std::string_view rhs) {
}
// Can remove "enum" after the function @c file_type is removed.
-inline enum file_type file_status::type() const { return _type; }
+inline enum file_type
+file_status::type() const {
+ return _type;
+}
-inline mode_t file_status::mode() const { return _stat.st_mode; }
+inline mode_t
+file_status::mode() const {
+ return _stat.st_mode;
+}
inline bool
is_char_device(const file_status &fs) {
diff --git a/code/include/swoc/swoc_meta.h b/code/include/swoc/swoc_meta.h
index 796095a..0d987b2 100644
--- a/code/include/swoc/swoc_meta.h
+++ b/code/include/swoc/swoc_meta.h
@@ -165,7 +165,9 @@ eraser(U &&u) -> U {
* }, v);
* @endcode
*/
-template <typename... Args> struct vary : public Args... { using Args::operator()...; };
+template <typename... Args> struct vary : public Args... {
+ using Args::operator()...;
+};
/// Template argument deduction guide (C++17 required).
template <typename... Args> vary(Args...) -> vary<Args...>;
diff --git a/code/src/ArenaWriter.cc b/code/src/ArenaWriter.cc
index e165df2..c25265e 100644
--- a/code/src/ArenaWriter.cc
+++ b/code/src/ArenaWriter.cc
@@ -44,5 +44,4 @@ ArenaWriter::realloc(size_t n) {
memcpy(_buffer, text.data(), text.size());
}
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/src/Errata.cc b/code/src/Errata.cc
index 036c9b4..3b78c89 100644
--- a/code/src/Errata.cc
+++ b/code/src/Errata.cc
@@ -29,7 +29,7 @@ string_view
Errata::Data::localize(string_view src) {
auto span = _arena.alloc(src.size()).rebind<char>();
memcpy(span.data(), src.data(), src.size());
- return { span.data(), span.size() };
+ return {span.data(), span.size()};
}
/* ----------------------------------------------------------------------- */
@@ -40,7 +40,9 @@ Errata::Severity Errata::FAILURE_SEVERITY(2);
Errata::Severity Errata::FILTER_SEVERITY(0);
/// Default set of severity names.
-std::array<swoc::TextView, 3> Severity_Names{{"Info", "Warning", "Error"}};
+std::array<swoc::TextView, 3> Severity_Names{
+ {"Info", "Warning", "Error"}
+};
swoc::MemSpan<TextView const> Errata::SEVERITY_NAMES{Severity_Names.data(), Severity_Names.size()};
@@ -48,7 +50,7 @@ Errata::~Errata() {
this->sink();
}
-Errata&
+Errata &
Errata::sink() {
if (_data) {
for (auto &f : Sink_List) {
@@ -93,7 +95,7 @@ Errata::note_s(std::optional<Severity> severity, std::string_view text) {
Errata &
Errata::note_localized(std::string_view const &text, std::optional<Severity> severity) {
- auto d = this->data();
+ auto d = this->data();
auto *n = d->_arena.make<Annotation>(text, severity);
d->_notes.append(n);
return *this;
@@ -107,7 +109,7 @@ Errata::alloc(size_t n) {
Errata &
Errata::note(const self_type &that) {
if (that._data) {
- auto d = this->data();
+ auto d = this->data();
if (that.has_severity()) {
this->update(that.severity());
}
@@ -118,8 +120,9 @@ Errata::note(const self_type &that) {
return *this;
}
-auto Errata::update(Severity severity) -> self_type & {
- if (! _data || ! _data->_severity.has_value() || _data->_severity.value() < severity) {
+auto
+Errata::update(Severity severity) -> self_type & {
+ if (!_data || !_data->_severity.has_value() || _data->_severity.value() < severity) {
this->assign(severity);
}
return *this;
@@ -153,16 +156,13 @@ bwformat(BufferWriter &bw, bwf::Spec const &, Errata const &errata) {
}
bool trailing_p = false;
- auto glue = errata.annotation_glue_text();
- auto a_s_glue = errata.annotation_severity_glue_text();
- auto id_txt = errata.indent_text();
+ auto glue = errata.annotation_glue_text();
+ auto a_s_glue = errata.annotation_severity_glue_text();
+ auto id_txt = errata.indent_text();
for (auto ¬e : errata) {
if (note.text()) {
- bw.print("{}{}{}{}"
- , swoc::bwf::If(trailing_p, "{}", glue)
- , swoc::bwf::Pattern{int(note.level()), id_txt}
- , swoc::bwf::If(note.has_severity(), "{}{}", note.severity(), a_s_glue)
- , note.text());
+ bw.print("{}{}{}{}", swoc::bwf::If(trailing_p, "{}", glue), swoc::bwf::Pattern{int(note.level()), id_txt},
+ swoc::bwf::If(note.has_severity(), "{}{}", note.severity(), a_s_glue), note.text());
trailing_p = true;
}
}
@@ -185,5 +185,4 @@ operator<<(std::ostream &os, Errata const &err) {
return err.write(os);
}
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/src/MemArena.cc b/code/src/MemArena.cc
index 451169f..54bdbdd 100644
--- a/code/src/MemArena.cc
+++ b/code/src/MemArena.cc
@@ -10,7 +10,7 @@
namespace swoc { inline namespace SWOC_VERSION_NS {
-void (*MemArena::destroyer)(MemArena*) = std::destroy_at<MemArena>;
+void (*MemArena::destroyer)(MemArena *) = std::destroy_at<MemArena>;
inline bool
MemArena::Block::satisfies(size_t n, size_t align) const {
@@ -34,8 +34,8 @@ MemArena::MemArena(MemSpan<void> static_block) {
// Need to break these out because the default implementation doesn't clear the
// integral values in @a that.
-MemArena::MemArena(swoc::MemArena::self_type &&that)
- noexcept : _active_allocated(that._active_allocated),
+MemArena::MemArena(swoc::MemArena::self_type &&that) noexcept
+ : _active_allocated(that._active_allocated),
_active_reserved(that._active_reserved),
_frozen_allocated(that._frozen_allocated),
_frozen_reserved(that._frozen_reserved),
@@ -57,7 +57,7 @@ MemArena::construct_self_contained(size_t n) {
}
MemArena &
-MemArena::operator=(swoc::MemArena::self_type &&that) noexcept {
+MemArena::operator=(swoc::MemArena::self_type &&that) noexcept {
this->clear();
std::swap(_active_allocated, that._active_allocated);
std::swap(_active_reserved, that._active_reserved);
@@ -94,7 +94,7 @@ MemArena::make_block(size_t n) {
// Allocate space for the Block instance and the request memory and construct a Block at the front.
// In theory this could use ::operator new(n) but this causes a size mismatch during ::operator delete.
// Easier to use malloc and override @c delete.
- auto free_space = n - sizeof(Block);
+ auto free_space = n - sizeof(Block);
_active_reserved += free_space;
return new (::malloc(n)) Block(free_space);
}
@@ -103,8 +103,8 @@ MemSpan<void>
MemArena::alloc(size_t n, size_t align) {
MemSpan<void> zret;
this->require(n, align);
- auto block = _active.head();
- zret = block->alloc(n, align);
+ auto block = _active.head();
+ zret = block->alloc(n, align);
_active_allocated += n;
// If this block is now full, move it to the back.
if (block->is_full() && block != _active.tail()) {
@@ -159,7 +159,7 @@ MemArena::require(size_t n, size_t align) {
spot = _active.end();
} else {
++spot;
-}
+ }
}
if (spot == _active.end()) { // no block has enough free space
block = this->make_block(n); // assuming a new block is sufficiently aligned.
@@ -181,7 +181,7 @@ MemArena::destroy_active() {
.apply([=](Block *b) {
if (b != sb) {
delete b;
-}
+ }
})
.clear();
}
@@ -193,7 +193,7 @@ MemArena::destroy_frozen() {
.apply([=](Block *b) {
if (b != sb) {
delete b;
-}
+ }
})
.clear();
}
@@ -233,14 +233,14 @@ MemArena::~MemArena() {
bf = bf->_link._next;
if (b != sb) {
delete b;
-}
+ }
}
while (ba) {
Block *b = ba;
ba = ba->_link._next;
if (b != sb) {
delete b;
-}
+ }
}
}
@@ -259,5 +259,4 @@ MemArena::do_is_equal(std::pmr::memory_resource const &that) const noexcept {
}
#endif
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/src/RBTree.cc b/code/src/RBTree.cc
index 7e708d5..1697284 100644
--- a/code/src/RBTree.cc
+++ b/code/src/RBTree.cc
@@ -343,11 +343,9 @@ RBNode::left_most_descendant() const -> self_type * {
const self_type *n = this;
while (n->_left) {
n = n->_left;
-}
+ }
return const_cast<self_type *>(n);
}
-} // namespace detail
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}}} // namespace swoc::SWOC_VERSION_NS::detail
diff --git a/code/src/TextView.cc b/code/src/TextView.cc
index f8da111..4c7710d 100644
--- a/code/src/TextView.cc
+++ b/code/src/TextView.cc
@@ -80,7 +80,7 @@ svtou(TextView src, TextView *out, int base) {
}
if (src.ltrim_if(&isspace).size()) {
auto origin = src.data();
- int8_t v = 0;
+ int8_t v = 0;
// If base is 0, it wasn't specified - check for standard base prefixes
if (0 == base) {
base = 10;
@@ -154,8 +154,8 @@ svtod(swoc::TextView text, swoc::TextView *parsed) {
if (e & 1) {
zret *= scale;
}
- scale *= scale;
- e >>= 1;
+ scale *= scale;
+ e >>= 1;
}
return zret;
};
@@ -192,7 +192,7 @@ svtod(swoc::TextView text, swoc::TextView *parsed) {
++text;
double scale = 0.1;
while (text && isdigit(*text)) {
- frac += scale * (*text++ - '0');
+ frac += scale * (*text++ - '0');
scale /= 10.0;
}
}
@@ -220,8 +220,7 @@ svtod(swoc::TextView text, swoc::TextView *parsed) {
// Do the template instantiations.
template std::ostream &TextView::stream_write(std::ostream &, const TextView &) const;
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
namespace std {
ostream &
diff --git a/code/src/bw_format.cc b/code/src/bw_format.cc
index df53f00..de62200 100644
--- a/code/src/bw_format.cc
+++ b/code/src/bw_format.cc
@@ -95,12 +95,12 @@ Spec::parse(TextView fmt) {
if (!isxdigit(d0) || !isxdigit(d1)) {
throw std::invalid_argument("URI encoding with non-hex characters");
}
- _fill = isdigit(d0) ? d0 - '0' : tolower(d0) - 'a' + 10;
+ _fill = isdigit(d0) ? d0 - '0' : tolower(d0) - 'a' + 10;
_fill += (isdigit(d1) ? d1 - '0' : tolower(d1) - 'a' + 10) << 4;
- sz += 4;
+ sz += 4;
} else if (sz.size() > 1 && Align::NONE != (_align = align_of(sz[1]))) {
- _fill = *sz;
- sz += 2;
+ _fill = *sz;
+ sz += 2;
} else if (Align::NONE != (_align = align_of(*sz))) {
++sz;
}
@@ -312,7 +312,8 @@ namespace {
char UPPER_DIGITS[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char LOWER_DIGITS[] = "0123456789abcdefghijklmnopqrstuvwxyz";
static const std::array<uint64_t, 11> POWERS_OF_TEN = {
- {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000}};
+ {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000}
+};
} // namespace
/// Templated radix based conversions. Only a small number of radix are
@@ -326,8 +327,8 @@ To_Radix(uintmax_t n, char *buff, size_t width, char *digits) {
char *out = buff + width;
if (n) {
while (n) {
- *--out = digits[n % RADIX];
- n /= RADIX;
+ *--out = digits[n % RADIX];
+ n /= RADIX;
}
} else {
*--out = '0';
@@ -531,9 +532,9 @@ Format_Float(BufferWriter &w, Spec const &spec, double f, bool negative_p) {
}
static constexpr char dec = '.';
- double frac = NAN;
- size_t l = 0;
- size_t r = 0;
+ double frac = NAN;
+ size_t l = 0;
+ size_t r = 0;
char whole[std::numeric_limits<double>::digits10 + 1];
char fraction[std::numeric_limits<double>::digits10 + 1];
char neg = 0;
@@ -630,7 +631,7 @@ Format::Format(TextView fmt) {
bool
Format::is_literal() const {
- for (auto const& spec : _items) {
+ for (auto const &spec : _items) {
if (Spec::LITERAL_TYPE != spec._type) {
return false;
}
@@ -712,14 +713,14 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::HexDump const &hex) {
BufferWriter &
bwformat(BufferWriter &w, bwf::Spec const &spec, MemSpan<void const> const &span) {
if ('x' == spec._type || 'X' == spec._type) {
- const char *digits = ('X' == spec._type) ? bwf::UPPER_DIGITS : bwf::LOWER_DIGITS;
+ const char *digits = ('X' == spec._type) ? bwf::UPPER_DIGITS : bwf::LOWER_DIGITS;
size_t block = spec._prec > 0 ? spec._prec : span.size();
TextView view{span.rebind<char const>()};
bool space_p = false;
while (view) {
if (space_p) {
w.write(' ');
-}
+ }
space_p = true;
if (spec._radix_lead_p) {
w.write('0').write(digits[33]);
@@ -743,142 +744,77 @@ namespace {
// Hand rolled, might not be totally compliant everywhere, but probably close
// enough. The long string will be locally accurate. Clang requires the double
// braces. Why, Turing only knows.
-static const std::array<std::string_view, 134> ERRNO_SHORT_NAME = {{
- "SUCCESS",
- "EPERM",
- "ENOENT",
- "ESRCH",
- "EINTR",
- "EIO",
- "ENXIO",
- "E2BIG ",
- "ENOEXEC",
- "EBADF",
- "ECHILD",
- "EAGAIN",
- "ENOMEM",
- "EACCES",
- "EFAULT",
- "ENOTBLK",
- "EBUSY",
- "EEXIST",
- "EXDEV",
- "ENODEV",
- "ENOTDIR",
- "EISDIR",
- "EINVAL",
- "ENFILE",
- "EMFILE",
- "ENOTTY",
- "ETXTBSY",
- "EFBIG",
- "ENOSPC",
- "ESPIPE",
- "EROFS",
- "EMLINK",
- "EPIPE",
- "EDOM",
- "ERANGE",
- "EDEADLK",
- "ENAMETOOLONG",
- "ENOLCK",
- "ENOSYS",
- "ENOTEMPTY",
- "ELOOP",
- "EWOULDBLOCK",
- "ENOMSG",
- "EIDRM",
- "ECHRNG",
- "EL2NSYNC",
- "EL3HLT",
- "EL3RST",
- "ELNRNG",
- "EUNATCH",
- "ENOCSI",
- "EL2HTL",
- "EBADE",
- "EBADR",
- "EXFULL",
- "ENOANO",
- "EBADRQC",
- "EBADSLT",
- "EDEADLOCK",
- "EBFONT",
- "ENOSTR",
- "ENODATA",
- "ETIME",
- "ENOSR",
- "ENONET",
- "ENOPKG",
- "EREMOTE",
- "ENOLINK",
- "EADV",
- "ESRMNT",
- "ECOMM",
- "EPROTO",
- "EMULTIHOP",
- "EDOTDOT",
- "EBADMSG",
- "EOVERFLOW",
- "ENOTUNIQ",
- "EBADFD",
- "EREMCHG",
- "ELIBACC",
- "ELIBBAD",
- "ELIBSCN",
- "ELIBMAX",
- "ELIBEXEC",
- "EILSEQ",
- "ERESTART",
- "ESTRPIPE",
- "EUSERS",
- "ENOTSOCK",
- "EDESTADDRREQ",
- "EMSGSIZE",
- "EPROTOTYPE",
- "ENOPROTOOPT",
- "EPROTONOSUPPORT",
- "ESOCKTNOSUPPORT",
- "EOPNOTSUPP",
- "EPFNOSUPPORT",
- "EAFNOSUPPORT",
- "EADDRINUSE",
- "EADDRNOTAVAIL",
- "ENETDOWN",
- "ENETUNREACH",
- "ENETRESET",
- "ECONNABORTED",
- "ECONNRESET",
- "ENOBUFS",
- "EISCONN",
- "ENOTCONN",
- "ESHUTDOWN",
- "ETOOMANYREFS",
- "ETIMEDOUT",
- "ECONNREFUSED",
- "EHOSTDOWN",
- "EHOSTUNREACH",
- "EALREADY",
- "EINPROGRESS",
- "ESTALE",
- "EUCLEAN",
- "ENOTNAM",
- "ENAVAIL",
- "EISNAM",
- "EREMOTEIO",
- "EDQUOT",
- "ENOMEDIUM",
- "EMEDIUMTYPE",
- "ECANCELED",
- "ENOKEY",
- "EKEYEXPIRED",
- "EKEYREVOKED",
- "EKEYREJECTED",
- "EOWNERDEAD",
- "ENOTRECOVERABLE",
- "ERFKILL",
- "EHWPOISON",
-}};
+static const std::array<std::string_view, 134> ERRNO_SHORT_NAME = {
+ {
+ "SUCCESS", "EPERM",
+ "ENOENT", "ESRCH",
+ "EINTR", "EIO",
+ "ENXIO", "E2BIG ",
+ "ENOEXEC", "EBADF",
+ "ECHILD", "EAGAIN",
+ "ENOMEM", "EACCES",
+ "EFAULT", "ENOTBLK",
+ "EBUSY", "EEXIST",
+ "EXDEV", "ENODEV",
+ "ENOTDIR", "EISDIR",
+ "EINVAL", "ENFILE",
+ "EMFILE", "ENOTTY",
+ "ETXTBSY", "EFBIG",
+ "ENOSPC", "ESPIPE",
+ "EROFS", "EMLINK",
+ "EPIPE", "EDOM",
+ "ERANGE", "EDEADLK",
+ "ENAMETOOLONG", "ENOLCK",
+ "ENOSYS", "ENOTEMPTY",
+ "ELOOP", "EWOULDBLOCK",
+ "ENOMSG", "EIDRM",
+ "ECHRNG", "EL2NSYNC",
+ "EL3HLT", "EL3RST",
+ "ELNRNG", "EUNATCH",
+ "ENOCSI", "EL2HTL",
+ "EBADE", "EBADR",
+ "EXFULL", "ENOANO",
+ "EBADRQC", "EBADSLT",
+ "EDEADLOCK", "EBFONT",
+ "ENOSTR", "ENODATA",
+ "ETIME", "ENOSR",
+ "ENONET", "ENOPKG",
+ "EREMOTE", "ENOLINK",
+ "EADV", "ESRMNT",
+ "ECOMM", "EPROTO",
+ "EMULTIHOP", "EDOTDOT",
+ "EBADMSG", "EOVERFLOW",
+ "ENOTUNIQ", "EBADFD",
+ "EREMCHG", "ELIBACC",
+ "ELIBBAD", "ELIBSCN",
+ "ELIBMAX", "ELIBEXEC",
+ "EILSEQ", "ERESTART",
+ "ESTRPIPE", "EUSERS",
+ "ENOTSOCK", "EDESTADDRREQ",
+ "EMSGSIZE", "EPROTOTYPE",
+ "ENOPROTOOPT", "EPROTONOSUPPORT",
+ "ESOCKTNOSUPPORT", "EOPNOTSUPP",
+ "EPFNOSUPPORT", "EAFNOSUPPORT",
+ "EADDRINUSE", "EADDRNOTAVAIL",
+ "ENETDOWN", "ENETUNREACH",
+ "ENETRESET", "ECONNABORTED",
+ "ECONNRESET", "ENOBUFS",
+ "EISCONN", "ENOTCONN",
+ "ESHUTDOWN", "ETOOMANYREFS",
+ "ETIMEDOUT", "ECONNREFUSED",
+ "EHOSTDOWN", "EHOSTUNREACH",
+ "EALREADY", "EINPROGRESS",
+ "ESTALE", "EUCLEAN",
+ "ENOTNAM", "ENAVAIL",
+ "EISNAM", "EREMOTEIO",
+ "EDQUOT", "ENOMEDIUM",
+ "EMEDIUMTYPE", "ECANCELED",
+ "ENOKEY", "EKEYEXPIRED",
+ "EKEYREVOKED", "EKEYREJECTED",
+ "EOWNERDEAD", "ENOTRECOVERABLE",
+ "ERFKILL", "EHWPOISON",
+ }
+};
static constexpr DiscreteRange<unsigned> ERRNO_RANGE{0, ERRNO_SHORT_NAME.size() - 1};
// This provides convenient safe access to the errno short name array.
auto errno_short_name = [](unsigned n) { return ERRNO_RANGE.contains(n) ? ERRNO_SHORT_NAME[n] : "Unknown"sv; };
@@ -918,7 +854,7 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::Date const &date) {
if (spec.has_numeric_type()) {
bwformat(w, spec, date._epoch);
} else {
- struct tm t{};
+ struct tm t {};
auto r = w.remaining();
size_t n{0};
// Verify @a fmt is null terminated, even outside the bounds of the view.
@@ -951,7 +887,7 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::Date const &date) {
BufferWriter &
bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::Pattern const &pattern) {
- if (! pattern._text.empty()) { // If there's no text, no point in looping.
+ if (!pattern._text.empty()) { // If there's no text, no point in looping.
auto limit = std::min<size_t>(spec._max, pattern._text.size() * pattern._n);
decltype(limit) n = 0;
while (n < limit) {
@@ -965,7 +901,7 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::Pattern const &pattern) {
BufferWriter &
bwformat(BufferWriter &w, bwf::Spec const &spec, std::error_code const &ec) {
static const auto G_CAT = &std::generic_category();
- static const auto S_CAT = &std::system_category();
+ static const auto S_CAT = &std::system_category();
// This provides convenient safe access to the errno short name array.
static const swoc::bwf::Format number_fmt{"[{}]"_sv}; // numeric value format.
@@ -986,9 +922,9 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, std::error_code const &ec) {
return w;
}
-BufferWriter&
-bwformat(BufferWriter &w, bwf::Spec const& spec, bwf::UnHex const& obj) {
- auto span { obj._span };
+BufferWriter &
+bwformat(BufferWriter &w, bwf::Spec const &spec, bwf::UnHex const &obj) {
+ auto span{obj._span};
size_t limit = spec._max;
while (span.size() >= 2 && limit--) {
auto b = svto_radix<16>(span.clip_prefix(2).rebind<char const>());
@@ -997,8 +933,7 @@ bwformat(BufferWriter &w, bwf::Spec const& spec, bwf::UnHex const& obj) {
return w;
}
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
namespace std {
ostream &
diff --git a/code/src/bw_ip_format.cc b/code/src/bw_ip_format.cc
index 53b5454..2fd66fb 100644
--- a/code/src/bw_ip_format.cc
+++ b/code/src/bw_ip_format.cc
@@ -143,10 +143,10 @@ bwformat(BufferWriter &w, Spec const &spec, sockaddr const *addr) {
}
if (bracket_p) {
w.write(']');
-}
+ }
if (port_p) {
w.write(':');
-}
+ }
}
if (port_p) {
if (local_numeric_fill_p) {
@@ -162,7 +162,7 @@ bwformat(BufferWriter &w, Spec const &spec, sockaddr const *addr) {
local_spec._min = 0;
if (addr_p || port_p) {
w.write(' ');
-}
+ }
if (spec.has_numeric_type()) {
bwformat(w, local_spec, static_cast<uintmax_t>(addr->sa_family));
} else {
@@ -211,7 +211,7 @@ bwformat(BufferWriter &w, Spec const &spec, IP6Addr const &addr) {
}
BufferWriter &
-bwformat(BufferWriter &w, Spec const &spec, IP4Srv const& srv) {
+bwformat(BufferWriter &w, Spec const &spec, IP4Srv const &srv) {
bwformat(w, spec, srv.addr());
if (srv.host_order_port()) {
w.print(":{}", srv.host_order_port());
@@ -220,7 +220,7 @@ bwformat(BufferWriter &w, Spec const &spec, IP4Srv const& srv) {
}
BufferWriter &
-bwformat(BufferWriter &w, Spec const &spec, IP6Srv const& srv) {
+bwformat(BufferWriter &w, Spec const &spec, IP6Srv const &srv) {
auto port = srv.host_order_port();
if (port) {
w.write('[');
@@ -233,9 +233,12 @@ bwformat(BufferWriter &w, Spec const &spec, IP6Srv const& srv) {
}
BufferWriter &
-bwformat(BufferWriter &w, Spec const &spec, IPSrv const& srv) {
- if (srv.is_ip4()) { bwformat(w, spec, IP4Srv(srv)); }
- else if (srv.is_ip6()) { bwformat(w, spec, IP6Srv(srv)); }
+bwformat(BufferWriter &w, Spec const &spec, IPSrv const &srv) {
+ if (srv.is_ip4()) {
+ bwformat(w, spec, IP4Srv(srv));
+ } else if (srv.is_ip6()) {
+ bwformat(w, spec, IP6Srv(srv));
+ }
return w;
}
@@ -344,14 +347,14 @@ bwformat(BufferWriter &w, Spec const &spec, IP6Range const &range) {
BufferWriter &
bwformat(BufferWriter &w, Spec const &spec, IPRange const &range) {
- return range.is(AF_INET) ? bwformat(w, spec, range.ip4()) :
- range.is(AF_INET6) ? bwformat(w, spec, range.ip6()) : w.write("*-*"_tv);
+ return range.is(AF_INET) ? bwformat(w, spec, range.ip4()) :
+ range.is(AF_INET6) ? bwformat(w, spec, range.ip6()) :
+ w.write("*-*"_tv);
}
BufferWriter &
bwformat(BufferWriter &w, Spec const &spec, IPRangeView const &rv) {
- return rv.is(AF_INET) ? bwformat(w, spec, rv.ip4()) :
- rv.is(AF_INET6) ? bwformat(w, spec, rv.ip6()) : w.write("*-*"_tv);
+ return rv.is(AF_INET) ? bwformat(w, spec, rv.ip4()) : rv.is(AF_INET6) ? bwformat(w, spec, rv.ip6()) : w.write("*-*"_tv);
}
BufferWriter &
@@ -385,5 +388,4 @@ bwformat(BufferWriter &w, Spec const &spec, IPMask const &mask) {
return bwformat(w, spec, mask.width());
}
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/src/swoc_file.cc b/code/src/swoc_file.cc
index 4ab6da6..374f4fc 100644
--- a/code/src/swoc_file.cc
+++ b/code/src/swoc_file.cc
@@ -34,7 +34,8 @@ path::relative_path() const {
return *this;
}
-auto path::filename() const -> self_type {
+auto
+path::filename() const -> self_type {
auto const idx = _path.find_last_of(SEPARATOR);
return idx == std::string::npos ? self_type(_path) : _path.substr(idx + 1);
}
@@ -57,16 +58,33 @@ path::operator/=(std::string_view that) {
return *this;
}
-void file_status::init() {
+void
+file_status::init() {
switch (_stat.st_mode & S_IFMT) {
- case S_IFREG : _type = file_type::regular; break;
- case S_IFDIR : _type = file_type::directory; break;
- case S_IFLNK : _type = file_type::symlink; break;
- case S_IFBLK : _type = file_type::block; break;
- case S_IFCHR : _type = file_type::character; break;
- case S_IFIFO : _type = file_type::fifo; break;
- case S_IFSOCK : _type = file_type::socket; break;
- default: _type = file_type::unknown; break;
+ case S_IFREG:
+ _type = file_type::regular;
+ break;
+ case S_IFDIR:
+ _type = file_type::directory;
+ break;
+ case S_IFLNK:
+ _type = file_type::symlink;
+ break;
+ case S_IFBLK:
+ _type = file_type::block;
+ break;
+ case S_IFCHR:
+ _type = file_type::character;
+ break;
+ case S_IFIFO:
+ _type = file_type::fifo;
+ break;
+ case S_IFSOCK:
+ _type = file_type::socket;
+ break;
+ default:
+ _type = file_type::unknown;
+ break;
}
}
@@ -127,7 +145,8 @@ absolute(path const &src, std::error_code &ec) {
namespace {
-inline file_time_type chrono_cast(timespec const &ts) {
+inline file_time_type
+chrono_cast(timespec const &ts) {
using namespace std::chrono;
return system_clock::time_point{duration_cast<system_clock::duration>(seconds{ts.tv_sec} + nanoseconds{ts.tv_nsec})};
}
@@ -188,7 +207,7 @@ status_time(file_status const &fs) {
}
file_time_type
-last_write_time(path const& p, std::error_code &ec) {
+last_write_time(path const &p, std::error_code &ec) {
auto fs = status(p, ec);
if (ec) {
return file_time_type::min();
@@ -202,13 +221,12 @@ is_readable(const path &p) {
}
path
-temp_directory_path()
-{
+temp_directory_path() {
/* ISO/IEC 9945 (POSIX): The path supplied by the first environment variable found in the list TMPDIR, TMP, TEMP, TEMPDIR.
* If none of these are found, "/tmp"
* */
- for ( char const * tp : { "TMPDIR", "TMP", "TEMPDIR" }) {
- if (auto v = ::getenv(tp) ; v) {
+ for (char const *tp : {"TMPDIR", "TMP", "TEMPDIR"}) {
+ if (auto v = ::getenv(tp); v) {
return path(v);
}
}
@@ -216,23 +234,21 @@ temp_directory_path()
}
path
-current_path()
-{
- char buff[PATH_MAX+1];
- if (auto p = ::getcwd(buff, sizeof(buff)) ; p) {
+current_path() {
+ char buff[PATH_MAX + 1];
+ if (auto p = ::getcwd(buff, sizeof(buff)); p) {
return path{buff};
-#if !__FreeBSD__ && ! __APPLE__ // Freakin' Apple and FreeBSD.
+#if !__FreeBSD__ && !__APPLE__ // Freakin' Apple and FreeBSD.
} else if (ERANGE == errno) {
swoc::unique_malloc<char> raw{::get_current_dir_name()};
- return path{ raw.get() };
+ return path{raw.get()};
#endif
}
return {};
}
path
-canonical(const path &p, std::error_code &ec)
-{
+canonical(const path &p, std::error_code &ec) {
if (p.empty()) {
ec = std::error_code(EINVAL, std::system_category());
return {};
@@ -240,11 +256,11 @@ canonical(const path &p, std::error_code &ec)
char buf[PATH_MAX + 1];
- if (auto rp = ::realpath(p.c_str(), buf) ; rp) {
+ if (auto rp = ::realpath(p.c_str(), buf); rp) {
return path{rp};
}
- if (auto rp = ::realpath(p.c_str(), nullptr) ; rp) {
+ if (auto rp = ::realpath(p.c_str(), nullptr); rp) {
return path{rp};
}
@@ -252,7 +268,8 @@ canonical(const path &p, std::error_code &ec)
return {};
}
-bool create_directory(const path &path, std::error_code &ec, mode_t mode) noexcept {
+bool
+create_directory(const path &path, std::error_code &ec, mode_t mode) noexcept {
if (path.empty()) {
ec = std::error_code(EINVAL, std::system_category());
return false;
@@ -274,8 +291,7 @@ bool create_directory(const path &path, std::error_code &ec, mode_t mode) noexce
}
bool
-create_directories(const path &p, std::error_code &ec, mode_t mode) noexcept
-{
+create_directories(const path &p, std::error_code &ec, mode_t mode) noexcept {
TextView text(p.string());
if (text.empty()) {
@@ -297,8 +313,8 @@ create_directories(const path &p, std::error_code &ec, mode_t mode) noexcept
path.reserve(p.string().size());
while (text) {
- auto elt = text.take_prefix_at(path::SEPARATOR);
- path /= elt;
+ auto elt = text.take_prefix_at(path::SEPARATOR);
+ path /= elt;
if (!create_directory(path, ec, mode)) {
return false;
}
@@ -308,8 +324,7 @@ create_directories(const path &p, std::error_code &ec, mode_t mode) noexcept
}
bool
-copy(const path &from, const path &to, std::error_code &ec)
-{
+copy(const path &from, const path &to, std::error_code &ec) {
static constexpr size_t BUF_SIZE = 65536;
std::error_code local_ec;
char buf[BUF_SIZE];
@@ -330,8 +345,8 @@ copy(const path &from, const path &to, std::error_code &ec)
auto src_fs = file::status(from, local_ec);
path final_to;
- if (auto fs = file::status(to, local_ec) ; !(local_ec && ENOENT == local_ec.value()) && is_dir(fs)) {
- final_to = to / from.filename();
+ if (auto fs = file::status(to, local_ec); !(local_ec && ENOENT == local_ec.value()) && is_dir(fs)) {
+ final_to = to / from.filename();
} else {
final_to = to;
}
@@ -343,7 +358,7 @@ copy(const path &from, const path &to, std::error_code &ec)
}
while (true) {
- if ( auto n = read(src_fd, span.data(), span.size()) ; n > 0 ) {
+ if (auto n = read(src_fd, span.data(), span.size()); n > 0) {
if (::write(dst_fd, span.data(), n) < n) {
ec = std::error_code(errno, std::system_category());
break;
@@ -357,15 +372,14 @@ copy(const path &from, const path &to, std::error_code &ec)
}
uintmax_t
-remove_all(const path &p, std::error_code &ec)
-{
+remove_all(const path &p, std::error_code &ec) {
// coverity TOCTOU - issue is doing stat before doing operation. Stupid complaint, ignore.
- DIR *dir = nullptr;
+ DIR *dir = nullptr;
struct dirent *entry = nullptr;
std::error_code err;
uintmax_t zret = 0;
- struct ::stat s{};
+ struct ::stat s {};
if (p.empty()) {
ec = std::error_code(EINVAL, std::system_category());
return zret;
@@ -373,7 +387,7 @@ remove_all(const path &p, std::error_code &ec)
ec = std::error_code(errno, std::system_category());
return zret;
} else if (S_ISREG(s.st_mode)) { // regular file, try to remove it!
- //coverity[toctou : SUPPRESS]
+ // coverity[toctou : SUPPRESS]
if (unlink(p.c_str()) != 0) {
ec = std::error_code(errno, std::system_category());
} else {
@@ -387,7 +401,7 @@ remove_all(const path &p, std::error_code &ec)
// Invariant - @a p is a directory.
// recursively remove nested files and directories
- //coverity[toctou : SUPPRESS]
+ // coverity[toctou : SUPPRESS]
if (nullptr == (dir = opendir(p.c_str()))) {
ec = std::error_code(errno, std::system_category());
return zret;
@@ -398,9 +412,9 @@ remove_all(const path &p, std::error_code &ec)
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
continue;
}
- child = p;
+ child = p;
child /= entry->d_name;
- zret += remove_all(child, ec);
+ zret += remove_all(child, ec);
}
if (0 != rmdir(p.c_str())) {
@@ -412,20 +426,21 @@ remove_all(const path &p, std::error_code &ec)
return zret;
}
-bool remove(path const& p, std::error_code &ec) {
+bool
+remove(path const &p, std::error_code &ec) {
// coverity TOCTOU - issue is doing stat before doing operation. Stupid complaint, ignore.
- struct ::stat fs{};
+ struct ::stat fs {};
if (p.empty()) {
ec = std::error_code(EINVAL, std::system_category());
} else if (::stat(p.c_str(), &fs) < 0) {
ec = std::error_code(errno, std::system_category());
} else if (S_ISREG(fs.st_mode)) { // regular file, try to remove it!
- //coverity[toctou : SUPPRESS]
+ // coverity[toctou : SUPPRESS]
if (unlink(p.c_str()) != 0) {
ec = std::error_code(errno, std::system_category());
}
} else if (S_ISDIR(fs.st_mode)) { // not a directory
- //coverity[toctou : SUPPRESS]
+ // coverity[toctou : SUPPRESS]
if (rmdir(p.c_str()) != 0) {
ec = std::error_code(errno, std::system_category());
}
@@ -439,10 +454,10 @@ std::string
load(const path &p, std::error_code &ec) {
std::string zret;
ec.clear();
- if (unique_fd fd(::open(p.c_str(), O_RDONLY)) ; fd < 0) {
+ if (unique_fd fd(::open(p.c_str(), O_RDONLY)); fd < 0) {
ec = std::error_code(errno, std::system_category());
} else {
- struct stat info{};
+ struct stat info {};
if (0 != ::fstat(fd, &info)) {
ec = std::error_code(errno, std::system_category());
} else {
@@ -464,5 +479,4 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, file::path const &p) {
return bwformat(w, spec, p.string());
}
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/code/src/swoc_ip.cc b/code/src/swoc_ip.cc
index e437e24..67fc9fa 100644
--- a/code/src/swoc_ip.cc
+++ b/code/src/swoc_ip.cc
@@ -99,7 +99,7 @@ IPEndpoint::assign(IPAddr const &src) {
}
IPEndpoint &
-IPEndpoint::assign(IPAddr const& addr, in_port_t port) {
+IPEndpoint::assign(IPAddr const &addr, in_port_t port) {
if (addr.is_ip4()) {
this->assign(IP4Srv(addr.ip4(), port));
} else if (addr.is_ip6()) {
@@ -307,18 +307,18 @@ IP4Addr::load(std::string_view const &text) {
while (n > 0) {
TextView parsed;
auto token = src.take_prefix_at('.');
- auto v = svtou(token, &parsed);
+ auto v = svtou(token, &parsed);
if (parsed.size() != token.size()) {
break;
}
if (src.empty()) {
if (v <= max) {
_addr += v;
- n = 0; // signal complete.
+ n = 0; // signal complete.
}
break;
- } else if (v <= std::numeric_limits<uint8_t>::max()){
- _addr += v << ( --n * 8);
+ } else if (v <= std::numeric_limits<uint8_t>::max()) {
+ _addr += v << (--n * 8);
} else {
break; // invalid.
}
@@ -326,7 +326,7 @@ IP4Addr::load(std::string_view const &text) {
}
// If there's text left, or not all the octets were filled, fail.
- if (! src.empty() || n != 0) {
+ if (!src.empty() || n != 0) {
_addr = INADDR_ANY;
return false;
}
@@ -344,7 +344,7 @@ IP4Addr::operator=(sockaddr_in const *sa) -> self_type & {
sockaddr_in *
IP4Addr::copy_to(sockaddr_in *sin) const {
- sin->sin_family = AF_INET;
+ sin->sin_family = AF_INET;
sin->sin_addr.s_addr = this->network_order();
Set_Sockaddr_Len(sin);
return sin;
@@ -370,12 +370,12 @@ IP6Addr::operator<<=(unsigned int n) {
static constexpr auto MASK = ~word_type{0};
if (n < WORD_WIDTH) {
_addr._store[MSW] <<= n;
- _addr._store[MSW] |= (_addr._store[LSW] >> (WORD_WIDTH - n)) & ~(MASK << n);
+ _addr._store[MSW] |= (_addr._store[LSW] >> (WORD_WIDTH - n)) & ~(MASK << n);
_addr._store[LSW] <<= n;
} else {
- n -= WORD_WIDTH;
- _addr._store[MSW] = _addr._store[LSW] << n;
- _addr._store[LSW] = 0;
+ n -= WORD_WIDTH;
+ _addr._store[MSW] = _addr._store[LSW] << n;
+ _addr._store[LSW] = 0;
}
return *this;
}
@@ -385,12 +385,12 @@ IP6Addr::operator>>=(unsigned int n) {
static constexpr auto MASK = ~word_type{0};
if (n < WORD_WIDTH) {
_addr._store[LSW] >>= n;
- _addr._store[LSW] |= (_addr._store[MSW] & ~(MASK << n)) << (WORD_WIDTH - n);
+ _addr._store[LSW] |= (_addr._store[MSW] & ~(MASK << n)) << (WORD_WIDTH - n);
_addr._store[MSW] >>= n;
} else {
- n -= WORD_WIDTH;
- _addr._store[LSW] = _addr._store[MSW] >> n;
- _addr._store[MSW] = 0;
+ n -= WORD_WIDTH;
+ _addr._store[LSW] = _addr._store[MSW] >> n;
+ _addr._store[MSW] = 0;
}
return *this;
}
@@ -698,8 +698,8 @@ IPMask
IPMask::mask_for(IP6Addr const &addr) {
auto cidr = IP6Addr::WIDTH;
for (unsigned idx = IP6Addr::N_QUADS; idx > 0;) {
- auto q = addr._addr._quad[IP6Addr::QUAD_IDX[--idx]];
- cidr -= IP6Addr::QUAD_WIDTH;
+ auto q = addr._addr._quad[IP6Addr::QUAD_IDX[--idx]];
+ cidr -= IP6Addr::QUAD_WIDTH;
if (q != 0) {
cidr += self_type::mask_for_quad(q);
break;
@@ -712,7 +712,7 @@ IP6Addr
IPMask::as_ip6() const {
static constexpr auto MASK = ~IP6Addr::word_type{0};
if (_cidr == 0) {
- return { 0, 0 };
+ return {0, 0};
} else if (_cidr <= IP6Addr::WORD_WIDTH) {
return {MASK << (IP6Addr::WORD_WIDTH - _cidr), 0};
} else if (_cidr < 2 * IP6Addr::WORD_WIDTH) {
@@ -801,9 +801,7 @@ IPSrv::load(swoc::TextView text) {
return false;
}
-
IPSrv::IPSrv(IPAddr addr, in_port_t port) : _family(addr.family()) {
-
if (addr.is_ip4()) {
_srv._ip4.assign(addr.ip4(), port);
} else if (addr.is_ip6()) {
@@ -813,7 +811,7 @@ IPSrv::IPSrv(IPAddr addr, in_port_t port) : _family(addr.family()) {
}
}
-IPSrv::IPSrv(IPEndpoint const& ep) {
+IPSrv::IPSrv(IPEndpoint const &ep) {
if (ep.is_ip4()) {
_family = _srv._ip4.family();
_srv._ip4.assign(&ep.sa4);
@@ -823,7 +821,8 @@ IPSrv::IPSrv(IPEndpoint const& ep) {
}
}
-auto IPSrv::assign(const sockaddr *sa) -> self_type & {
+auto
+IPSrv::assign(const sockaddr *sa) -> self_type & {
if (AF_INET == sa->sa_family) {
_family = AF_INET;
_srv._ip4.assign(reinterpret_cast<sockaddr_in const *>(sa));
@@ -838,12 +837,12 @@ auto IPSrv::assign(const sockaddr *sa) -> self_type & {
bool
IP4Net::load(TextView text) {
- if (auto mask_text = text.split_suffix_at('/') ; !mask_text.empty() ) {
+ if (auto mask_text = text.split_suffix_at('/'); !mask_text.empty()) {
IPMask mask;
bool mask_p = mask.load(mask_text);
if (IP4Addr addr; addr.load(text)) {
if (!mask_p) {
- if (IP4Addr m ; m.load(mask_text)) {
+ if (IP4Addr m; m.load(mask_text)) {
mask = IPMask::mask_for(m);
mask_p = (m == mask.as_ip4()); // must be an actual mask like address.
}
@@ -861,12 +860,12 @@ IP4Net::load(TextView text) {
bool
IP6Net::load(TextView text) {
- if (auto mask_text = text.split_suffix_at('/') ; !mask_text.empty() ) {
+ if (auto mask_text = text.split_suffix_at('/'); !mask_text.empty()) {
IPMask mask;
bool mask_p = mask.load(mask_text);
if (IP6Addr addr; addr.load(text)) {
if (!mask_p) {
- if (IP6Addr m ; m.load(mask_text)) {
+ if (IP6Addr m; m.load(mask_text)) {
mask = IPMask::mask_for(m);
mask_p = (m == mask.as_ip6()); // must be an actual mask like address.
}
@@ -884,13 +883,13 @@ IP6Net::load(TextView text) {
bool
IPNet::load(TextView text) {
- if ( auto mask_text = text.split_suffix_at('/') ; !mask_text.empty() ) {
+ if (auto mask_text = text.split_suffix_at('/'); !mask_text.empty()) {
IPMask mask;
bool mask_p = mask.load(mask_text);
- if (IP6Addr a6 ; a6.load(text)) { // load the address
+ if (IP6Addr a6; a6.load(text)) { // load the address
if (!mask_p) {
- if (IP6Addr m ; m.load(mask_text)) {
+ if (IP6Addr m; m.load(mask_text)) {
mask = IPMask::mask_for(m);
mask_p = (m == mask.as_ip6()); // must be an actual mask like address.
}
@@ -899,9 +898,9 @@ IPNet::load(TextView text) {
this->assign(a6, mask);
return true;
}
- } else if (IP4Addr a4 ; a4.load(text)) {
+ } else if (IP4Addr a4; a4.load(text)) {
if (!mask_p) {
- if (IP4Addr m ; m.load(mask_text)) {
+ if (IP4Addr m; m.load(mask_text)) {
mask = IPMask::mask_for(m);
mask_p = (m == mask.as_ip4()); // must be an actual mask like address.
}
@@ -931,9 +930,9 @@ IP4Range::assign(swoc::IP4Addr const &addr, swoc::IPMask const &mask) {
} else {
_min = _max = addr;
if (mask.width() < 32) {
- in_addr_t bits = INADDR_BROADCAST << (32 - mask.width());
- _min._addr &= bits;
- _max._addr |= ~bits;
+ in_addr_t bits = INADDR_BROADCAST << (32 - mask.width());
+ _min._addr &= bits;
+ _max._addr |= ~bits;
}
}
return *this;
@@ -1000,8 +999,9 @@ IP4Range::NetSource::operator++() -> self_type & {
return *this;
}
-auto IP4Range::NetSource::operator++(int) -> self_type {
- auto zret { *this };
+auto
+IP4Range::NetSource::operator++(int) -> self_type {
+ auto zret{*this};
++*this;
return zret;
}
@@ -1009,8 +1009,8 @@ auto IP4Range::NetSource::operator++(int) -> self_type {
void
IP4Range::NetSource::search_wider() {
while (_cidr > 0) {
- auto m = _mask;
- m <<= 1;
+ auto m = _mask;
+ m <<= 1;
if (this->is_valid(m)) {
_mask = m;
--_cidr;
@@ -1024,7 +1024,7 @@ void
IP4Range::NetSource::search_narrower() {
while (!this->is_valid(_mask)) {
_mask._addr >>= 1;
- _mask._addr |= 1U << (IP4Addr::WIDTH - 1); // put top bit back.
+ _mask._addr |= 1U << (IP4Addr::WIDTH - 1); // put top bit back.
++_cidr;
}
}
@@ -1051,7 +1051,7 @@ IP6Range::assign(IP6Addr const &addr, IPMask const &mask) {
} else if (cidr <= 128) { // _min bytes changed, _max bytes unaffected.
_min = _max = addr;
if (cidr < 128) {
- auto bits = FULL_MASK << (128 - cidr);
+ auto bits = FULL_MASK << (128 - cidr);
_min._addr._store[1] &= bits;
_max._addr._store[1] |= ~bits;
}
@@ -1097,7 +1097,7 @@ IPRange::IPRange(IPAddr const &min, IPAddr const &max) {
bool
IPRange::load(std::string_view const &text) {
- if ( auto idx = text.find_first_of(':') ; idx != text.npos ) {
+ if (auto idx = text.find_first_of(':'); idx != text.npos) {
if (_range._ip6.load(text)) {
_family = AF_INET6;
return true;
@@ -1211,8 +1211,8 @@ IP6Range::NetSource::operator++() -> self_type & {
void
IP6Range::NetSource::search_wider() {
while (_mask.width() > 0) {
- auto m = _mask;
- m <<= 1;
+ auto m = _mask;
+ m <<= 1;
if (this->is_valid(m)) {
_mask = m;
} else {
@@ -1254,5 +1254,4 @@ IPRangeView::operator==(IPRangeView::self_type const &that) const {
return false;
}
-} // namespace SWOC_VERSION_NS
-} // namespace swoc
+}} // namespace swoc::SWOC_VERSION_NS
diff --git a/example/ex_diskstats.cc b/example/ex_diskstats.cc
index 86248c9..5899cba 100644
--- a/example/ex_diskstats.cc
+++ b/example/ex_diskstats.cc
@@ -30,19 +30,20 @@ struct DiskInfo {
std::vector<unsigned> data;
};
-int main(int, char *[]) {
+int
+main(int, char *[]) {
std::vector<DiskInfo> info;
char buffer[1024];
// Unfortunately because this isn't a regular file, @c swoc::file doesn't work.
// The input must be streamed.
- FILE * f = fopen("/proc/diskstats", "r");
+ FILE *f = fopen("/proc/diskstats", "r");
while (fgets(buffer, sizeof(buffer), f)) {
DiskInfo item;
TextView txt{buffer, strlen(buffer)};
- item.id = svtou(txt.ltrim(' ').take_prefix_at(' '));
- item.idx = svtou(txt.ltrim(' ').take_prefix_at(' '));
+ item.id = svtou(txt.ltrim(' ').take_prefix_at(' '));
+ item.idx = svtou(txt.ltrim(' ').take_prefix_at(' '));
item.name = txt.ltrim(' ').take_prefix_at(' ');
while (txt.ltrim(' ')) {
item.data.push_back(svtou(txt.take_prefix_at(' ')));
@@ -52,18 +53,20 @@ int main(int, char *[]) {
std::cout << '[';
bool comma = false;
- for ( auto const& item : info) {
+ for (auto const &item : info) {
if (comma) {
std::cout << ",";
}
- std::cout << std::endl << " " << "{" << std::endl;
- std::cout << R"( "id": )" << item.id << ',' <<std::endl;
+ std::cout << std::endl
+ << " "
+ << "{" << std::endl;
+ std::cout << R"( "id": )" << item.id << ',' << std::endl;
std::cout << R"( "index": )" << item.idx << ',' << std::endl;
std::cout << W.clear().print(R"( "name": "{}",)", item.name).write('\n');
bool first = true;
if (!item.data.empty()) {
std::cout << R"( "values": [)";
- for ( auto n : item.data) {
+ for (auto n : item.data) {
if (!first) {
std::cout << ",";
}
@@ -72,7 +75,8 @@ int main(int, char *[]) {
}
std::cout << std::endl << " ]" << std::endl;
}
- std::cout << " " << "}";
+ std::cout << " "
+ << "}";
comma = true;
}
std::cout << std::endl << ']' << std::endl;
diff --git a/example/ex_flat_space.cc b/example/ex_flat_space.cc
index 8ad26be..802dbda 100644
--- a/example/ex_flat_space.cc
+++ b/example/ex_flat_space.cc
@@ -48,7 +48,10 @@ using swoc::IPSpace;
// Temp for error messages.
std::string err_text;
-std::error_code errno_code() { return std::error_code(errno, std::system_category()); }
+std::error_code
+errno_code() {
+ return std::error_code(errno, std::system_category());
+}
/** Allocate a span of type @a T.
*
@@ -56,14 +59,16 @@ std::error_code errno_code() { return std::error_code(errno, std::system_categor
* @param n Number of elements.
* @return A @c MemSpan<T> with @a n elements.
*/
-template < typename T > MemSpan<T> span_alloc(size_t n) {
+template <typename T>
+MemSpan<T>
+span_alloc(size_t n) {
size_t bytes = sizeof(T) * n;
- return { static_cast<T*>(malloc(bytes)), n };
+ return {static_cast<T *>(malloc(bytes)), n};
}
// Array type for flat files.
// Each flat file is an instance of this, which is a wrapper over an array of its nodes.
-template < typename METRIC, typename PAYLOAD > class IPArray {
+template <typename METRIC, typename PAYLOAD> class IPArray {
public:
struct Node {
METRIC _min;
@@ -85,19 +90,25 @@ public:
*
* This will allocate memory to hold an array that mirrors the data in @a space.
*/
- IPArray(IPSpace<PAYLOAD> const& space);
+ IPArray(IPSpace<PAYLOAD> const &space);
/** Find @a addr.
*
* @param addr Search value.
* @return The node that contains @a addr, or @c nullptr if not found.
*/
- Node* find(METRIC const& addr);
+ Node *find(METRIC const &addr);
- Errata store(swoc::file::path const& path);
+ Errata store(swoc::file::path const &path);
- size_t size() const { return _nodes.size(); }
- void* data() const { return _nodes.data(); }
+ size_t
+ size() const {
+ return _nodes.size();
+ }
+ void *
+ data() const {
+ return _nodes.data();
+ }
protected:
/// Array memory.
@@ -105,13 +116,15 @@ protected:
};
// Standard binary search on a sorted array.
-template < typename METRIC, typename PAYLOAD > auto IPArray<METRIC, PAYLOAD>::find(METRIC const& addr) -> Node* {
+template <typename METRIC, typename PAYLOAD>
+auto
+IPArray<METRIC, PAYLOAD>::find(METRIC const &addr) -> Node * {
ssize_t lidx = 0;
ssize_t ridx = _nodes.count() - 1;
- while (lidx <= ridx) { // still some array left to search.
+ while (lidx <= ridx) { // still some array left to search.
auto idx = (lidx + ridx) / 2; // Look at the middle element.
- auto n = _nodes.data() + idx;
+ auto n = _nodes.data() + idx;
if (addr < n->_min) { // target is to the left
ridx = idx - 1;
} else if (addr > n->_max) { // target is to the right
@@ -123,21 +136,22 @@ template < typename METRIC, typename PAYLOAD > auto IPArray<METRIC, PAYLOAD>::fi
return nullptr; // dropped out of the loop -> not found.
}
-template < typename METRIC, typename PAYLOAD > IPArray<METRIC, PAYLOAD>::IPArray(IPSpace<PAYLOAD> const& space) {
- auto n = space.count(METRIC::AF_value);
- _nodes = { span_alloc<Node>(n) }; // In memory array.
+template <typename METRIC, typename PAYLOAD> IPArray<METRIC, PAYLOAD>::IPArray(IPSpace<PAYLOAD> const &space) {
+ auto n = space.count(METRIC::AF_value);
+ _nodes = {span_alloc<Node>(n)}; // In memory array.
auto node = _nodes.data();
// Update the array with all IPv4 ranges.
- for ( auto spot = space.begin(METRIC::AF_value), limit = space.end(METRIC::AF_value) ; spot != limit ; ++spot, ++node ) {
- auto && [ range, payload ] { *spot };
- node->_min = static_cast<METRIC>(range.min());
- node->_max = static_cast<METRIC>(range.max());
+ for (auto spot = space.begin(METRIC::AF_value), limit = space.end(METRIC::AF_value); spot != limit; ++spot, ++node) {
+ auto &&[range, payload]{*spot};
+ node->_min = static_cast<METRIC>(range.min());
+ node->_max = static_cast<METRIC>(range.max());
node->_payload = payload;
}
-
}
-template <typename METRIC, typename PAYLOAD> Errata IPArray<METRIC, PAYLOAD>::store(swoc::file::path const &path) {
+template <typename METRIC, typename PAYLOAD>
+Errata
+IPArray<METRIC, PAYLOAD>::store(swoc::file::path const &path) {
auto fd = ::open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0644);
if (fd >= 0) {
auto written = ::write(fd, _nodes.data(), _nodes.size());
@@ -155,10 +169,11 @@ using A4 = IPArray<IP4Addr, unsigned>;
using A6 = IPArray<IP6Addr, unsigned>;
// Load the CSV file @a src into @a space.
-void build(IPSpace<unsigned> & space, swoc::file::path src) {
+void
+build(IPSpace<unsigned> &space, swoc::file::path src) {
std::error_code ec;
auto content = swoc::file::load(src, ec);
- TextView text { content };
+ TextView text{content};
while (text) {
auto line = text.take_prefix_at('\n');
if ('#' == *line) {
@@ -170,12 +185,13 @@ void build(IPSpace<unsigned> & space, swoc::file::path src) {
}
}
-int main(int argc, char const *argv[]) {
+int
+main(int argc, char const *argv[]) {
swoc::file::path path_4{"/opt/ip4.mem"};
swoc::file::path path_6{"/tmp/ip6.mem"};
swoc::file::path src;
- MemSpan<char const*> args{argv, size_t(argc)};
+ MemSpan<char const *> args{argv, size_t(argc)};
args.remove_prefix(1); // drop executable name.
if (args.empty()) {
exit(0); // nothing to do.
@@ -185,15 +201,15 @@ int main(int argc, char const *argv[]) {
if (0 == strcasecmp("--build"_tv, args.front())) {
IPSpace<unsigned int> space;
args.remove_prefix(1);
- while (!args.empty() && ! TextView(std::string_view(args[0])).starts_with("-")) {
+ while (!args.empty() && !TextView(std::string_view(args[0])).starts_with("-")) {
build(space, swoc::file::path(args[0]));
args.remove_prefix(1);
}
- if ( auto errata = A4(space).store(path_4) ; !errata.is_ok() ) {
+ if (auto errata = A4(space).store(path_4); !errata.is_ok()) {
std::cerr << errata << std::endl;
exit(1);
}
- if (auto errata = A6(space).store(path_6) ; !errata.is_ok()) {
+ if (auto errata = A6(space).store(path_6); !errata.is_ok()) {
std::cerr << errata << std::endl;
exit(1);
}
@@ -228,18 +244,19 @@ int main(int argc, char const *argv[]) {
// map the flat files in to memory.
auto fsize = swoc::file::file_size(stat_4);
- auto fd_4 = ::open(path_4.c_str(), O_RDONLY);
- MemSpan<void> mem4 { ::mmap(nullptr, fsize, PROT_READ, MAP_PRIVATE, fd_4, 0), size_t(fsize) };
- A4 a_4 { mem4.rebind<A4::Node>() };
+ auto fd_4 = ::open(path_4.c_str(), O_RDONLY);
+ MemSpan<void> mem4{::mmap(nullptr, fsize, PROT_READ, MAP_PRIVATE, fd_4, 0), size_t(fsize)};
+ A4 a_4{mem4.rebind<A4::Node>()};
- fsize = swoc::file::file_size(stat_6);
+ fsize = swoc::file::file_size(stat_6);
auto fd_6 = ::open(path_6.c_str(), O_RDONLY);
- MemSpan<void> mem6 { ::mmap(nullptr, fsize, PROT_READ, MAP_PRIVATE, fd_6, 0), size_t(fsize) };
- A6 a_6 { mem6.rebind<A6::Node>() };
+ MemSpan<void> mem6{::mmap(nullptr, fsize, PROT_READ, MAP_PRIVATE, fd_6, 0), size_t(fsize)};
+ A6 a_6{mem6.rebind<A6::Node>()};
- std::cout << swoc::bwprint(err_text, "Mapped files in {} us\n", std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - t0).count());
+ std::cout << swoc::bwprint(err_text, "Mapped files in {} us\n",
+ std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - t0).count());
- #if 0
+#if 0
// performance testing.
t0 = std::chrono::system_clock::now();
auto step = ~0U / 10000000;
@@ -250,10 +267,10 @@ int main(int argc, char const *argv[]) {
}
auto delta = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now() - t0);
std::cout << swoc::bwprint(err_text, "Searched files in {} ns - {} ns / lookup\n", delta.count(), delta.count() / 10000000);
- #endif
+#endif
// Now the in memory flat files can be searched.
- while (! args.empty()) {
+ while (!args.empty()) {
IPAddr addr;
if (addr.load(args.front())) {
if (addr.is_ip4()) {
diff --git a/example/ex_host_file.cc b/example/ex_host_file.cc
index 709b4f5..b1a1bcb 100644
--- a/example/ex_host_file.cc
+++ b/example/ex_host_file.cc
@@ -32,7 +32,7 @@ using V6Lexicon = swoc::Lexicon<IP6Addr>;
// --------------------------------------------------
-static constexpr TextView HOST_FILE { R"(
+static constexpr TextView HOST_FILE{R"(
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
@@ -52,7 +52,8 @@ static constexpr TextView HOST_FILE { R"(
192.168.2.32 edge-ts
)"};
-int main(int, char *[]) {
+int
+main(int, char *[]) {
V4Lexicon hosts_ipv4;
V6Lexicon hosts_ipv6;
@@ -63,7 +64,7 @@ int main(int, char *[]) {
continue;
}
auto addr_token = line.take_prefix_if(&isspace);
- if (IPAddr addr ; addr.load(addr_token)) {
+ if (IPAddr addr; addr.load(addr_token)) {
while (line.ltrim_if(&isspace)) {
auto host = line.take_prefix_if(&isspace);
if (addr.is_ip4()) {
@@ -80,10 +81,10 @@ int main(int, char *[]) {
std::cout << swoc::detail::what("{} -> {}\n", IP4Addr("192.168.2.3"), hosts_ipv4[IP4Addr("192.168.2.3")]);
std::cout << "Table dump by name" << std::endl;
- for ( auto const & item : hosts_ipv4.by_names()) {
+ for (auto const &item : hosts_ipv4.by_names()) {
std::cout << swoc::detail::what("{} -> {}\n", std::get<V4Lexicon::NAME_IDX>(item), std::get<V4Lexicon::VALUE_IDX>(item));
}
- for ( auto const & item : hosts_ipv6.by_names()) {
+ for (auto const &item : hosts_ipv6.by_names()) {
std::cout << swoc::detail::what("{} -> {}\n", std::get<V4Lexicon::NAME_IDX>(item), std::get<V4Lexicon::VALUE_IDX>(item));
}
diff --git a/example/ex_lru_cache.cc b/example/ex_lru_cache.cc
index f141175..436152b 100644
--- a/example/ex_lru_cache.cc
+++ b/example/ex_lru_cache.cc
@@ -35,23 +35,27 @@ using swoc::IPAddr;
using time_point = std::chrono::time_point<std::chrono::system_clock>;
-template < typename K, typename V > class LRU {
+template <typename K, typename V> class LRU {
using self_type = LRU;
+
public:
LRU() = default;
- self_type & insert(K const& key, V && value);
+ 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(); }
+ self_type &erase(K const &key);
+ V retrieve(K const &key) const;
+ size_t
+ count() const {
+ return _table.count();
+ }
protected:
struct Item {
using self_type = Item;
struct Links {
- self_type * _next = nullptr;
- self_type * _prev = nullptr;
+ self_type *_next = nullptr;
+ self_type *_prev = nullptr;
};
K _key;
@@ -60,37 +64,65 @@ 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)) {}
+ 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; }
+ 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<Linkage>;
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<K> Hasher;
- static K const& key_of(Item * item) { return item->_key; }
- static decltype(Hasher(std::declval<K>())) hash_of(K const& key) { return Hasher(key); }
- static bool equal(K const& lhs, K const& rhs) { return lhs == rhs; }
+ static K const &
+ key_of(Item *item) {
+ return item->_key;
+ }
+ static decltype(Hasher(std::declval<K>()))
+ hash_of(K const &key) {
+ return Hasher(key);
+ }
+ static bool
+ equal(K const &lhs, K const &rhs) {
+ return lhs == rhs;
+ }
};
using Table = swoc::IntrusiveHashMap<Hashing>;
std::shared_mutex _mutex; ///< Read/write lock.
- size_t _max = 1024; ///< Maximum number of elements.
- List _list; ///< LRU list.
- Table _table; ///< Keyed set of values.
- List _free; ///< Free list.
+ size_t _max = 1024; ///< Maximum number of elements.
+ List _list; ///< LRU list.
+ Table _table; ///< Keyed set of values.
+ List _free; ///< Free list.
swoc::MemArena _arena;
};
-template <typename K, typename V> auto LRU<K, V>::insert(K const &key, V &&value) -> self_type & {
+template <typename K, typename V>
+auto
+LRU<K, V>::insert(K const &key, V &&value) -> self_type & {
Item *target = nullptr;
{
std::unique_lock lock(_mutex);
@@ -98,7 +130,7 @@ template <typename K, typename V> auto LRU<K, V>::insert(K const &key, V &&value
if (spot != _table.end()) {
spot->_value = std::move(value);
} else {
- Item * item = _free.take_head();
+ Item *item = _free.take_head();
if (item != nullptr) {
new (item) Item(key, std::move(value));
} else {
@@ -122,11 +154,13 @@ template <typename K, typename V> auto LRU<K, V>::insert(K const &key, V &&value
return *this;
}
-template <typename K, typename V> auto LRU<K, V>::erase(K const &key) -> self_type & {
+template <typename K, typename V>
+auto
+LRU<K, V>::erase(K const &key) -> self_type & {
std::unique_lock lock(_mutex);
auto spot = _table.find(key);
if (spot != _table.end()) {
- Item * item = spot;
+ Item *item = spot;
_table.erase(item);
_list.erase(item);
_free.append(item);
@@ -134,7 +168,9 @@ template <typename K, typename V> auto LRU<K, V>::erase(K const &key) -> self_ty
return *this;
}
-template <typename K, typename V> auto LRU<K, V>::retrieve(K const &key) const -> V {
+template <typename K, typename V>
+auto
+LRU<K, V>::retrieve(K const &key) const -> V {
std::shared_lock lock(_mutex);
auto spot = _table.find(key);
return spot == _table.end() ? V{} : *spot;
@@ -142,9 +178,10 @@ template <typename K, typename V> auto LRU<K, V>::retrieve(K const &key) const -
// --------------------------------------------------
-int main(int, char *[]) {
+int
+main(int, char *[]) {
static constexpr size_t N_THREAD = 16; ///< Number of threads.
- static constexpr size_t N_ITER = 20000;
+ static constexpr size_t N_ITER = 20000;
std::array<std::thread, N_THREAD> threads;
std::mutex gate_m;
@@ -159,15 +196,15 @@ int main(int, char *[]) {
LRU<IPAddr, Data> lru;
lru.insert(swoc::IP4Addr{"172.17.56.93"}, Data{time_point(), 2});
- auto worker = [&] () -> void {
+ auto worker = [&]() -> void {
unsigned dummy;
{
std::unique_lock _(gate_m);
- gate_cv.wait(_, [&] () {return count >= 0; });
+ gate_cv.wait(_, [&]() { return count >= 0; });
}
swoc::IP4Addr addr((reinterpret_cast<uintptr_t>(&dummy) >> 16) & 0xFFFFFFFF);
auto tp = time_point();
- for ( unsigned i = 0 ; i < N_ITER ; ++i ) {
+ for (unsigned i = 0; i < N_ITER; ++i) {
lru.insert(addr, Data{tp, 1});
addr = htonl(addr.host_order() + 1);
}
@@ -178,7 +215,7 @@ int main(int, char *[]) {
gate_cv.notify_all();
};
- for ( unsigned i = 0 ; i < N_THREAD; ++i ) {
+ for (unsigned i = 0; i < N_THREAD; ++i) {
threads[i] = std::thread(worker);
}
@@ -191,14 +228,14 @@ int main(int, char *[]) {
{
std::unique_lock _(gate_m);
- gate_cv.wait(_, [&] () { return count == N_THREAD; });
+ gate_cv.wait(_, [&]() { return count == N_THREAD; });
}
- auto tf = std::chrono::system_clock::now();
+ auto tf = std::chrono::system_clock::now();
auto delta = tf - t0;
std::cout << "Done in " << delta.count() << " with " << lru.count() << std::endl;
std::cout << "ns per operation " << (delta.count() / (N_THREAD * N_ITER)) << std::endl;
- for ( unsigned i = 0 ; i < N_THREAD ; ++i ) {
+ for (unsigned i = 0; i < N_THREAD; ++i) {
threads[i].join();
}
diff --git a/example/ex_netcompact.cc b/example/ex_netcompact.cc
index 3822d8e..9fef738 100644
--- a/example/ex_netcompact.cc
+++ b/example/ex_netcompact.cc
@@ -39,11 +39,12 @@ using W = swoc::LocalBufferWriter<512>;
/// IPSpace for mapping address. Treating it as a set so use a no-data payload.
using Space = swoc::IPSpace<std::monostate>;
-void post_processing_performance_test(Space & space);
+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.
+unsigned
+process(Space &space, TextView content) {
+ int line_no = 0; /// Track for error reporting.
unsigned n_ranges = 0;
// For each line in @a content
@@ -67,7 +68,8 @@ unsigned process(Space& space, TextView content) {
return n_ranges;
}
-int main(int argc, char *argv[]) {
+int
+main(int argc, char *argv[]) {
Space space;
if (argc < 2) {
@@ -89,8 +91,8 @@ int main(int argc, char *argv[]) {
// Dump the results.
unsigned n_nets = 0;
- for ( auto && [range, payload] : space ) {
- for ( auto && net : range.networks() ) {
+ for (auto &&[range, payload] : space) {
+ for (auto &&net : range.networks()) {
++n_nets;
std::cout << W().print("{}\n", net);
}
@@ -98,21 +100,21 @@ int main(int argc, char *argv[]) {
auto delta = std::chrono::system_clock::now() - t0;
- std::cerr << W().print("{} ranges in, {} ranges condensed, {} networks out in {} ms\n"
- , n_ranges, space.count(), n_nets
- , std::chrono::duration_cast<std::chrono::milliseconds>(delta).count());
+ std::cerr << W().print("{} ranges in, {} ranges condensed, {} networks out in {} ms\n", n_ranges, space.count(), n_nets,
+ std::chrono::duration_cast<std::chrono::milliseconds>(delta).count());
post_processing_performance_test(space);
return 0;
}
-void post_processing_performance_test(Space & space) {
+void
+post_processing_performance_test(Space &space) {
using swoc::IP4Addr;
using swoc::IP6Addr;
std::vector<IP4Addr> a4;
std::vector<IP6Addr> a6;
- for ( auto && [ r, p] : space) {
+ for (auto &&[r, p] : space) {
if (r.is_ip4()) {
IP4Addr a = r.min().ip4();
a4.push_back(a);
@@ -134,7 +136,7 @@ void post_processing_performance_test(Space & space) {
}
}
- if (! a4.empty()) {
+ if (!a4.empty()) {
auto t0 = std::chrono::system_clock::now();
for (auto const &addr : a4) {
[[maybe_unused]] auto spot = space.find(addr);
diff --git a/example/ex_netdb.cc b/example/ex_netdb.cc
index 2099c70..de5fc68 100644
--- a/example/ex_netdb.cc
+++ b/example/ex_netdb.cc
@@ -62,12 +62,12 @@ using W = swoc::LocalBufferWriter<512>;
/// Network properties.
enum class Flag {
- INVALID = -1, ///< Value for initialization, invalid.
- INTERNAL = 0, ///< Internal network.
- PROD, ///< Production network.
- DMZ, ///< DMZ
- SECURE, ///< Secure network
- NONE ///< No flags - useful because the input uses "-" sometimes to mark no properties.
+ INVALID = -1, ///< Value for initialization, invalid.
+ INTERNAL = 0, ///< Internal network.
+ PROD, ///< Production network.
+ DMZ, ///< DMZ
+ SECURE, ///< Secure network
+ NONE ///< No flags - useful because the input uses "-" sometimes to mark no properties.
};
namespace std {
@@ -81,36 +81,39 @@ using FlagSet = std::bitset<std::tuple_size<Flag>::value>;
/// Pod type.
enum class PodType {
INVALID, ///< Initialization value.
- YAHOO, ///< Yahoo! pod.
- PARTNER ///< Partner pod.
+ YAHOO, ///< Yahoo! pod.
+ PARTNER ///< Partner pod.
};
/// Mapping of names and property flags.
-swoc::Lexicon<Flag> FlagNames {decltype(FlagNames)::with_multi{
- {Flag::NONE, {"-", "NONE"}}
- , {Flag::INTERNAL, { "internal" }}
- , {Flag::PROD, {"prod"}}
- , {Flag::DMZ, {"dmz"}}
- , {Flag::SECURE, {"secure"}}
- }, Flag::INVALID};
+swoc::Lexicon<Flag> FlagNames{
+ decltype(FlagNames)::with_multi{{Flag::NONE, {"-", "NONE"}},
+ {Flag::INTERNAL, {"internal"}},
+ {Flag::PROD, {"prod"}},
+ {Flag::DMZ, {"dmz"}},
+ {Flag::SECURE, {"secure"}}},
+ Flag::INVALID
+};
/// Mapping of names and pod types.
-swoc::Lexicon<PodType> PodTypeNames {decltype(PodTypeNames)::with{
- {PodType::YAHOO, "yahoo"}
- , {PodType::PARTNER, "partner"}
- }, PodType::INVALID};
+swoc::Lexicon<PodType> PodTypeNames{
+ decltype(PodTypeNames)::with{{PodType::YAHOO, "yahoo"}, {PodType::PARTNER, "partner"}},
+ PodType::INVALID
+};
// Create BW formatters for the types so they can be used for output.
namespace swoc {
-BufferWriter& bwformat(BufferWriter& w, bwf::Spec const& spec, PodType pt) {
+BufferWriter &
+bwformat(BufferWriter &w, bwf::Spec const &spec, PodType pt) {
return bwformat(w, spec, (PodTypeNames[pt]));
}
-BufferWriter& bwformat(BufferWriter& w, bwf::Spec const& spec, FlagSet const& flags) {
+BufferWriter &
+bwformat(BufferWriter &w, bwf::Spec const &spec, FlagSet const &flags) {
bool first_p = true; // Track to get separators correct.
// Loop through the indices and write the flag name if it's set.
- for ( unsigned idx = 0 ; idx < std::tuple_size<Flag>::value ; ++idx) {
+ for (unsigned idx = 0; idx < std::tuple_size<Flag>::value; ++idx) {
if (flags[idx]) {
if (!first_p) {
w.write(';');
@@ -121,7 +124,7 @@ BufferWriter& bwformat(BufferWriter& w, bwf::Spec const& spec, FlagSet const& fl
}
return w;
}
-} // namespace SWOC_NAMESPACE
+} // namespace swoc
// These are used to keep pointers for the same string identical so the payloads
// can be directly compared.
@@ -132,27 +135,24 @@ std::unordered_set<TextView, std::hash<std::string_view>> Descriptions;
/// The "color" for the IPSpace.
struct Payload {
PodType _type = PodType::INVALID; ///< Type of ownership.
- TextView _owner; ///< Corporate owner.
- TextView _pod; ///< Pod / colocation.
- TextView _descr; ///< Description / comment
- FlagSet _flags; ///< Flags.
+ TextView _owner; ///< Corporate owner.
+ TextView _pod; ///< Pod / colocation.
+ TextView _descr; ///< Description / comment
+ FlagSet _flags; ///< Flags.
/// @return @c true if @a this is equal to @a that.
- bool operator == (Payload const& that) {
- return _type == that._type &&
- _owner == that._owner &&
- _pod == that._pod &&
- _flags == that._flags &&
- _descr == that._descr;
+ bool
+ operator==(Payload const &that) {
+ return _type == that._type && _owner == that._owner && _pod == that._pod && _flags == that._flags && _descr == that._descr;
}
/// @return @c true if @a this is not equal to @a that.
- bool operator != (Payload const& that) {
- return ! (*this == that);
+ bool
+ operator!=(Payload const &that) {
+ return !(*this == that);
}
};
-
/// IPSpace for mapping address to @c Payload
using Space = swoc::IPSpace<Payload>;
@@ -160,18 +160,20 @@ using Space = swoc::IPSpace<Payload>;
swoc::MemArena Storage;
/// Convert a parsed string into a stored string to make the pointer persistent.
-TextView store(TextView const& text) {
+TextView
+store(TextView const &text) {
auto span = Storage.alloc(text.size()).rebind<char>();
memcpy(span, text);
return span;
}
/// Process the @a content of a file in to @a space.
-void process(Space& space, TextView content) {
+void
+process(Space &space, TextView content) {
int line_no = 0; /// Track for error reporting.
// For each line in @a content
- for (TextView line ; ! (line = content.take_prefix_at('\n')).empty() ; ) {
+ for (TextView line; !(line = content.take_prefix_at('\n')).empty();) {
++line_no;
line.trim_if(&isspace);
// Allow empty lines and '#' comments without error.
@@ -190,7 +192,7 @@ void process(Space& space, TextView content) {
// Get the owner / type.
auto owner_token = line.ltrim_if(&isspace).take_prefix_if(&isspace);
PodType pod_type = PodType::YAHOO; // default to this if no owner specifier found.
- if (auto type_token = owner_token.split_prefix_at(':') ; ! type_token.empty()) {
+ if (auto type_token = owner_token.split_prefix_at(':'); !type_token.empty()) {
pod_type = PodTypeNames[type_token];
if (PodType::INVALID == pod_type) {
std::cerr << W().print("Invalid type '{}' on line {}\n", type_token, line_no);
@@ -199,7 +201,7 @@ void process(Space& space, TextView content) {
}
// normalize owner
- if ( auto spot = OwnerNames.find(owner_token) ; spot == OwnerNames.end()) {
+ if (auto spot = OwnerNames.find(owner_token); spot == OwnerNames.end()) {
owner_token = store(owner_token);
OwnerNames.insert(owner_token);
} else {
@@ -210,7 +212,7 @@ void process(Space& space, TextView content) {
auto pod_token = line.ltrim_if(&isspace).take_prefix_if(&isspace);
// normalize
- if ( auto spot = PodNames.find(pod_token) ; spot == PodNames.end()) {
+ if (auto spot = PodNames.find(pod_token); spot == PodNames.end()) {
pod_token = store(pod_token);
PodNames.insert(pod_token);
} else {
@@ -223,7 +225,7 @@ void process(Space& space, TextView content) {
auto flag_token = line.ltrim_if(&isspace).take_prefix_if(&isspace);
FlagSet flags;
// Loop over the token, picking out comma separated keys.
- for ( TextView key ; ! (key = flag_token.take_prefix_at(',')).empty() ; ) {
+ for (TextView key; !(key = flag_token.take_prefix_at(',')).empty();) {
auto idx = FlagNames[key]; // look up the key.
if (Flag::INVALID == idx) {
std::cerr << W().print("Invalid flag '{}' on line {}\n", key, line_no);
@@ -234,7 +236,7 @@ void process(Space& space, TextView content) {
}
}
- #if 0
+#if 0
// The description is what's left, trim the spaces and then the quotes.
auto descr_token = line.trim_if(&isspace).trim('"');
// normalize
@@ -244,11 +246,11 @@ void process(Space& space, TextView content) {
} else {
descr_token = *spot;
}
- #endif
+#endif
// Everything went OK, create the payload and put it in the space.
Payload payload{pod_type, owner_token, pod_token, {}, flags};
- space.blend(range, payload, [&](Payload & lhs, Payload const& rhs) {
+ space.blend(range, payload, [&](Payload &lhs, Payload const &rhs) {
// It's an error if there's overlap that's not consistent.
if (lhs._type != PodType::INVALID && lhs != rhs) {
std::cerr << W().print("Range collision while blending {} on line {}\n", range, line_no);
@@ -259,30 +261,31 @@ void process(Space& space, TextView content) {
}
}
-void post_processing_performance_test(Space & old_space) {
+void
+post_processing_performance_test(Space &old_space) {
Space space;
swoc::file::path vz_db_path{"vz_netdb.csv"};
std::error_code ec;
- auto t0 = std::chrono::system_clock::now();
+ auto t0 = std::chrono::system_clock::now();
std::string content = swoc::file::load(vz_db_path, ec);
TextView text{content};
unsigned line_no = 0;
- for (TextView line ; ! (line = text.take_prefix_at('\n')).empty() ; ) {
+ for (TextView line; !(line = text.take_prefix_at('\n')).empty();) {
++line_no;
// Get the range, make sure it's a valid range.
auto range_token = line.take_prefix_at(',');
IPRange range{range_token};
// Get the owner / type.
- auto pod_type = PodTypeNames[line.take_prefix_at(',')];
- auto owner = line.take_prefix_at(',');
- auto pod_token = line.take_prefix_at(',');
+ auto pod_type = PodTypeNames[line.take_prefix_at(',')];
+ auto owner = line.take_prefix_at(',');
+ auto pod_token = line.take_prefix_at(',');
auto flag_token = line.take_prefix_at(',');
FlagSet flags;
// Loop over the token, picking out keys
- for ( TextView key ; ! (key = flag_token.take_prefix_at(';')).empty() ; ) {
+ for (TextView key; !(key = flag_token.take_prefix_at(';')).empty();) {
auto idx = FlagNames[key]; // look up the key.
if (Flag::INVALID == idx) {
std::cerr << W().print("Invalid flag '{}'\n", key);
@@ -296,15 +299,14 @@ void post_processing_performance_test(Space & old_space) {
space.mark(range, payload);
}
auto vz_delta = std::chrono::system_clock::now() - t0;
- std::cout << W().print("Reload time - {} ms\n",
- std::chrono::duration_cast<std::chrono::milliseconds>(vz_delta).count());
+ std::cout << W().print("Reload time - {} ms\n", std::chrono::duration_cast<std::chrono::milliseconds>(vz_delta).count());
if (line_no != space.count()) {
std::cerr << W().print("Space count {} does not match line count {}\n", space.count(), line_no);
}
std::vector<IP4Addr> a4;
std::vector<IP6Addr> a6;
- for ( auto && [ r, p] : space) {
+ for (auto &&[r, p] : space) {
if (r.is_ip4()) {
IP4Addr a = r.min().ip4();
a4.push_back(a);
@@ -326,39 +328,40 @@ void post_processing_performance_test(Space & old_space) {
}
}
t0 = std::chrono::system_clock::now();
- for ( auto const& addr : a4) {
+ for (auto const &addr : a4) {
[[maybe_unused]] auto spot = space.find(addr);
}
vz_delta = std::chrono::system_clock::now() - t0;
- std::cout << W().print("IPv4 time - {} addresses, {} ns total, {} ns per lookup\n",
- a4.size(), vz_delta.count(), vz_delta.count() / a4.size());
+ std::cout << W().print("IPv4 time - {} addresses, {} ns total, {} ns per lookup\n", a4.size(), vz_delta.count(),
+ vz_delta.count() / a4.size());
t0 = std::chrono::system_clock::now();
- for ( auto const& addr : a6) {
+ for (auto const &addr : a6) {
[[maybe_unused]] auto spot = space.find(addr);
}
vz_delta = std::chrono::system_clock::now() - t0;
- std::cout << W().print("IPv6 time - {} addresses, {} ns total, {} ns per lookup\n",
- a6.size(), vz_delta.count(), vz_delta.count() / a6.size());
+ std::cout << W().print("IPv6 time - {} addresses, {} ns total, {} ns per lookup\n", a6.size(), vz_delta.count(),
+ vz_delta.count() / a6.size());
t0 = std::chrono::system_clock::now();
- for ( auto const& addr : a4) {
+ for (auto const &addr : a4) {
[[maybe_unused]] auto spot = old_space.find(addr);
}
vz_delta = std::chrono::system_clock::now() - t0;
- std::cout << W().print("IPv4 time (pre-cleaning) - {} addresses, {} ns total, {} ns per lookup\n",
- a4.size(), vz_delta.count(), vz_delta.count() / a4.size());
+ std::cout << W().print("IPv4 time (pre-cleaning) - {} addresses, {} ns total, {} ns per lookup\n", a4.size(), vz_delta.count(),
+ vz_delta.count() / a4.size());
t0 = std::chrono::system_clock::now();
- for ( auto const& addr : a6) {
+ for (auto const &addr : a6) {
[[maybe_unused]] auto spot = old_space.find(addr);
}
vz_delta = std::chrono::system_clock::now() - t0;
- std::cout << W().print("IPv6 time (pre-cleaning) - {} addresses, {} ns total, {} ns per lookup\n",
- a6.size(), vz_delta.count(), vz_delta.count() / a6.size());
+ std::cout << W().print("IPv6 time (pre-cleaning) - {} addresses, {} ns total, {} ns per lookup\n", a6.size(), vz_delta.count(),
+ vz_delta.count() / a6.size());
}
-int main(int argc, char *argv[]) {
+int
+main(int argc, char *argv[]) {
Space space;
// Set the defaults so bogus input doesn't throw.
@@ -368,17 +371,17 @@ int main(int argc, char *argv[]) {
// Open the output file.
std::ofstream output;
output.open("vz_netdb.csv", std::ofstream::out | std::ofstream::trunc);
- if (! output.is_open()) {
+ if (!output.is_open()) {
std::cerr << W().print("Unable to open output file: {}", swoc::bwf::Errno{errno});
}
auto t0 = std::chrono::system_clock::now();
// Process the files in the command line.
- for ( int idx = 1 ; idx < argc ; ++idx ) {
+ for (int idx = 1; idx < argc; ++idx) {
swoc::file::path path(argv[idx]);
std::error_code ec;
std::string content = swoc::file::load(path, ec);
- if (! ec) {
+ if (!ec) {
std::cout << W().print("Processing {}, {} bytes\n", path, content.size());
process(space, content);
}
@@ -387,7 +390,7 @@ int main(int argc, char *argv[]) {
// Dump the resulting space.
std::cout << W().print("{} ranges\n", space.count());
- for ( auto && [ r, p] : space) {
+ for (auto &&[r, p] : space) {
// Note - if description is to be used, it needs to be added here.
output << W().print("{},{},{},{},{}\n", r, p._type, p._owner, p._pod, p._flags);
}
@@ -395,8 +398,8 @@ int main(int argc, char *argv[]) {
auto write_delta = std::chrono::system_clock::now() - t0;
std::cout << W().print("Read & process time - {} ms, write time {} ms\n",
- std::chrono::duration_cast<std::chrono::milliseconds>(read_delta).count(),
- std::chrono::duration_cast<std::chrono::milliseconds>(write_delta - read_delta).count());
+ std::chrono::duration_cast<std::chrono::milliseconds>(read_delta).count(),
+ std::chrono::duration_cast<std::chrono::milliseconds>(write_delta - read_delta).count());
post_processing_performance_test(space);
return 0;
diff --git a/unit_tests/ex_IntrusiveDList.cc b/unit_tests/ex_IntrusiveDList.cc
index c0c9d54..3c59a9e 100644
--- a/unit_tests/ex_IntrusiveDList.cc
+++ b/unit_tests/ex_IntrusiveDList.cc
@@ -34,8 +34,7 @@
using swoc::IntrusiveDList;
-class Message
-{
+class Message {
using self_type = Message; ///< Self reference type.
public:
@@ -62,31 +61,27 @@ protected:
};
auto
-Message::Linkage::next_ptr(self_type *that) -> self_type *&
-{
+Message::Linkage::next_ptr(self_type *that) -> self_type *& {
return that->_link._next;
}
auto
-Message::Linkage::prev_ptr(self_type *that) -> self_type *&
-{
+Message::Linkage::prev_ptr(self_type *that) -> self_type *& {
return that->_link._prev;
}
bool
-Message::is_in_list() const
-{
+Message::is_in_list() const {
return _link._next || _link._prev;
}
-class Container
-{
+class Container {
using self_type = Container;
using MessageList = IntrusiveDList<Message::Linkage>;
public:
~Container();
- template <typename... Args> self_type &debug(std::string_view fmt, Args &&... args);
+ template <typename... Args> self_type &debug(std::string_view fmt, Args &&...args);
size_t count() const;
self_type &clear();
@@ -97,14 +92,12 @@ protected:
MessageList _msgs;
};
-Container::~Container()
-{
+Container::~Container() {
this->clear(); // clean up memory.
}
auto
-Container::clear() -> self_type &
-{
+Container::clear() -> self_type & {
Message *msg;
while (nullptr != (msg = _msgs.take_head())) {
delete msg;
@@ -114,15 +107,13 @@ Container::clear() -> self_type &
}
size_t
-Container::count() const
-{
+Container::count() const {
return _msgs.count();
}
template <typename... Args>
auto
-Container::debug(std::string_view fmt, Args &&... args) -> self_type &
-{
+Container::debug(std::string_view fmt, Args &&...args) -> self_type & {
Message *msg = new Message;
swoc::bwprint_v(msg->_text, fmt, std::forward_as_tuple(args...));
msg->_severity = Message::LVL_DEBUG;
@@ -131,23 +122,20 @@ Container::debug(std::string_view fmt, Args &&... args) -> self_type &
}
Message::Severity
-Container::max_severity() const
-{
+Container::max_severity() const {
auto spot = std::max_element(_msgs.begin(), _msgs.end(),
[](Message const &lhs, Message const &rhs) { return lhs._severity < rhs._severity; });
return spot == _msgs.end() ? Message::Severity::LVL_DEBUG : spot->_severity;
}
void
-Container::print() const
-{
+Container::print() const {
for (auto &&elt : _msgs) {
std::cout << static_cast<unsigned int>(elt._severity) << ": " << elt._text << std::endl;
}
}
-TEST_CASE("IntrusiveDList Example", "[libswoc][IntrusiveDList]")
-{
+TEST_CASE("IntrusiveDList Example", "[libswoc][IntrusiveDList]") {
Container container;
container.debug("This is message {}", 1);
@@ -165,8 +153,7 @@ struct Thing {
};
// Just for you, @maskit ! Demonstrating non-public links and subclassing.
-class PrivateThing : protected Thing
-{
+class PrivateThing : protected Thing {
using self_type = PrivateThing;
using super_type = Thing;
@@ -175,26 +162,22 @@ public:
struct Linkage {
static self_type *&
- next_ptr(self_type *t)
- {
+ next_ptr(self_type *t) {
return swoc::ptr_ref_cast<self_type>(t->_next);
}
static self_type *&
- prev_ptr(self_type *t)
- {
+ prev_ptr(self_type *t) {
return swoc::ptr_ref_cast<self_type>(t->_prev);
}
};
std::string const &
- payload() const
- {
+ payload() const {
return _payload;
}
};
-class PrivateThing2 : protected Thing
-{
+class PrivateThing2 : protected Thing {
using self_type = PrivateThing2;
using super_type = Thing;
@@ -204,14 +187,12 @@ public:
friend Linkage;
std::string const &
- payload() const
- {
+ payload() const {
return _payload;
}
};
-TEST_CASE("IntrusiveDList Inheritance", "[libswoc][IntrusiveDList][example]")
-{
+TEST_CASE("IntrusiveDList Inheritance", "[libswoc][IntrusiveDList][example]") {
IntrusiveDList<PrivateThing::Linkage> priv_list;
for (size_t i = 1; i <= 23; ++i) {
swoc::LocalBufferWriter<16> w;
diff --git a/unit_tests/ex_Lexicon.cc b/unit_tests/ex_Lexicon.cc
index 2f1baa1..1be975e 100644
--- a/unit_tests/ex_Lexicon.cc
+++ b/unit_tests/ex_Lexicon.cc
@@ -19,9 +19,9 @@
// doc.1.begin
enum class NetType {
EXTERNAL = 0, // 0x1
- PROD, // 0x2
- SECURE, // 0x4
- EDGE, // 0x8
+ PROD, // 0x2
+ SECURE, // 0x4
+ EDGE, // 0x8
INVALID
};
// doc.1.end
@@ -31,12 +31,10 @@ static constexpr size_t N_TYPES = size_t(NetType::INVALID);
// Set up a Lexicon to convert between the enumeration and strings.
// doc.2.begin
-swoc::Lexicon<NetType> const NetTypeNames { {{NetType::EXTERNAL, "external"},
- {NetType::PROD, "prod"},
- {NetType::SECURE, "secure"},
- {NetType::EDGE, "edge"}},
- NetType::INVALID // default value for undefined name
- };
+swoc::Lexicon<NetType> const NetTypeNames{
+ {{NetType::EXTERNAL, "external"}, {NetType::PROD, "prod"}, {NetType::SECURE, "secure"}, {NetType::EDGE, "edge"}},
+ NetType::INVALID // default value for undefined name
+};
// doc.2.end
// A bit set for the flags.
@@ -46,13 +44,13 @@ TEST_CASE("Lexicon Example", "[libts][Lexicon]") {
swoc::IPSpace<Flags> space; // Space in which to store the flags.
// Load the file contents
// doc.file.begin
- swoc::TextView text { R"(
+ swoc::TextView text{R"(
10.0.0.2-10.0.0.254,edge
10.12.0.0/25,prod
10.15.37.10-10.15.37.99,prod,secure
172.19.0.0/22,external,secure
192.168.18.0/23,external,prod
- )" };
+ )"};
// doc.file.end
// doc.load.begin
// Process all the lines in the file.
@@ -65,7 +63,7 @@ TEST_CASE("Lexicon Example", "[libts][Lexicon]") {
while (line) { // parse out the rest of the comma separated elements
auto token = line.take_prefix_at(',');
auto idx = NetTypeNames[token];
- if (idx != NetType::INVALID) { // one of the valid strings
+ if (idx != NetType::INVALID) { // one of the valid strings
flags.set(static_cast<int>(idx)); // set the bit
}
}
@@ -76,17 +74,17 @@ TEST_CASE("Lexicon Example", "[libts][Lexicon]") {
using AddrCase = std::tuple<swoc::IPAddr, Flags>;
using swoc::IPAddr;
- std::array<AddrCase, 5> AddrList = {{
- {IPAddr{"10.0.0.6"}, 0x8}
- , {IPAddr{"172.19.3.31"}, 0x5}
- , {IPAddr{"192.168.18.19"}, 0x3}
- , {IPAddr{"10.15.37.57"}, 0x6}
- , {IPAddr{"10.12.0.126"}, 0x2}
- }};
-
- for ( auto const& [ addr, bits ] : AddrList ) {
+ std::array<AddrCase, 5> AddrList = {
+ {{IPAddr{"10.0.0.6"}, 0x8},
+ {IPAddr{"172.19.3.31"}, 0x5},
+ {IPAddr{"192.168.18.19"}, 0x3},
+ {IPAddr{"10.15.37.57"}, 0x6},
+ {IPAddr{"10.12.0.126"}, 0x2}}
+ };
+
+ for (auto const &[addr, bits] : AddrList) {
// doc.lookup.begin
- auto [ range, flags ] = *space.find(addr);
+ auto [range, flags] = *space.find(addr);
// doc.lookup.end
REQUIRE_FALSE(range.empty());
CHECK(flags == bits);
@@ -96,44 +94,37 @@ TEST_CASE("Lexicon Example", "[libts][Lexicon]") {
namespace {
// doc.ctor.1.begin
-swoc::Lexicon<NetType> const Example1 {
- {{NetType::EXTERNAL, "external"},
- {NetType::PROD, "prod"},
- {NetType::SECURE, "secure"},
- {NetType::EDGE, "edge"}},
+swoc::Lexicon<NetType> const Example1{
+ {{NetType::EXTERNAL, "external"}, {NetType::PROD, "prod"}, {NetType::SECURE, "secure"}, {NetType::EDGE, "edge"}},
"*invalid*", // default name for undefined values
- NetType::INVALID // default value for undefined name
+ NetType::INVALID // default value for undefined name
};
// doc.ctor.1.end
// doc.ctor.2.begin
-swoc::Lexicon<NetType> const Example2 {
- {{NetType::EXTERNAL, "external"},
- {NetType::PROD, "prod"},
- {NetType::SECURE, "secure"},
- {NetType::EDGE, "edge"}},
+swoc::Lexicon<NetType> const Example2{
+ {{NetType::EXTERNAL, "external"}, {NetType::PROD, "prod"}, {NetType::SECURE, "secure"}, {NetType::EDGE, "edge"}},
};
// doc.ctor.2.end
// doc.ctor.3.begin
-swoc::Lexicon<NetType> Example3 {
- "*invalid*", // default name for undefined values
- NetType::INVALID // default value for undefined name
+swoc::Lexicon<NetType> Example3{
+ "*invalid*", // default name for undefined values
+ NetType::INVALID // default value for undefined name
};
// doc.ctor.3.end
// doc.ctor.4.begin
enum BoolTag {
INVALID = -1,
- False = 0,
- True = 1,
+ False = 0,
+ True = 1,
};
-swoc::Lexicon<BoolTag> const BoolNames {
- {{ BoolTag::True, { "true", "1", "on", "enable", "Y", "yes" }}
- , { BoolTag::False, { "false", "0", "off", "disable", "N", "no" }}}
- , BoolTag::INVALID };
+swoc::Lexicon<BoolTag> const BoolNames{
+ {{BoolTag::True, {"true", "1", "on", "enable", "Y", "yes"}}, {BoolTag::False, {"false", "0", "off", "disable", "N", "no"}}},
+ BoolTag::INVALID
+};
// doc.ctor.4.end
-
} // namespace
diff --git a/unit_tests/ex_MemArena.cc b/unit_tests/ex_MemArena.cc
index 8b9afff..a6f7098 100644
--- a/unit_tests/ex_MemArena.cc
+++ b/unit_tests/ex_MemArena.cc
@@ -35,8 +35,7 @@ using swoc::FixedBufferWriter;
using namespace std::literals;
TextView
-localize(MemArena &arena, TextView view)
-{
+localize(MemArena &arena, TextView view) {
auto span = arena.alloc(view.size()).rebind<char>();
memcpy(span, view);
return span;
@@ -44,20 +43,17 @@ localize(MemArena &arena, TextView view)
template <typename T> struct Destructor {
void
- operator()(T *t)
- {
+ operator()(T *t) {
t->~T();
}
};
void
-Destroy(MemArena *arena)
-{
+Destroy(MemArena *arena) {
arena->~MemArena();
}
-TEST_CASE("MemArena inversion", "[libswoc][MemArena][example][inversion]")
-{
+TEST_CASE("MemArena inversion", "[libswoc][MemArena][example][inversion]") {
TextView tv{"You done messed up A-A-Ron"};
TextView text{"SolidWallOfCode"};
@@ -131,8 +127,7 @@ TEST_CASE("MemArena inversion", "[libswoc][MemArena][example][inversion]")
template <typename... Args>
TextView
-bw_localize(MemArena &arena, TextView const &fmt, Args &&... args)
-{
+bw_localize(MemArena &arena, TextView const &fmt, Args &&...args) {
FixedBufferWriter w(arena.remnant());
auto arg_tuple{std::forward_as_tuple(args...)};
w.print_v(fmt, arg_tuple);
@@ -142,8 +137,7 @@ bw_localize(MemArena &arena, TextView const &fmt, Args &&... args)
return arena.alloc(w.extent()).rebind<char>();
}
-TEST_CASE("MemArena example", "[libswoc][MemArena][example]")
-{
+TEST_CASE("MemArena example", "[libswoc][MemArena][example]") {
struct Thing {
using self_type = Thing;
@@ -165,20 +159,17 @@ TEST_CASE("MemArena example", "[libswoc][MemArena][example]")
struct Linkage : swoc::IntrusiveLinkage<self_type> {
static std::string_view
- key_of(self_type *thing)
- {
+ key_of(self_type *thing) {
return thing->name;
}
static uint32_t
- hash_of(std::string_view const &s)
- {
+ hash_of(std::string_view const &s) {
return swoc::Hash32FNV1a().hash_immediate(swoc::transform_view_of(&toupper, s));
}
static bool
- equal(std::string_view const &lhs, std::string_view const &rhs)
- {
+ equal(std::string_view const &lhs, std::string_view const &rhs) {
return lhs == rhs;
}
};
diff --git a/unit_tests/ex_TextView.cc b/unit_tests/ex_TextView.cc
index ceb7711..d048439 100644
--- a/unit_tests/ex_TextView.cc
+++ b/unit_tests/ex_TextView.cc
@@ -19,15 +19,15 @@ using swoc::TextView;
using namespace swoc::literals;
// CSV parsing.
-namespace
-{
+namespace {
// Standard results array so these names can be used repeatedly.
-std::array<TextView, 6> alphabet{{"alpha", "bravo", "charlie", "delta", "echo", "foxtrot"}};
+std::array<TextView, 6> alphabet{
+ {"alpha", "bravo", "charlie", "delta", "echo", "foxtrot"}
+};
// -- doc csv start
void
-parse_csv(TextView src, std::function<void(TextView)> const &f)
-{
+parse_csv(TextView src, std::function<void(TextView)> const &f) {
while (src.ltrim_if(&isspace)) {
TextView token{src.take_prefix_at(',').rtrim_if(&isspace)};
if (token) { // skip empty tokens (double separators)
@@ -39,8 +39,7 @@ parse_csv(TextView src, std::function<void(TextView)> const &f)
// -- doc csv non-empty start
void
-parse_csv_non_empty(TextView src, std::function<void(TextView)> const &f)
-{
+parse_csv_non_empty(TextView src, std::function<void(TextView)> const &f) {
TextView token;
while ((token = src.take_prefix_at(',').trim_if(&isspace))) {
f(token);
@@ -50,8 +49,7 @@ parse_csv_non_empty(TextView src, std::function<void(TextView)> const &f)
// -- doc kv start
void
-parse_kw(TextView src, std::function<void(TextView, TextView)> const &f)
-{
+parse_kw(TextView src, std::function<void(TextView, TextView)> const &f) {
while (src) {
TextView value{src.take_prefix_at(',').trim_if(&isspace)};
if (value) {
@@ -65,18 +63,16 @@ parse_kw(TextView src, std::function<void(TextView, TextView)> const &f)
} // namespace
-TEST_CASE("TextView Example CSV", "[libswoc][example][textview][csv]")
-{
- char const *src = "alpha,bravo, charlie,delta , echo ,, ,foxtrot";
+TEST_CASE("TextView Example CSV", "[libswoc][example][textview][csv]") {
+ char const *src = "alpha,bravo, charlie,delta , echo ,, ,foxtrot";
char const *src_non_empty = "alpha,bravo, charlie, delta, echo ,foxtrot";
- int idx = 0;
+ int idx = 0;
parse_csv(src, [&](TextView tv) -> void { REQUIRE(tv == alphabet[idx++]); });
idx = 0;
parse_csv_non_empty(src_non_empty, [&](TextView tv) -> void { REQUIRE(tv == alphabet[idx++]); });
};
-TEST_CASE("TextView Example KW", "[libswoc][example][textview][kw]")
-{
+TEST_CASE("TextView Example KW", "[libswoc][example][textview][kw]") {
TextView src{"alpha=1, bravo= 2,charlie = 3, delta =4 ,echo ,, ,foxtrot=6"};
size_t idx = 0;
parse_kw(src, [&](TextView key, TextView value) -> void {
@@ -91,8 +87,7 @@ TEST_CASE("TextView Example KW", "[libswoc][example][textview][kw]")
// Example: streaming token parsing, with quote stripping.
-TEST_CASE("TextView Tokens", "[libswoc][example][textview][tokens]")
-{
+TEST_CASE("TextView Tokens", "[libswoc][example][textview][tokens]") {
auto tokenizer = [](TextView &src, char sep, bool strip_quotes_p = true) -> TextView {
TextView::size_type idx = 0;
// Characters of interest in a null terminated string.
@@ -204,8 +199,7 @@ TEST_CASE("TextView Tokens", "[libswoc][example][textview][tokens]")
// Example: line parsing from a file.
-TEST_CASE("TextView Lines", "[libswoc][example][textview][lines]")
-{
+TEST_CASE("TextView Lines", "[libswoc][example][textview][lines]") {
swoc::file::path path{"doc/conf.py"};
std::error_code ec;
@@ -227,8 +221,7 @@ TEST_CASE("TextView Lines", "[libswoc][example][textview][lines]")
#include <set>
#include "swoc/swoc_ip.h"
-TEST_CASE("TextView misc", "[libswoc][example][textview][misc]")
-{
+TEST_CASE("TextView misc", "[libswoc][example][textview][misc]") {
TextView src = " alpha.bravo.old:charlie.delta.old : echo.foxtrot.old ";
REQUIRE("alpha.bravo" == src.take_prefix_at(':').remove_suffix_at('.').ltrim_if(&isspace));
REQUIRE("charlie.delta" == src.take_prefix_at(':').remove_suffix_at('.').ltrim_if(&isspace));
@@ -237,48 +230,43 @@ TEST_CASE("TextView misc", "[libswoc][example][textview][misc]")
}
TEST_CASE("TextView parsing", "[libswoc][example][text][parsing]") {
- static const std::set<std::string_view> DC_TAGS {
- "amb", "ata", "aue", "bga", "bra", "cha", "coa", "daa", "dca", "deb", "dnb", "esa", "fra", "frb"
- , "hkb", "inc", "ir2", "jpa", "laa", "lob", "mib"
- , "nya", "rob", "seb", "sgb", "sja", "swb", "tpb", "twb", "via", "waa"
- };
+ static const std::set<std::string_view> DC_TAGS{"amb", "ata", "aue", "bga", "bra", "cha", "coa", "daa", "dca", "deb", "dnb",
+ "esa", "fra", "frb", "hkb", "inc", "ir2", "jpa", "laa", "lob", "mib", "nya",
+ "rob", "seb", "sgb", "sja", "swb", "tpb", "twb", "via", "waa"};
TextView parsed;
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 };
+ TextView content{data};
while (content) {
- auto line { content.take_prefix_at('\n').trim_if(&isspace) }; // get the next line.
- if (line.empty() || *line == '#') { // skip empty and lines starting with '#'
+ auto line{content.take_prefix_at('\n').trim_if(&isspace)}; // get the next line.
+ if (line.empty() || *line == '#') { // skip empty and lines starting with '#'
continue;
}
- auto addr_txt = line.take_prefix_at(';');
- auto conf_txt = line.ltrim_if(&isspace).take_prefix_if(&isspace);
+ auto addr_txt = line.take_prefix_at(';');
+ auto conf_txt = line.ltrim_if(&isspace).take_prefix_if(&isspace);
auto dcnum_txt = line.ltrim_if(&isspace).take_prefix_if(&isspace);
- auto dc_txt = line.ltrim_if(&isspace).take_prefix_if(&isspace);
+ auto dc_txt = line.ltrim_if(&isspace).take_prefix_if(&isspace);
// First element must be a valid IPv4 address.
REQUIRE(addr.load(addr_txt) == true);
// Confidence value must be an unsigned integer after the '='.
- auto conf_value {conf_txt.split_suffix_at('=')};
+ auto conf_value{conf_txt.split_suffix_at('=')};
swoc::svtou(conf_value, &parsed);
REQUIRE(conf_value == parsed); // valid integer
// Number of elements in @a dc_txt - verify it's an integer.
- auto dcnum_value {dcnum_txt.split_suffix_at('=')};
+ auto dcnum_value{dcnum_txt.split_suffix_at('=')};
auto dc_n = swoc::svtou(dcnum_value, &parsed);
REQUIRE(dcnum_value == parsed); // valid integer
// Verify the expected prefix for the DC list.
- static constexpr TextView DC_PREFIX { "dc=[" };
- if (!dc_txt.starts_with(DC_PREFIX) ||
- dc_txt.remove_prefix(DC_PREFIX.size()).empty() ||
- dc_txt.back() != ']'
- ) {
+ static constexpr TextView DC_PREFIX{"dc=["};
+ if (!dc_txt.starts_with(DC_PREFIX) || dc_txt.remove_prefix(DC_PREFIX.size()).empty() || dc_txt.back() != ']') {
continue;
}
@@ -286,8 +274,8 @@ TEST_CASE("TextView parsing", "[libswoc][example][text][parsing]") {
// walk the comma separated tokens
unsigned dc_count = 0;
while (dc_txt) {
- auto key = dc_txt.take_prefix_at(',');
- auto value = key.take_suffix_at('=');
+ auto key = dc_txt.take_prefix_at(',');
+ auto value = key.take_suffix_at('=');
[[maybe_unused]] auto n = swoc::svtou(value, &parsed);
// Each element must be one of the known tags, followed by '=' and an integer.
REQUIRE(parsed == value); // value integer.
diff --git a/unit_tests/ex_UnitParser.cc b/unit_tests/ex_UnitParser.cc
index 43613db..b146196 100644
--- a/unit_tests/ex_UnitParser.cc
+++ b/unit_tests/ex_UnitParser.cc
@@ -36,8 +36,8 @@ using swoc::Rv;
class UnitParser {
using self_type = UnitParser; ///< Self reference type.
public:
- using value_type = uintmax_t; ///< Integral type returned.
- using Units = swoc::Lexicon<value_type>; ///< Unit definition type.
+ using value_type = uintmax_t; ///< Integral type returned.
+ using Units = swoc::Lexicon<value_type>; ///< Unit definition type.
/// Symbolic name for setting whether units are required.
static constexpr bool UNITS_REQUIRED = true;
@@ -49,38 +49,42 @@ public:
* @param units A @c Lexicon of unit definitions.
* @param unit_required_p Whether valid input requires units on all values.
*/
- UnitParser(Units && units, bool unit_required_p = true) noexcept;
+ UnitParser(Units &&units, bool unit_required_p = true) noexcept;
/** Set whether a unit is required.
*
* @param flag @c true if a unit is required, @c false if not.
* @return @a this.
*/
- self_type & unit_required(bool flag);
+ self_type &unit_required(bool flag);
/** Parse a string.
*
* @param src Input string.
* @return The computed value if the input it valid, or an error report.
*/
- Rv<value_type> operator() (swoc::TextView const& src) const noexcept;
+ Rv<value_type> operator()(swoc::TextView const &src) const noexcept;
+
protected:
bool _unit_required_p = true; ///< Whether unitless values are allowed.
- Units _units; ///< Unit definitions.
+ Units _units; ///< Unit definitions.
};
-UnitParser::UnitParser(UnitParser::Units&& units, bool unit_required_p) noexcept : _unit_required_p(unit_required_p), _units(std::move(units)) {
+UnitParser::UnitParser(UnitParser::Units &&units, bool unit_required_p) noexcept
+ : _unit_required_p(unit_required_p), _units(std::move(units)) {
_units.set_default(value_type{0}); // Used to check for bad unit names.
}
-UnitParser::self_type& UnitParser::unit_required(bool flag) {
+UnitParser::self_type &
+UnitParser::unit_required(bool flag) {
_unit_required_p = false;
return *this;
}
-auto UnitParser::operator()(swoc::TextView const& src) const noexcept -> Rv<value_type> {
+auto
+UnitParser::operator()(swoc::TextView const &src) const noexcept -> Rv<value_type> {
value_type zret = 0;
- TextView text = src; // Keep @a src around to report error offsets.
+ TextView text = src; // Keep @a src around to report error offsets.
while (text.ltrim_if(&isspace)) {
TextView parsed;
@@ -93,7 +97,7 @@ auto UnitParser::operator()(swoc::TextView const& src) const noexcept -> Rv<valu
text.remove_prefix(parsed.size());
auto ptr = text.ltrim_if(&isspace).data(); // save for error reporting.
// Everything up to the next digit or whitespace.
- auto unit = text.clip_prefix_of([](char c) { return !(isspace(c) || isdigit(c)); } );
+ auto unit = text.clip_prefix_of([](char c) { return !(isspace(c) || isdigit(c)); });
if (unit.empty()) {
if (_unit_required_p) {
return Errata("Required unit not found at offset {}", ptr - src.data());
@@ -113,17 +117,11 @@ auto UnitParser::operator()(swoc::TextView const& src) const noexcept -> Rv<valu
// --- Tests ---
TEST_CASE("UnitParser Bytes", "[Lexicon][UnitParser]") {
- UnitParser bytes{
- UnitParser::Units{
- {
- {1, {"B", "bytes"}}
- , {1024, {"K", "KB", "kilo", "kilobyte", "kilobytes"}}
- , {1048576, {"M", "MB", "mega", "megabyte", "megabytes"}}
- , {1 << 30, {"G", "GB", "giga", "gigabyte", "gigabytes"}}
- }
- }
- , UnitParser::UNITS_NOT_REQUIRED
- };
+ UnitParser bytes{UnitParser::Units{{{1, {"B", "bytes"}},
+ {1024, {"K", "KB", "kilo", "kilobyte", "kilobytes"}},
+ {1048576, {"M", "MB", "mega", "megabyte", "megabytes"}},
+ {1 << 30, {"G", "GB", "giga", "gigabyte", "gigabytes"}}}},
+ UnitParser::UNITS_NOT_REQUIRED};
REQUIRE(bytes("56 bytes") == 56);
REQUIRE(bytes("3 kb") == 3 * (1 << 10));
@@ -135,8 +133,8 @@ TEST_CASE("UnitParser Bytes", "[Lexicon][UnitParser]") {
REQUIRE(bytes("111") == 111);
REQUIRE(bytes("4MB") == 4 * (uintmax_t(1) << 20));
REQUIRE(bytes("4 giga") == 4 * (uintmax_t(1) << 30));
- REQUIRE(bytes("10M 256K 512") == 10 * (1<<20) + 256*(1<<10) + 512);
- REQUIRE(bytes("512 256 kilobytes 10 megabytes") == 10 * (1<<20) + 256*(1<<10) + 512);
+ REQUIRE(bytes("10M 256K 512") == 10 * (1 << 20) + 256 * (1 << 10) + 512);
+ REQUIRE(bytes("512 256 kilobytes 10 megabytes") == 10 * (1 << 20) + 256 * (1 << 10) + 512);
REQUIRE(bytes("0x100000000") == 0x100000000);
auto result = bytes("56delain");
REQUIRE(result.is_ok() == false);
@@ -151,23 +149,17 @@ TEST_CASE("UnitParser Bytes", "[Lexicon][UnitParser]") {
TEST_CASE("UnitParser Time", "[Lexicon][UnitParser]") {
using namespace std::chrono;
- UnitParser time {
- UnitParser::Units{
- {
- {nanoseconds{1}.count(), {"ns", "nanosec", "nanoseconds" }}
- , {nanoseconds{microseconds{1}}.count(), {"us", "microsec", "microseconds"}}
- , {nanoseconds{milliseconds{1}}.count(), {"ms", "millisec", "milliseconds"}}
- , {nanoseconds{seconds{1}}.count(), {"s", "sec", "seconds"}}
- , {nanoseconds{minutes{1}}.count(), {"m", "min", "minutes"}}
- , {nanoseconds{hours{1}}.count(), {"h", "hour", "hours"}}
- , {nanoseconds{hours{24}}.count(), {"d", "day", "days"}}
- , {nanoseconds{hours{168}}.count(), {"w", "week", "weeks"}}
- }
- }
- };
+ UnitParser time{UnitParser::Units{{{nanoseconds{1}.count(), {"ns", "nanosec", "nanoseconds"}},
+ {nanoseconds{microseconds{1}}.count(), {"us", "microsec", "microseconds"}},
+ {nanoseconds{milliseconds{1}}.count(), {"ms", "millisec", "milliseconds"}},
+ {nanoseconds{seconds{1}}.count(), {"s", "sec", "seconds"}},
+ {nanoseconds{minutes{1}}.count(), {"m", "min", "minutes"}},
+ {nanoseconds{hours{1}}.count(), {"h", "hour", "hours"}},
+ {nanoseconds{hours{24}}.count(), {"d", "day", "days"}},
+ {nanoseconds{hours{168}}.count(), {"w", "week", "weeks"}}}}};
REQUIRE(nanoseconds{time("2s")} == seconds{2});
- REQUIRE(nanoseconds{time("1w 2days 12 hours")} == hours{168} + hours{2*24} + hours{12});
+ REQUIRE(nanoseconds{time("1w 2days 12 hours")} == hours{168} + hours{2 * 24} + hours{12});
REQUIRE(nanoseconds{time("300ms")} == milliseconds{300});
REQUIRE(nanoseconds{time("1h30m")} == hours{1} + minutes{30});
@@ -180,7 +172,9 @@ TEST_CASE("UnitParser Time", "[Lexicon][UnitParser]") {
}
TEST_CASE("UnitParser Eggs", "[Lexicon][UnitParser]") {
- const UnitParser eggs{UnitParser::Units{UnitParser::Units::with_multi{ {1, { "egg", "eggs"}}, {12, {"dozen"} }, {12 * 12, { "gross" }}}}, UnitParser::UNITS_NOT_REQUIRED};
+ const UnitParser eggs{
+ UnitParser::Units{UnitParser::Units::with_multi{{1, {"egg", "eggs"}}, {12, {"dozen"}}, {12 * 12, {"gross"}}}},
+ UnitParser::UNITS_NOT_REQUIRED};
REQUIRE(eggs("1") == 1);
REQUIRE(eggs("6") == 6);
diff --git a/unit_tests/ex_bw_format.cc b/unit_tests/ex_bw_format.cc
index df3de82..4291bd6 100644
--- a/unit_tests/ex_bw_format.cc
+++ b/unit_tests/ex_bw_format.cc
@@ -38,8 +38,7 @@ using swoc::LocalBufferWriter;
static constexpr TextView VERSION{"1.0.2"};
-TEST_CASE("BWFormat substrings", "[swoc][bwf][substr]")
-{
+TEST_CASE("BWFormat substrings", "[swoc][bwf][substr]") {
LocalBufferWriter<256> bw;
std::string_view text{"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
@@ -63,15 +62,13 @@ TEST_CASE("BWFormat substrings", "[swoc][bwf][substr]")
REQUIRE(bw.view() == "Text: |QRSTUVWXYZ|");
}
-namespace
-{
+namespace {
static constexpr std::string_view NA{"N/A"};
// Define some global generators
BufferWriter &
-BWF_Timestamp(BufferWriter &w, Spec const &spec)
-{
+BWF_Timestamp(BufferWriter &w, Spec const &spec) {
auto now = std::chrono::system_clock::now();
auto epoch = std::chrono::system_clock::to_time_t(now);
LocalBufferWriter<48> lw;
@@ -84,20 +81,17 @@ BWF_Timestamp(BufferWriter &w, Spec const &spec)
}
BufferWriter &
-BWF_Now(BufferWriter &w, Spec const &spec)
-{
+BWF_Now(BufferWriter &w, Spec const &spec) {
return swoc::bwf::Format_Integer(w, spec, std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()), false);
}
BufferWriter &
-BWF_Version(BufferWriter &w, Spec const &spec)
-{
+BWF_Version(BufferWriter &w, Spec const &spec) {
return bwformat(w, spec, VERSION);
}
BufferWriter &
-BWF_EvilDave(BufferWriter &w, Spec const &spec)
-{
+BWF_EvilDave(BufferWriter &w, Spec const &spec) {
return bwformat(w, spec, "Evil Dave");
}
@@ -113,23 +107,26 @@ struct Context {
std::string tls_version{"tls/1.2"};
std::string ip_family{"ipv4"};
std::string ip_remote{"172.99.80.70"};
- Fields http_fields = {{{"Host", "docs.solidwallofcode.com"},
- {"YRP", "10.28.56.112"},
- {"Connection", "keep-alive"},
- {"Age", "956"},
- {"ETag", "1337beef"}}};
+ Fields http_fields = {
+ {{"Host", "docs.solidwallofcode.com"},
+ {"YRP", "10.28.56.112"},
+ {"Connection", "keep-alive"},
+ {"Age", "956"},
+ {"ETag", "1337beef"}}
+ };
static inline std::string A{"A"};
static inline std::string alpha{"alpha"};
static inline std::string B{"B"};
static inline std::string bravo{"bravo"};
- Fields cookie_fields = {{{A, alpha}, {B, bravo}}};
+ Fields cookie_fields = {
+ {{A, alpha}, {B, bravo}}
+ };
};
} // namespace
void
-EX_BWF_Format_Init()
-{
+EX_BWF_Format_Init() {
swoc::bwf::Global_Names.assign("timestamp", &BWF_Timestamp);
swoc::bwf::Global_Names.assign("now", &BWF_Now);
swoc::bwf::Global_Names.assign("version", &BWF_Version);
@@ -137,8 +134,7 @@ EX_BWF_Format_Init()
}
// Work with external / global names.
-TEST_CASE("BufferWriter Example", "[bufferwriter][example]")
-{
+TEST_CASE("BufferWriter Example", "[bufferwriter][example]") {
LocalBufferWriter<256> w;
w.clear();
@@ -149,8 +145,7 @@ TEST_CASE("BufferWriter Example", "[bufferwriter][example]")
REQUIRE(w.size() > 12);
}
-TEST_CASE("BufferWriter Context Simple", "[bufferwriter][example][context]")
-{
+TEST_CASE("BufferWriter Context Simple", "[bufferwriter][example][context]") {
// Container for name bindings.
using CookieBinding = swoc::bwf::ContextNames<Context const>;
@@ -201,15 +196,13 @@ TEST_CASE("BufferWriter Context Simple", "[bufferwriter][example][context]")
REQUIRE(w.view() == "Potzrebie is N/A");
};
-TEST_CASE("BufferWriter Context 2", "[bufferwriter][example][context]")
-{
+TEST_CASE("BufferWriter Context 2", "[bufferwriter][example][context]") {
LocalBufferWriter<1024> w;
// Add field based access as methods to the base context.
struct ExContext : public Context {
void
- field_gen(BufferWriter &w, Spec const &spec, TextView const &field) const
- {
+ field_gen(BufferWriter &w, Spec const &spec, TextView const &field) const {
if (auto spot = http_fields.find(field); spot != http_fields.end()) {
bwformat(w, spec, spot->second);
} else {
@@ -218,8 +211,7 @@ TEST_CASE("BufferWriter Context 2", "[bufferwriter][example][context]")
};
void
- cookie_gen(BufferWriter &w, Spec const &spec, TextView const &tag) const
- {
+ cookie_gen(BufferWriter &w, Spec const &spec, TextView const &tag) const {
if (auto spot = cookie_fields.find(tag); spot != cookie_fields.end()) {
bwformat(w, spec, spot->second);
} else {
@@ -231,16 +223,14 @@ TEST_CASE("BufferWriter Context 2", "[bufferwriter][example][context]")
// Container for name bindings.
// Override the name lookup to handle structured names.
- class CookieBinding : public swoc::bwf::ContextNames<ExContext const>
- {
+ class CookieBinding : public swoc::bwf::ContextNames<ExContext const> {
using super_type = swoc::bwf::ContextNames<ExContext const>;
public:
// Intercept name dispatch to check for structured names and handle those. If not structured,
// chain up to super class to dispatch normally.
BufferWriter &
- operator()(BufferWriter &w, Spec const &spec, ExContext const &ctx) const override
- {
+ operator()(BufferWriter &w, Spec const &spec, ExContext const &ctx) const override {
// Structured name prefixes.
static constexpr TextView FIELD_TAG{"field"};
static constexpr TextView COOKIE_TAG{"cookie"};
@@ -292,8 +282,7 @@ TEST_CASE("BufferWriter Context 2", "[bufferwriter][example][context]")
REQUIRE(w.view() == "Align: | docs.solidwallofcode.com|");
};
-namespace
-{
+namespace {
// Alternate format string parsing.
// This is the extractor, an instance of which is passed to the formatting logic.
struct AltFormatEx {
@@ -312,14 +301,12 @@ struct AltFormatEx {
AltFormatEx::AltFormatEx(TextView fmt) : _fmt{fmt} {}
// The extractor is empty if the format string is empty.
-AltFormatEx::operator bool() const
-{
+AltFormatEx::operator bool() const {
return !_fmt.empty();
}
bool
-AltFormatEx::operator()(std::string_view &literal, swoc::bwf::Spec &spec)
-{
+AltFormatEx::operator()(std::string_view &literal, swoc::bwf::Spec &spec) {
if (_fmt.size()) { // data left.
literal = _fmt.take_prefix_at('%');
if (_fmt.empty()) { // no '%' found, it's all literal, we're done.
@@ -357,8 +344,7 @@ AltFormatEx::operator()(std::string_view &literal, swoc::bwf::Spec &spec)
} // namespace
-TEST_CASE("bwf alternate syntax", "[libswoc][bwf][alternate]")
-{
+TEST_CASE("bwf alternate syntax", "[libswoc][bwf][alternate]") {
using BW = BufferWriter;
using AltNames = swoc::bwf::ContextNames<Context>;
AltNames names;
@@ -422,8 +408,7 @@ TEST_CASE("bwf alternate syntax", "[libswoc][bwf][alternate]")
* w.print_v(C_Format(fmt), std::forward_as_tuple(args));
* @endcode
*/
-class C_Format
-{
+class C_Format {
public:
/// Construct for @a fmt.
C_Format(TextView const &fmt);
@@ -449,16 +434,14 @@ protected:
inline C_Format::C_Format(TextView const &fmt) : _fmt(fmt) {}
// C_Format operator bool
-inline C_Format::operator bool() const
-{
+inline C_Format::operator bool() const {
return _saved_p || !_fmt.empty();
}
// C_Format operator bool
// C_Format capture
void
-C_Format::capture(BufferWriter &, Spec const &spec, std::any const &value)
-{
+C_Format::capture(BufferWriter &, Spec const &spec, std::any const &value) {
unsigned v;
if (typeid(int *) == value.type())
v = static_cast<unsigned>(*std::any_cast<int *>(value));
@@ -479,8 +462,7 @@ C_Format::capture(BufferWriter &, Spec const &spec, std::any const &value)
// C_Format parsing
bool
-C_Format::operator()(std::string_view &literal, Spec &spec)
-{
+C_Format::operator()(std::string_view &literal, Spec &spec) {
TextView parsed;
// clean up any old business from a previous specifier.
@@ -617,12 +599,10 @@ C_Format::operator()(std::string_view &literal, Spec &spec)
return false;
}
-namespace
-{
+namespace {
template <typename... Args>
int
-bwprintf(BufferWriter &w, TextView const &fmt, Args &&... args)
-{
+bwprintf(BufferWriter &w, TextView const &fmt, Args &&...args) {
size_t n = w.size();
w.print_nfv(swoc::bwf::NilBinding(), C_Format(fmt), swoc::bwf::ArgTuple{std::forward_as_tuple(args...)});
return static_cast<int>(w.size() - n);
@@ -630,8 +610,7 @@ bwprintf(BufferWriter &w, TextView const &fmt, Args &&... args)
} // namespace
-TEST_CASE("bwf printf", "[libswoc][bwf][printf]")
-{
+TEST_CASE("bwf printf", "[libswoc][bwf][printf]") {
// C_Format tests
LocalBufferWriter<256> w;
@@ -667,8 +646,7 @@ struct As_Rot13 {
};
BufferWriter &
-bwformat(BufferWriter &w, Spec const &spec, As_Rot13 const &wrap)
-{
+bwformat(BufferWriter &w, Spec const &spec, As_Rot13 const &wrap) {
static constexpr auto rot13 = [](char c) -> char {
return islower(c) ? (c + 13 - 'a') % 26 + 'a' : isupper(c) ? (c + 13 - 'A') % 26 + 'A' : c;
};
@@ -676,8 +654,7 @@ bwformat(BufferWriter &w, Spec const &spec, As_Rot13 const &wrap)
}
As_Rot13
-Rotter(std::string_view const &sv)
-{
+Rotter(std::string_view const &sv) {
return As_Rot13(sv);
}
@@ -687,13 +664,11 @@ struct Thing {
};
As_Rot13
-Rotter(Thing const &thing)
-{
+Rotter(Thing const &thing) {
return As_Rot13(thing._name);
}
-TEST_CASE("bwf wrapper", "[libswoc][bwf][wrapper]")
-{
+TEST_CASE("bwf wrapper", "[libswoc][bwf][wrapper]") {
LocalBufferWriter<256> w;
std::string_view s1{"Frcvqru"};
diff --git a/unit_tests/ex_ipspace_properties.cc b/unit_tests/ex_ipspace_properties.cc
index 7d610c2..8db96fe 100644
--- a/unit_tests/ex_ipspace_properties.cc
+++ b/unit_tests/ex_ipspace_properties.cc
@@ -39,12 +39,12 @@ using W = swoc::LocalBufferWriter<256>;
namespace {
bool Verbose_p =
#if VERBOSE_EXAMPLE_OUTPUT
- true
+ true
#else
- false
+ false
#endif
- ;
-}
+ ;
+} // namespace
TEST_CASE("IPSpace bitset blending", "[libswoc][ipspace][bitset][blending]") {
// Color each address with a set of bits.
@@ -55,10 +55,10 @@ TEST_CASE("IPSpace bitset blending", "[libswoc][ipspace][bitset][blending]") {
using Data = std::tuple<TextView, PAYLOAD>;
// Dump the ranges to stdout.
- auto dump = [](Space&space) -> void {
+ auto dump = [](Space &space) -> void {
if (Verbose_p) {
std::cout << W().print("{} ranges\n", space.count());
- for (auto && [r, payload] : space) {
+ for (auto &&[r, payload] : space) {
std::cout << W().print("{:25} : {}\n", r, payload);
}
}
@@ -74,13 +74,13 @@ TEST_CASE("IPSpace bitset blending", "[libswoc][ipspace][bitset][blending]") {
};
// Bitset blend functor which computes a union of the bitsets.
- auto blender = [](PAYLOAD& lhs, PAYLOAD const& rhs) -> bool {
+ auto blender = [](PAYLOAD &lhs, PAYLOAD const &rhs) -> bool {
lhs |= rhs;
return true;
};
// Example marking functor.
- auto marker = [&](Space & space, swoc::MemSpan<Data> ranges) -> void {
+ auto marker = [&](Space &space, swoc::MemSpan<Data> ranges) -> void {
// For each test range, compute the bitset from the list of bit indices.
for (auto &&[text, bits] : ranges) {
space.blend(IPRange{text}, bits, blender);
@@ -91,63 +91,60 @@ TEST_CASE("IPSpace bitset blending", "[libswoc][ipspace][bitset][blending]") {
Space space;
// test ranges 1
- std::array<Data, 7> ranges_1 = {{
- { "100.0.0.0-100.0.0.255", make_bits({ 0 }) }
- , { "100.0.1.0-100.0.1.255", make_bits({ 1 }) }
- , { "100.0.2.0-100.0.2.255", make_bits({ 2 }) }
- , { "100.0.3.0-100.0.3.255", make_bits({ 3 }) }
- , { "100.0.4.0-100.0.4.255", make_bits({ 4 }) }
- , { "100.0.5.0-100.0.5.255", make_bits({ 5 }) }
- , { "100.0.6.0-100.0.6.255", make_bits({ 6 }) }
- }};
+ std::array<Data, 7> ranges_1 = {
+ {{"100.0.0.0-100.0.0.255", make_bits({0})},
+ {"100.0.1.0-100.0.1.255", make_bits({1})},
+ {"100.0.2.0-100.0.2.255", make_bits({2})},
+ {"100.0.3.0-100.0.3.255", make_bits({3})},
+ {"100.0.4.0-100.0.4.255", make_bits({4})},
+ {"100.0.5.0-100.0.5.255", make_bits({5})},
+ {"100.0.6.0-100.0.6.255", make_bits({6})}}
+ };
marker(space, MemSpan<Data>{ranges_1.data(), ranges_1.size()});
dump(space);
// test ranges 2
- std::array<Data, 3> ranges_2 = {{
- { "100.0.0.0-100.0.0.255", make_bits({ 31 }) }
- , { "100.0.1.0-100.0.1.255", make_bits({ 30 }) }
- , { "100.0.2.128-100.0.3.127", make_bits({ 29 }) }
- }};
+ std::array<Data, 3> ranges_2 = {
+ {{"100.0.0.0-100.0.0.255", make_bits({31})},
+ {"100.0.1.0-100.0.1.255", make_bits({30})},
+ {"100.0.2.128-100.0.3.127", make_bits({29})}}
+ };
marker(space, MemSpan<Data>{ranges_2.data(), ranges_2.size()});
dump(space);
// test ranges 3
- std::array<Data, 1> ranges_3 = {{
- { "100.0.2.0-100.0.4.255", make_bits({ 2, 3, 29 })}
- }};
+ std::array<Data, 1> ranges_3 = {{{"100.0.2.0-100.0.4.255", make_bits({2, 3, 29})}}};
marker(space, MemSpan<Data>{ranges_3.data(), ranges_3.size()});
dump(space);
// reset blend functor
- auto resetter = [](PAYLOAD& lhs, PAYLOAD const& rhs) -> bool {
- auto mask = rhs;
- lhs &= mask.flip();
+ auto resetter = [](PAYLOAD &lhs, PAYLOAD const &rhs) -> bool {
+ auto mask = rhs;
+ lhs &= mask.flip();
return lhs != 0;
};
// erase bits
- space.blend(IPRange{"0.0.0.0-255.255.255.255"}, make_bits({2,3,29}), resetter);
+ space.blend(IPRange{"0.0.0.0-255.255.255.255"}, make_bits({2, 3, 29}), resetter);
dump(space);
// ragged boundaries
- space.blend(IPRange{"100.0.2.19-100.0.5.117"}, make_bits({16,18,20}), blender);
+ space.blend(IPRange{"100.0.2.19-100.0.5.117"}, make_bits({16, 18, 20}), blender);
dump(space);
// bit list blend functor which computes a union of the bitsets.
- auto bit_blender = [](PAYLOAD& lhs, std::initializer_list<unsigned> const& rhs) -> bool {
- for ( auto idx : rhs )
+ auto bit_blender = [](PAYLOAD &lhs, std::initializer_list<unsigned> const &rhs) -> bool {
+ for (auto idx : rhs)
lhs[idx] = true;
return true;
};
- std::initializer_list<unsigned> bit_list = { 10,11 };
+ std::initializer_list<unsigned> bit_list = {10, 11};
space.blend(IPRange{"0.0.0.1-255.255.255.254"}, bit_list, bit_blender);
dump(space);
-
}
// ---
@@ -173,7 +170,7 @@ public:
*
* @param name Property name.
*/
- Property(TextView const& name) : _name(name) {};
+ Property(TextView const &name) : _name(name){};
/// Force virtual destructor.
virtual ~Property() = default;
@@ -188,7 +185,10 @@ public:
*
* @return The column index.
*/
- unsigned idx() const { return _idx; }
+ unsigned
+ idx() const {
+ return _idx;
+ }
/** Token persistence.
*
@@ -198,10 +198,16 @@ public:
* itself needs to be persistent for the lifetime of the table, this must be overridden to
* return @c true.
*/
- virtual bool needs_localized_token() const { return false; }
+ virtual bool
+ needs_localized_token() const {
+ return false;
+ }
/// @return The row data offset in bytes for this property.
- size_t offset() const { return _offset; }
+ size_t
+ offset() const {
+ return _offset;
+ }
/** Parse the @a token.
*
@@ -218,9 +224,9 @@ public:
protected:
friend class Table;
- TextView _name; ///< Name of the property.
- unsigned _idx = std::numeric_limits<unsigned>::max(); ///< Column index.
- size_t _offset = std::numeric_limits<size_t>::max(); ///< Offset into a row.
+ TextView _name; ///< Name of the property.
+ unsigned _idx = std::numeric_limits<unsigned>::max(); ///< Column index.
+ size_t _offset = std::numeric_limits<size_t>::max(); ///< Offset into a row.
/** Set the column index.
*
@@ -229,7 +235,11 @@ public:
*
* This is called from @c Table to indicate the column index.
*/
- self_type & assign_idx(unsigned idx) { _idx = idx; return *this; }
+ self_type &
+ assign_idx(unsigned idx) {
+ _idx = idx;
+ return *this;
+ }
/** Set the row data @a offset.
*
@@ -238,7 +248,11 @@ public:
*
* This is called from @c Table to store the row data offset.
*/
- self_type & assign_offset(size_t offset) { _offset = offset; return *this; }
+ self_type &
+ assign_offset(size_t offset) {
+ _offset = offset;
+ return *this;
+ }
};
/// Construct an empty Table.
@@ -253,8 +267,7 @@ public:
* The @c Property instance must be owned by the @c Table because changes are made to it specific
* to this instance of @c Table.
*/
- template < typename P >
- P * add_column(std::unique_ptr<P> && col);
+ template <typename P> P *add_column(std::unique_ptr<P> &&col);
/// A row in the table.
class Row {
@@ -267,7 +280,7 @@ public:
* @param prop Property that defines the data.
* @return The range of bytes in the row for @a prop.
*/
- MemSpan<std::byte> span_for(Property const& prop) const;
+ MemSpan<std::byte> span_for(Property const &prop) const;
protected:
MemSpan<std::byte> _data; ///< Raw row data.
@@ -289,17 +302,23 @@ public:
* @param addr Address to find.
* @return A @c Row for the address, or @c nullptr if not found.
*/
- Row* find(IPAddr const& addr);
+ Row *find(IPAddr const &addr);
/// @return The number of ranges in the container.
- size_t size() const { return _space.count(); }
+ size_t
+ size() const {
+ return _space.count();
+ }
/** Property for column @a idx.
*
* @param idx Index.
* @return The property.
*/
- Property * column(unsigned idx) { return _columns[idx].get(); }
+ Property *
+ column(unsigned idx) {
+ return _columns[idx].get();
+ }
protected:
size_t _size = 0; ///< Size of row data.
@@ -317,7 +336,7 @@ protected:
* @param line Current line [in,out]
* @return Extracted token.
*/
- TextView token(TextView & line);
+ TextView token(TextView &line);
/** Localize view.
*
@@ -326,32 +345,35 @@ protected:
*
* This copies @a src to the internal @c MemArena and returns a view of the copied data.
*/
- TextView localize(TextView const& src);
+ TextView localize(TextView const &src);
};
-template < typename P >
-P * Table::add_column(std::unique_ptr<P> &&col) {
+template <typename P>
+P *
+Table::add_column(std::unique_ptr<P> &&col) {
auto prop = col.get();
- auto idx = _columns.size();
+ auto idx = _columns.size();
col->assign_offset(_size);
col->assign_idx(idx);
- _size += static_cast<Property*>(prop)->size();
+ _size += static_cast<Property *>(prop)->size();
_columns.emplace_back(std::move(col));
return prop;
}
-TextView Table::localize(TextView const&src) {
+TextView
+Table::localize(TextView const &src) {
auto span = _arena.alloc(src.size()).rebind<char>();
memcpy(span, src);
return span;
}
-TextView Table::token(TextView & line) {
+TextView
+Table::token(TextView &line) {
TextView::size_type idx = 0;
// Characters of interest.
- static char constexpr separators[2] = { '"', SEP };
- static TextView sep_list { separators, 2 };
- bool in_quote_p = false;
+ 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.
idx = line.find_first_of(sep_list, idx);
@@ -361,7 +383,7 @@ TextView Table::token(TextView & line) {
in_quote_p = !in_quote_p;
++idx;
} else if (SEP == line[idx]) { // separator.
- if (in_quote_p) { // quoted separator, skip and continue.
+ if (in_quote_p) { // quoted separator, skip and continue.
++idx;
} else { // found token, finish up.
break;
@@ -374,7 +396,8 @@ TextView Table::token(TextView & line) {
return zret;
}
-bool Table::parse(TextView src) {
+bool
+Table::parse(TextView src) {
unsigned line_no = 0;
while (src) {
auto line = src.take_prefix_at('\n').ltrim_if(&isspace);
@@ -392,13 +415,13 @@ bool Table::parse(TextView src) {
}
auto span = _arena.alloc(_size).rebind<std::byte>(); // need this broken out.
- Row row{span}; // store the original span to preserve it.
- for ( auto const& col : _columns) {
+ Row row{span}; // store the original span to preserve it.
+ for (auto const &col : _columns) {
auto token = this->token(line);
if (col->needs_localized_token()) {
token = this->localize(token);
}
- if (! col->parse(token, span.subspan(0, col->size()))) {
+ if (!col->parse(token, span.subspan(0, col->size()))) {
std::cout << W().print("Value \"{}\" at index {} on line {} is invalid.", token, col->idx(), line_no);
}
// drop reference to storage used by this column.
@@ -409,14 +432,19 @@ bool Table::parse(TextView src) {
return true;
}
-auto Table::find(IPAddr const &addr) -> Row * {
+auto
+Table::find(IPAddr const &addr) -> Row * {
auto spot = _space.find(addr);
return spot == _space.end() ? nullptr : &(spot->payload());
}
-bool operator == (Table::Row const&, Table::Row const&) { return false; }
+bool
+operator==(Table::Row const &, Table::Row const &) {
+ return false;
+}
-MemSpan<std::byte> Table::Row::span_for(Table::Property const&prop) const {
+MemSpan<std::byte>
+Table::Row::span_for(Table::Property const &prop) const {
return _data.subspan(prop.offset(), prop.size());
}
@@ -426,8 +454,8 @@ MemSpan<std::byte> Table::Row::span_for(Table::Property const&prop) const {
* The set of keys must be specified at construction, keys not in the list are invalid.
*/
class FlagGroupProperty : public Table::Property {
- using self_type = FlagGroupProperty; ///< Self reference type.
- using super_type = Table::Property; ///< Parent type.
+ using self_type = FlagGroupProperty; ///< Self reference type.
+ using super_type = Table::Property; ///< Parent type.
public:
/** Construct with a @a name and a list of @a tags.
*
@@ -437,7 +465,7 @@ public:
* Input tokens must consist of lists of tokens, each of which is one of the @a tags.
* This is stored so that the exact set of tags present can be retrieved.
*/
- FlagGroupProperty(TextView const& name, std::initializer_list<TextView> tags);
+ FlagGroupProperty(TextView const &name, std::initializer_list<TextView> tags);
/** Check for a tag being present.
*
@@ -445,7 +473,7 @@ public:
* @param row Row data from the @c Table.
* @return @c true if the tag was present, @c false if not.
*/
- bool is_set(Table::Row const&row, unsigned idx) const;
+ bool is_set(Table::Row const &row, unsigned idx) const;
protected:
size_t size() const override; ///< Storeage required in a row.
@@ -467,19 +495,23 @@ protected:
* accumulated as needed. The property supports a maximum of 255 distinct tags.
*/
class EnumProperty : public Table::Property {
- using self_type = EnumProperty; ///< Self reference type.
+ using self_type = EnumProperty; ///< Self reference type.
using super_type = Table::Property; ///< Parent type.
- using store_type = __uint8_t; ///< Row storage type.
+ using store_type = __uint8_t; ///< Row storage type.
public:
using super_type::super_type; ///< Inherit super type constructors.
/// @return The enumeration tag for this @a row.
- TextView operator() (Table::Row const& row) const;
+ TextView operator()(Table::Row const &row) const;
+
protected:
std::vector<TextView> _tags; ///< Tags in the enumeration.
/// @a return Size of required storage.
- size_t size() const override { return sizeof(store_type); }
+ size_t
+ size() const override {
+ return sizeof(store_type);
+ }
/** Parse a token.
*
@@ -491,42 +523,51 @@ protected:
};
class StringProperty : public Table::Property {
- using self_type = StringProperty;
+ using self_type = StringProperty;
using super_type = Table::Property;
+
public:
static constexpr size_t SIZE = sizeof(TextView);
using super_type::super_type;
protected:
- size_t size() const override { return SIZE; }
+ size_t
+ size() const override {
+ return SIZE;
+ }
bool parse(TextView token, MemSpan<std::byte> span) override;
- bool needs_localized_token() const override { return true; }
+ bool
+ needs_localized_token() const override {
+ return true;
+ }
};
// ---
-bool StringProperty::parse(TextView token, MemSpan<std::byte> span) {
+bool
+StringProperty::parse(TextView token, MemSpan<std::byte> span) {
memcpy(span.data(), &token, sizeof(token));
return true;
}
-FlagGroupProperty::FlagGroupProperty(TextView const& name, std::initializer_list<TextView> tags)
- : super_type(name)
-{
+FlagGroupProperty::FlagGroupProperty(TextView const &name, std::initializer_list<TextView> tags) : super_type(name) {
_tags.reserve(tags.size());
- for ( auto const& tag : tags ) {
+ for (auto const &tag : tags) {
_tags.emplace_back(tag);
}
}
-bool FlagGroupProperty::parse(TextView token, MemSpan<std::byte> span) {
- if ("-"_tv == token) { return true; } // marker for no flags.
+bool
+FlagGroupProperty::parse(TextView token, MemSpan<std::byte> span) {
+ if ("-"_tv == token) {
+ return true;
+ } // marker for no flags.
memset(span, 0);
while (token) {
- auto tag = token.take_prefix_at(';');
+ auto tag = token.take_prefix_at(';');
unsigned j = 0;
- for ( auto const& key : _tags ) {
+ for (auto const &key : _tags) {
if (0 == strcasecmp(key, tag)) {
- span[j/8] |= (std::byte{1} << (j % 8));
+ span[j / 8] |= (std::byte{1} << (j % 8));
break;
}
++j;
@@ -539,18 +580,21 @@ bool FlagGroupProperty::parse(TextView token, MemSpan<std::byte> span) {
return true;
}
-bool FlagGroupProperty::is_set(Table::Row const&row, unsigned idx) const {
+bool
+FlagGroupProperty::is_set(Table::Row const &row, unsigned idx) const {
auto sp = row.span_for(*this);
return std::byte{0} != ((sp[idx / 8] >> (idx % 8)) & std::byte{1});
}
-size_t FlagGroupProperty::size() const {
+size_t
+FlagGroupProperty::size() const {
return swoc::Scalar<8>(swoc::round_up(_tags.size())).count();
}
-bool EnumProperty::parse(TextView token, MemSpan<std::byte> span) {
+bool
+EnumProperty::parse(TextView token, MemSpan<std::byte> span) {
// Already got one?
- auto spot = std::find_if(_tags.begin(), _tags.end(), [&](TextView const& tag) { return 0 == strcasecmp(token, tag); });
+ auto spot = std::find_if(_tags.begin(), _tags.end(), [&](TextView const &tag) { return 0 == strcasecmp(token, tag); });
if (spot == _tags.end()) { // nope, add it to the list.
_tags.push_back(token);
spot = std::prev(_tags.end());
@@ -559,7 +603,8 @@ bool EnumProperty::parse(TextView token, MemSpan<std::byte> span) {
return true;
}
-TextView EnumProperty::operator()(Table::Row const& row) const {
+TextView
+EnumProperty::operator()(Table::Row const &row) const {
auto idx = row.span_for(*this).rebind<store_type>()[0];
return _tags[idx];
}
@@ -568,10 +613,10 @@ TextView EnumProperty::operator()(Table::Row const& row) const {
TEST_CASE("IPSpace properties", "[libswoc][ip][ex][properties]") {
Table table;
- auto flag_names = { "prod"_tv, "dmz"_tv, "internal"_tv};
- auto owner = table.add_column(std::make_unique<EnumProperty>("owner"));
- auto colo = table.add_column(std::make_unique<EnumProperty>("colo"));
- auto flags = table.add_column(std::make_unique<FlagGroupProperty>("flags"_tv, flag_names));
+ auto flag_names = {"prod"_tv, "dmz"_tv, "internal"_tv};
+ auto owner = table.add_column(std::make_unique<EnumProperty>("owner"));
+ auto colo = table.add_column(std::make_unique<EnumProperty>("colo"));
+ auto flags = table.add_column(std::make_unique<FlagGroupProperty>("flags"_tv, flag_names));
[[maybe_unused]] auto description = table.add_column(std::make_unique<StringProperty>("Description"));
TextView src = R"(10.1.1.0/24,asf,cmi,prod;internal,"ASF core net"
@@ -592,4 +637,3 @@ TEST_CASE("IPSpace properties", "[libswoc][ip][ex][properties]") {
REQUIRE(row != nullptr);
CHECK("abq"_tv == (*colo)(*row));
};
-
diff --git a/unit_tests/test_BufferWriter.cc b/unit_tests/test_BufferWriter.cc
index ae89d63..9eeee19 100644
--- a/unit_tests/test_BufferWriter.cc
+++ b/unit_tests/test_BufferWriter.cc
@@ -29,15 +29,12 @@
using swoc::TextView;
using swoc::MemSpan;
-namespace
-{
+namespace {
std::string_view three[] = {"a", "", "bcd"};
}
-TEST_CASE("BufferWriter::write(StringView)", "[BWWSV]")
-{
- class X : public swoc::BufferWriter
- {
+TEST_CASE("BufferWriter::write(StringView)", "[BWWSV]") {
+ class X : public swoc::BufferWriter {
size_t i, j;
public:
@@ -46,8 +43,7 @@ TEST_CASE("BufferWriter::write(StringView)", "[BWWSV]")
X() : i(0), j(0), good(true) {}
X &
- write(char c) override
- {
+ write(char c) override {
while (j == three[i].size()) {
++i;
j = 0;
@@ -63,35 +59,42 @@ TEST_CASE("BufferWriter::write(StringView)", "[BWWSV]")
}
bool
- error() const override
- {
+ error() const override {
return false;
}
// Dummies.
const char *
- data() const override
- {
+ data() const override {
return nullptr;
}
size_t
- capacity() const override
- {
+ capacity() const override {
return 0;
}
size_t
- extent() const override
- {
+ extent() const override {
return 0;
}
X &restrict(size_t) override { return *this; }
- X &restore(size_t) override { return *this; }
- bool commit(size_t) override { return true; }
- X &discard(size_t) override { return *this; }
- X ©(size_t, size_t, size_t) override { return *this; }
+ X &
+ restore(size_t) override {
+ return *this;
+ }
+ bool
+ commit(size_t) override {
+ return true;
+ }
+ X &
+ discard(size_t) override {
+ return *this;
+ }
+ X &
+ copy(size_t, size_t, size_t) override {
+ return *this;
+ }
std::ostream &
- operator>>(std::ostream &stream) const override
- {
+ operator>>(std::ostream &stream) const override {
return stream;
}
};
@@ -103,13 +106,11 @@ TEST_CASE("BufferWriter::write(StringView)", "[BWWSV]")
REQUIRE(x.good);
}
-namespace
-{
+namespace {
template <size_t N> using LBW = swoc::LocalBufferWriter<N>;
}
-TEST_CASE("Minimal Local Buffer Writer", "[BWLM]")
-{
+TEST_CASE("Minimal Local Buffer Writer", "[BWLM]") {
LBW<1> bw;
REQUIRE(!((bw.capacity() != 1) or (bw.size() != 0) or bw.error() or (bw.remaining() != 1)));
@@ -131,12 +132,10 @@ TEST_CASE("Minimal Local Buffer Writer", "[BWLM]")
REQUIRE(bw.view() == "#");
}
-namespace
-{
+namespace {
template <class BWType>
bool
-twice(BWType &bw)
-{
+twice(BWType &bw) {
if ((bw.capacity() != 20) or (bw.size() != 0) or bw.error() or (bw.remaining() != 20)) {
return false;
}
@@ -250,8 +249,7 @@ twice(BWType &bw)
} // end anonymous namespace
-TEST_CASE("Discard Buffer Writer", "[BWD]")
-{
+TEST_CASE("Discard Buffer Writer", "[BWD]") {
char scratch[1] = {'!'};
swoc::FixedBufferWriter bw(scratch, 0);
@@ -295,8 +293,7 @@ TEST_CASE("Discard Buffer Writer", "[BWD]")
REQUIRE(scratch[0] == '!');
}
-TEST_CASE("LocalBufferWriter discard/restore", "[BWD]")
-{
+TEST_CASE("LocalBufferWriter discard/restore", "[BWD]") {
swoc::LocalBufferWriter<10> bw;
bw.restrict(7);
@@ -316,10 +313,10 @@ TEST_CASE("Writing", "[BW]") {
swoc::LocalBufferWriter<1024> bw;
// Test run length encoding.
- TextView s1 = "Delain";
- TextView s2 = "Nightwish";
- uint8_t const r[] = { uint8_t(s1.size()), 'D', 'e', 'l', 'a', 'i', 'n'
- , uint8_t(s2.size()), 'N', 'i', 'g', 'h', 't', 'w','i','s','h' };
+ TextView s1 = "Delain";
+ TextView s2 = "Nightwish";
+ uint8_t const r[] = {
+ uint8_t(s1.size()), 'D', 'e', 'l', 'a', 'i', 'n', uint8_t(s2.size()), 'N', 'i', 'g', 'h', 't', 'w', 'i', 's', 'h'};
bw.print("{}{}{}{}", char(s1.size()), s1, char(s2.size()), s2);
auto result{swoc::MemSpan{bw.view()}.rebind<uint8_t const>()};
@@ -328,8 +325,7 @@ TEST_CASE("Writing", "[BW]") {
REQUIRE(MemSpan(r) == result);
}
-TEST_CASE("ArenaWriter write", "[BW][ArenaWriter]")
-{
+TEST_CASE("ArenaWriter write", "[BW][ArenaWriter]") {
swoc::MemArena arena{256};
swoc::ArenaWriter aw{arena};
std::array<char, 85> buffer;
@@ -351,8 +347,8 @@ TEST_CASE("ArenaWriter write", "[BW][ArenaWriter]")
// The allocated data should be identical to that in the writer.
REQUIRE(0 == memcmp(span.data(), aw.data(), span.size()));
- bool valid_p = true;
- auto tv = swoc::TextView(span.rebind<char>());
+ bool valid_p = true;
+ auto tv = swoc::TextView(span.rebind<char>());
try {
for (char c = 'a'; c <= 'z'; ++c) {
for (size_t i = 0; i < buffer.size(); ++i) {
@@ -367,8 +363,7 @@ TEST_CASE("ArenaWriter write", "[BW][ArenaWriter]")
REQUIRE(valid_p == true);
}
-TEST_CASE("ArenaWriter print", "[BW][ArenaWriter]")
-{
+TEST_CASE("ArenaWriter print", "[BW][ArenaWriter]") {
swoc::MemArena arena{256};
swoc::ArenaWriter aw{arena};
std::array<char, 85> buffer;
@@ -391,8 +386,8 @@ TEST_CASE("ArenaWriter print", "[BW][ArenaWriter]")
// The allocated data should be identical to that in the writer.
REQUIRE(0 == memcmp(span.data(), aw.data(), span.size()));
- bool valid_p = true;
- auto tv = swoc::TextView(span);
+ bool valid_p = true;
+ auto tv = swoc::TextView(span);
try {
for (char c = 'a'; c <= 'z'; ++c) {
for (size_t i = 0; i < buffer.size(); ++i) {
diff --git a/unit_tests/test_Errata.cc b/unit_tests/test_Errata.cc
index 070e291..acb41a0 100644
--- a/unit_tests/test_Errata.cc
+++ b/unit_tests/test_Errata.cc
@@ -25,37 +25,33 @@ static constexpr swoc::Errata::Severity ERRATA_INFO{2};
static constexpr swoc::Errata::Severity ERRATA_WARN{3};
static constexpr swoc::Errata::Severity ERRATA_ERROR{4};
-std::array<swoc::TextView, 5> Severity_Names { {
- "Debug", "Diag", "Info", "Warn", "Error"
-}};
+std::array<swoc::TextView, 5> Severity_Names{
+ {"Debug", "Diag", "Info", "Warn", "Error"}
+};
std::string ErrataSinkText;
// Call from unit test main before starting tests.
-void test_Errata_init() {
+void
+test_Errata_init() {
swoc::Errata::DEFAULT_SEVERITY = ERRATA_ERROR;
swoc::Errata::FAILURE_SEVERITY = ERRATA_WARN;
- swoc::Errata::SEVERITY_NAMES = swoc::MemSpan<swoc::TextView const>(Severity_Names.data(), Severity_Names.size());
+ swoc::Errata::SEVERITY_NAMES = swoc::MemSpan<swoc::TextView const>(Severity_Names.data(), Severity_Names.size());
- swoc::Errata::register_sink([](swoc::Errata const& errata) ->void {
- bwprint(ErrataSinkText, "{}", errata);
- });
+ swoc::Errata::register_sink([](swoc::Errata const &errata) -> void { bwprint(ErrataSinkText, "{}", errata); });
}
Errata
-Noteworthy(std::string_view text)
-{
+Noteworthy(std::string_view text) {
return Errata{ERRATA_INFO, text};
}
Errata
-cycle(Errata &erratum)
-{
+cycle(Errata &erratum) {
return std::move(erratum.note("Note well, young one!"));
}
-TEST_CASE("Errata copy", "[libswoc][Errata]")
-{
+TEST_CASE("Errata copy", "[libswoc][Errata]") {
auto notes = Noteworthy("Evil Dave Rulz.");
REQUIRE(notes.length() == 1);
REQUIRE(notes.begin()->text() == "Evil Dave Rulz.");
@@ -88,8 +84,7 @@ TEST_CASE("Errata copy", "[libswoc][Errata]")
REQUIRE(match_p);
};
-TEST_CASE("Rv", "[libswoc][Errata]")
-{
+TEST_CASE("Rv", "[libswoc][Errata]") {
Rv<int> zret;
struct Thing {
char const *s = "thing";
@@ -100,7 +95,7 @@ TEST_CASE("Rv", "[libswoc][Errata]")
zret = Errata(std::error_code(EINVAL, std::generic_category()), ERRATA_ERROR, "This is an error");
{
- auto & [result, erratum] = zret;
+ auto &[result, erratum] = zret;
REQUIRE(erratum.length() == 1);
REQUIRE(erratum.severity() == ERRATA_ERROR);
@@ -111,7 +106,7 @@ TEST_CASE("Rv", "[libswoc][Errata]")
}
{
- auto && [result, erratum] = zret;
+ auto &&[result, erratum] = zret;
REQUIRE(erratum.length() == 1);
REQUIRE(erratum.severity() == ERRATA_ERROR);
@@ -135,7 +130,6 @@ TEST_CASE("Rv", "[libswoc][Errata]")
test(ERRATA_ERROR, zret); // invoke it.
}
-
zret.clear();
REQUIRE(zret.result() == 56);
@@ -184,7 +178,7 @@ TEST_CASE("Rv", "[libswoc][Errata]")
handle->s = "other"; // mark it.
thing_rv = std::move(handle);
- thing_rv = Errata(ERRATA_WARN, "This is a warning");
+ thing_rv = Errata(ERRATA_WARN, "This is a warning");
auto &&[tr1, te1]{thing_rv};
REQUIRE(te1.length() == 1);
@@ -206,9 +200,9 @@ TEST_CASE("Rv", "[libswoc][Errata]")
};
// DOC -> NoteInfo
-template < typename ...Args >
-Errata&
-NoteInfo(Errata & errata, std::string_view fmt, Args ... args) {
+template <typename... Args>
+Errata &
+NoteInfo(Errata &errata, std::string_view fmt, Args... args) {
return errata.note_v(ERRATA_INFO, fmt, std::forward_as_tuple(args...));
}
// DOC -< NoteInfo
@@ -230,20 +224,21 @@ TEST_CASE("Errata API", "[libswoc][Errata]") {
// Check that if an int is expected from a function, it can be changed to
// @c Rv<int> without change at the call site.
int size = -7;
- auto f = [&] () -> Rv<int> {
- if (size > 0) return size;
- return { -1, Errata(ERRATA_ERROR, "No size, doofus!")};
+ auto f = [&]() -> Rv<int> {
+ if (size > 0)
+ return size;
+ return {-1, Errata(ERRATA_ERROR, "No size, doofus!")};
};
int r1 = f();
REQUIRE(r1 == -1);
- size = 10;
+ size = 10;
int r2 = f();
REQUIRE(r2 == 10);
}
TEST_CASE("Errata sink", "[libswoc][Errata]") {
- auto & s = ErrataSinkText;
+ auto &s = ErrataSinkText;
{
Errata errata{ERRATA_ERROR, "Nominal failure"};
NoteInfo(errata, "Some");
@@ -342,13 +337,16 @@ TEST_CASE("Errata glue", "[libswoc][Errata]") {
REQUIRE("Error -> First, Second, Third" == s);
}
-template < typename ... Args >
-Errata errata_errno(int err, Errata::Severity s, swoc::TextView fmt, Args && ... args) {
- return Errata(std::error_code(err, std::system_category()), s, "{} - {}", swoc::bwf::SubText(fmt, std::forward_as_tuple<Args...>(args...)), swoc::bwf::Errno(err));
+template <typename... Args>
+Errata
+errata_errno(int err, Errata::Severity s, swoc::TextView fmt, Args &&...args) {
+ return Errata(std::error_code(err, std::system_category()), s, "{} - {}",
+ swoc::bwf::SubText(fmt, std::forward_as_tuple<Args...>(args...)), swoc::bwf::Errno(err));
}
-template < typename ... Args >
-Errata errata_errno(Errata::Severity s, swoc::TextView fmt, Args && ... args) {
+template <typename... Args>
+Errata
+errata_errno(Errata::Severity s, swoc::TextView fmt, Args &&...args) {
return errata_errno(errno, s, fmt, std::forward<Args>(args)...);
}
@@ -357,7 +355,7 @@ TEST_CASE("Errata Wrapper", "[libswoc][errata]") {
TextView tv2 = "ni";
SECTION("no args") {
- errno = EPERM;
+ errno = EPERM;
auto errata = errata_errno(ERRATA_ERROR, "no args");
REQUIRE(errata.front().text().starts_with("no args - EPERM"));
}
@@ -373,7 +371,7 @@ TEST_CASE("Errata Wrapper", "[libswoc][errata]") {
}
SECTION("args") {
- errno = EINVAL;
+ errno = EINVAL;
auto errata = errata_errno(ERRATA_ERROR, "{} {}", tv2, tv1);
REQUIRE(errata.front().text().starts_with("ni itchi - EINVAL"));
}
diff --git a/unit_tests/test_IntrusiveDList.cc b/unit_tests/test_IntrusiveDList.cc
index b41b5b1..51f57a0 100644
--- a/unit_tests/test_IntrusiveDList.cc
+++ b/unit_tests/test_IntrusiveDList.cc
@@ -31,8 +31,7 @@
using swoc::IntrusiveDList;
using swoc::bwprint;
-namespace
-{
+namespace {
struct Thing {
std::string _payload;
Thing *_next{nullptr};
@@ -42,14 +41,12 @@ struct Thing {
struct Linkage {
static Thing *&
- next_ptr(Thing *t)
- {
+ next_ptr(Thing *t) {
return t->_next;
}
static Thing *&
- prev_ptr(Thing *t)
- {
+ prev_ptr(Thing *t) {
return t->_prev;
}
};
@@ -59,8 +56,7 @@ using ThingList = IntrusiveDList<Thing::Linkage>;
} // namespace
-TEST_CASE("IntrusiveDList", "[libswoc][IntrusiveDList]")
-{
+TEST_CASE("IntrusiveDList", "[libswoc][IntrusiveDList]") {
ThingList list;
int n;
@@ -136,7 +132,7 @@ TEST_CASE("IntrusiveDList list prefix", "[libswoc][IntrusiveDList]") {
ThingList list;
std::string tmp;
- for (unsigned idx = 1 ; idx <= 20 ; ++idx) {
+ for (unsigned idx = 1; idx <= 20; ++idx) {
list.append(new Thing(bwprint(tmp, "{}", idx)));
}
@@ -150,13 +146,13 @@ TEST_CASE("IntrusiveDList list prefix", "[libswoc][IntrusiveDList]") {
REQUIRE(list_none.head() == nullptr);
REQUIRE(list.count() == 20);
- auto v = list.head();
+ auto v = list.head();
auto list_1 = list.take_prefix(1);
REQUIRE(list_1.count() == 1);
REQUIRE(list_1.head() == v);
REQUIRE(list.count() == 19);
- v = list.head();
+ v = list.head();
auto list_5 = list.take_prefix(5);
REQUIRE(list_5.count() == 5);
REQUIRE(list_5.head() == v);
@@ -164,14 +160,14 @@ TEST_CASE("IntrusiveDList list prefix", "[libswoc][IntrusiveDList]") {
REQUIRE(list.head() != nullptr);
REQUIRE(list.head()->_payload == "7");
- v = list.head();
+ v = list.head();
auto list_most = list.take_prefix(9); // more than half.
REQUIRE(list_most.count() == 9);
REQUIRE(list_most.head() == v);
REQUIRE(list.count() == 5);
REQUIRE(list.head() != nullptr);
- v = list.head();
+ v = list.head();
auto list_rest = list.take_prefix(20);
REQUIRE(list_rest.count() == 5);
REQUIRE(list_rest.head() == v);
@@ -184,7 +180,7 @@ TEST_CASE("IntrusiveDList list suffix", "[libswoc][IntrusiveDList]") {
ThingList list;
std::string tmp;
- for (unsigned idx = 1 ; idx <= 20 ; ++idx) {
+ for (unsigned idx = 1; idx <= 20; ++idx) {
list.append(new Thing(bwprint(tmp, "{}", idx)));
}
@@ -193,13 +189,13 @@ TEST_CASE("IntrusiveDList list suffix", "[libswoc][IntrusiveDList]") {
REQUIRE(list_none.head() == nullptr);
REQUIRE(list.count() == 20);
- auto * v = list.tail();
+ auto *v = list.tail();
auto list_1 = list.take_suffix(1);
REQUIRE(list_1.count() == 1);
REQUIRE(list_1.tail() == v);
REQUIRE(list.count() == 19);
- v = list.tail();
+ v = list.tail();
auto list_5 = list.take_suffix(5);
REQUIRE(list_5.count() == 5);
REQUIRE(list_5.tail() == v);
@@ -207,14 +203,14 @@ TEST_CASE("IntrusiveDList list suffix", "[libswoc][IntrusiveDList]") {
REQUIRE(list.head() != nullptr);
REQUIRE(list.tail()->_payload == "14");
- v = list.tail();
+ v = list.tail();
auto list_most = list.take_suffix(9); // more than half.
REQUIRE(list_most.count() == 9);
REQUIRE(list_most.tail() == v);
REQUIRE(list.count() == 5);
REQUIRE(list.tail() != nullptr);
- v = list.head();
+ v = list.head();
auto list_rest = list.take_suffix(20);
REQUIRE(list_rest.count() == 5);
REQUIRE(list_rest.head() == v);
@@ -224,8 +220,8 @@ TEST_CASE("IntrusiveDList list suffix", "[libswoc][IntrusiveDList]") {
REQUIRE(list.tail() == nullptr);
// reassemble the list.
- list.append(list_most); // middle 6..14
- list_1.prepend(list_5); // -> last 15..20
+ list.append(list_most); // middle 6..14
+ list_1.prepend(list_5); // -> last 15..20
list.prepend(list_rest); // initial, 1..5 -> 1..14
list.append(list_1);
@@ -255,10 +251,10 @@ TEST_CASE("IntrusiveDList Extra", "[libswoc][IntrusiveDList]") {
list.append(new Thing(bwprint(tmp, "{}", 11)));
list.append(new Thing(bwprint(tmp, "{}", 12)));
- for (unsigned idx = 3 ; idx <= 5 ; ++idx) {
+ for (unsigned idx = 3; idx <= 5; ++idx) {
list_b.append(new Thing(bwprint(tmp, "{}", idx)));
}
- for (unsigned idx = 7 ; idx <= 10 ; ++idx) {
+ for (unsigned idx = 7; idx <= 10; ++idx) {
list_a.append(new Thing(bwprint(tmp, "{}", idx)));
}
@@ -269,7 +265,7 @@ TEST_CASE("IntrusiveDList Extra", "[libswoc][IntrusiveDList]") {
list.insert_after(v, list_a);
auto spot = list.begin();
- for ( unsigned idx = 0 ; idx <= 12 ; ++idx, ++spot ) {
+ for (unsigned idx = 0; idx <= 12; ++idx, ++spot) {
bwprint(tmp, "{}", idx);
REQUIRE(spot->_payload == tmp);
}
diff --git a/unit_tests/test_IntrusiveHashMap.cc b/unit_tests/test_IntrusiveHashMap.cc
index a392e31..1844ae3 100644
--- a/unit_tests/test_IntrusiveHashMap.cc
+++ b/unit_tests/test_IntrusiveHashMap.cc
@@ -36,8 +36,7 @@ using swoc::IntrusiveHashMap;
using namespace std::literals;
-namespace
-{
+namespace {
struct Thing {
std::string _payload;
int _n{0};
@@ -51,29 +50,24 @@ struct Thing {
struct ThingMapDescriptor {
static Thing *&
- next_ptr(Thing *thing)
- {
+ next_ptr(Thing *thing) {
return thing->_next;
}
static Thing *&
- prev_ptr(Thing *thing)
- {
+ prev_ptr(Thing *thing) {
return thing->_prev;
}
static std::string_view
- key_of(Thing *thing)
- {
+ key_of(Thing *thing) {
return thing->_payload;
}
static constexpr std::hash<std::string_view> hasher{};
static auto
- hash_of(std::string_view s) -> decltype(hasher(s))
- {
+ hash_of(std::string_view s) -> decltype(hasher(s)) {
return hasher(s);
}
static bool
- equal(std::string_view const &lhs, std::string_view const &rhs)
- {
+ equal(std::string_view const &lhs, std::string_view const &rhs) {
return lhs == rhs;
}
};
@@ -82,8 +76,7 @@ using Map = IntrusiveHashMap<ThingMapDescriptor>;
} // namespace
-TEST_CASE("IntrusiveHashMap", "[libts][IntrusiveHashMap]")
-{
+TEST_CASE("IntrusiveHashMap", "[libts][IntrusiveHashMap]") {
Map map;
map.insert(new Thing("bob"));
REQUIRE(map.count() == 1);
@@ -153,8 +146,7 @@ TEST_CASE("IntrusiveHashMap", "[libts][IntrusiveHashMap]")
};
// Some more involved tests.
-TEST_CASE("IntrusiveHashMapManyStrings", "[IntrusiveHashMap]")
-{
+TEST_CASE("IntrusiveHashMapManyStrings", "[IntrusiveHashMap]") {
std::vector<std::string_view> strings;
std::uniform_int_distribution<short> char_gen{'a', 'z'};
@@ -235,5 +227,4 @@ TEST_CASE("IntrusiveHashMapManyStrings", "[IntrusiveHashMap]")
REQUIRE(miss_p == false);
};
... 2647 lines suppressed ...