trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: Errata: CacheTool updates.
Date Wed, 14 Mar 2018 15:21:26 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 6f7f814  Errata: CacheTool updates.
6f7f814 is described below

commit 6f7f814df57a84fc897255b579b0ceb6ca7e126f
Author: Alan M. Carroll <amc@apache.org>
AuthorDate: Mon Mar 12 13:17:47 2018 -0500

    Errata: CacheTool updates.
---
 lib/tsconfig/Errata.cc | 48 +++++++++++++++++++++++-----------------
 lib/tsconfig/Errata.h  | 60 ++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 86 insertions(+), 22 deletions(-)

diff --git a/lib/tsconfig/Errata.cc b/lib/tsconfig/Errata.cc
index 488c2dc..0d1c5e9 100644
--- a/lib/tsconfig/Errata.cc
+++ b/lib/tsconfig/Errata.cc
@@ -53,6 +53,11 @@ Errata::Data::push(Message const& msg) {
   m_items.push_back(msg);
 }
 
+void
+Errata::Data::push(Message && msg) {
+  m_items.push_back(std::move(msg));
+}
+
 Errata::Message const&
 Errata::Data::top() const {
   return m_items.size() ? m_items.back() : NIL_MESSAGE ;
@@ -65,21 +70,16 @@ inline Errata::Errata(ImpPtr const& ptr)
 Errata::Data::~Data() {
   if (m_log_on_delete) {
     Errata tmp(this); // because client API requires a wrapper.
-    std::deque<Errata::Sink::Handle>::iterator spot, limit;
-    for ( spot = Sink_List.begin(), limit = Sink_List.end();
-          spot != limit;
-          ++spot
-    ) {
-      (**spot)(tmp);
-    }
+    for ( auto& f : Sink_List ) (*f)(tmp);
     tmp.m_data.release(); // don't delete this again.
   }
 }
 
-Errata::Errata() {
+Errata::Errata(self const& that)
+  : m_data(that.m_data) {
 }
 
-Errata::Errata(self const& that)
+Errata::Errata(self && that)
   : m_data(that.m_data) {
 }
 
@@ -111,7 +111,7 @@ Errata::pre_write() {
 }
 
 // Just create an instance if needed.
-Errata::Data*
+Errata::Data const*
 Errata::instance() {
   if (!m_data) { m_data = new Data;
 }
@@ -125,6 +125,12 @@ Errata::push(Message const& msg) {
 }
 
 Errata&
+Errata::push(Message && msg) {
+  this->pre_write()->push(std::move(msg));
+  return *this;
+}
+
+Errata&
 Errata::operator=(self const& that) {
   m_data = that.m_data;
   return *this;
@@ -144,6 +150,12 @@ Errata::operator = (Message const& msg) {
 }
 
 Errata&
+Errata::operator = (self && that) {
+  m_data = that.m_data;
+  return *this;
+}
+
+Errata&
 Errata::pull(self& that) {
   if (that.m_data) {
     this->pre_write();
@@ -217,21 +229,18 @@ Errata::write(
   int shift,
   char const* lead
 ) const {
-  for ( const_iterator spot = this->begin(), limit = this->end();
-        spot != limit;
-        ++spot
-  ) {
+
+  for ( auto m : *this ) {
     if ((offset + indent) > 0) {
       out << std::setw(indent + offset) << std::setfill(' ')
           << ((indent > 0 && lead) ? lead : " ");
-}
+    }
 
-    out << spot->m_id << " [" << spot->m_code << "]: " <<
spot->m_text
+    out << m.m_id << " [" << m.m_code << "]: " << m.m_text
         << std::endl
       ;
-    if (spot->getErrata().size()) {
-      spot->getErrata().write(out, offset, indent+shift, shift, lead);
-}
+    if (m.getErrata().size())
+      m.getErrata().write(out, offset, indent+shift, shift, lead);
 
   }
   return out;
@@ -259,4 +268,3 @@ std::ostream& operator<< (std::ostream& os, Errata const&
err) {
 }
 
 } // namespace ts
-
diff --git a/lib/tsconfig/Errata.h b/lib/tsconfig/Errata.h
index 8cb50da..278697a 100644
--- a/lib/tsconfig/Errata.h
+++ b/lib/tsconfig/Errata.h
@@ -68,6 +68,7 @@
 # include <memory>
 # include <string>
 # include <iosfwd>
+# include <sstream>
 # include <deque>
 # include "NumericType.h"
 # include "IntrusivePtr.h"
@@ -141,6 +142,11 @@ public:
       Message const& msg ///< Message to push
     );
 
+    /// Move constructor.
+    Errata(self && that);
+    /// Move constructor from @c Message.
+    Errata(Message && msg);
+
     /// destructor
     ~Errata();
 
@@ -150,6 +156,9 @@ public:
       const self& that ///< Source instance.
     );
 
+    /// Move assignment.
+    self& operator = (self && that);
+
     /** Assign message.
         All other messages are discarded.
         @return A reference to this object.
@@ -181,6 +190,15 @@ public:
         @return A reference to this object.
     */
     self& push(Message const& msg);
+    self& push(Message && msg);
+
+    /** Push a constructed @c Message.
+	The @c Message is set to have the @a id and @a code. The other arguments are converted
+	to strings and concatenated to form the messsage text.
+	@return A reference to this object.
+    */
+    template < typename ... Args >
+      self& push(Id id, Code code, Args const& ... args);
 
     /** Push a nested status.
         @a err becomes the top item.
@@ -342,7 +360,7 @@ protected:
     Data* pre_write();
     /// Force and return an implementation instance.
     /// Does not follow copy on write.
-    Data* instance();
+    Data const* instance();
 
     /// Used for returns when no data is present.
     static Message const NIL_MESSAGE;
@@ -382,6 +400,16 @@ struct Errata::Message {
     std::string const& text ///< Final text for message.
   );
 
+  /// Construct with an @a id, @a code, and a @a message.
+  /// The message contents are created by converting the variable arguments
+  /// to strings using the stream operator and concatenated in order.
+  template < typename ... Args>
+    Message(
+	    Id id, ///< Message Id.
+	    Code code, ///< Message Code.
+	    Args const& ... text
+	    );
+
   /// Reset to the message to default state.
   self& clear();
 
@@ -452,6 +480,8 @@ struct Errata::Message {
 
   static SuccessTest const DEFAULT_SUCCESS_TEST;
 
+  template < typename ... Args> static std::string stringify(Args const& ... items);
+
   Id m_id; ///< Message ID.
   Code m_code; ///< Message code.
   std::string m_text; ///< Final text.
@@ -484,9 +514,10 @@ struct Errata::Data : public IntrusivePtrCounter {
 
   /// Put a message on top of the stack.
   void push(Message const& msg);
+  void push(Message && msg);
 
   /// Log this when it is deleted.
-  bool m_log_on_delete;
+  mutable bool m_log_on_delete;
 
   //! The message stack.
   Container m_items;
@@ -730,6 +761,12 @@ inline Errata::Message::Message(Id id, std::string const& text)
 inline Errata::Message::Message(Id id, Code code, std::string const& text)
   : m_id(id), m_code(code), m_text(text) {
 }
+template < typename ... Args>
+Errata::Message::Message(Id id, Code code, Args const& ... text)
+  : m_id(id), m_code(code), m_text(stringify(text ...))
+{
+}
+
 inline Errata::Message& Errata::Message::clear() {
   m_id = 0;
   m_code = Default_Code;
@@ -764,12 +801,24 @@ inline Errata::Message& Errata::Message::set(Errata const& err)
{
   return *this;
 }
 
+template < typename ... Args>
+std::string Errata::Message::stringify(Args const& ... items)
+{
+  std::ostringstream s;
+  (void)(int[]){0, ( (s << items) , 0 ) ... };
+  return s.str();
+}
+
+inline Errata::Errata() {}
 inline Errata::Errata(Id id, Code code, std::string const& text) {
   this->push(Message(id, code, text));
 }
 inline Errata::Errata(Message const& msg) {
   this->push(msg);
 }
+inline Errata::Errata(Message && msg) {
+  this->push(std::move(msg));
+}
 
 inline Errata::operator bool() const { return this->isOK(); }
 
@@ -802,6 +851,13 @@ Errata::push(Id id, Code code, std::string const& text) {
   return *this;
 }
 
+template < typename ... Args >
+auto Errata::push(Id id, Code code, Args const& ... args) -> self&
+{
+  this->push(Message(id, code, args ...));
+  return *this;
+}
+
 inline Errata::Message const&
 Errata::top() const {
   return m_data ? m_data->top() : NIL_MESSAGE;

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

Mime
View raw message