changeset 24254:4bca68f0d8d5

use shared_ptr to manage url_transfer object * url-transfer.h (base_url_transfer::count): Delete data member and all uses. (class usrl_transfer): Use default constructor and destrucor methods where possible. (url_transfer::rep): Manage with shared_ptr.
author John W. Eaton <jwe@octave.org>
date Wed, 15 Nov 2017 14:52:07 -0500
parents cf15cb87bad9
children b8e0bd54a268
files liboctave/util/url-transfer.h
diffstat 1 files changed, 8 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/util/url-transfer.h	Wed Nov 15 14:38:31 2017 -0500
+++ b/liboctave/util/url-transfer.h	Wed Nov 15 14:52:07 2017 -0500
@@ -31,6 +31,7 @@
 #include "octave-config.h"
 
 #include <iosfwd>
+#include <memory>
 #include <string>
 
 #include "str-vec.h"
@@ -57,7 +58,7 @@
     friend class url_transfer;
 
     base_url_transfer (void)
-      : count (1), host_or_url (), valid (false), ftp (false),
+      : host_or_url (), valid (false), ftp (false),
         ascii_mode (false), ok (true), errmsg (),
         curr_istream (&std::cin), curr_ostream (&std::cout) { }
 
@@ -65,12 +66,12 @@
                        const std::string& /* user_arg */,
                        const std::string& /* passwd */,
                        std::ostream& os)
-      : count (1), host_or_url (host), valid (false), ftp (true),
+      : host_or_url (host), valid (false), ftp (true),
         ascii_mode (false), ok (true), errmsg (), curr_istream (&std::cin),
         curr_ostream (&os) { }
 
     base_url_transfer (const std::string& url, std::ostream& os)
-      : count (1), host_or_url (url), valid (false), ftp (false),
+      : host_or_url (url), valid (false), ftp (false),
         ascii_mode (false), ok (true), errmsg (),
         curr_istream (&std::cin), curr_ostream (&os) { }
 
@@ -151,9 +152,6 @@
 
   protected:
 
-    // Reference count.
-    refcount<size_t> count;
-
     // Host for ftp transfers or full URL for http requests.
     std::string host_or_url;
     bool valid;
@@ -178,30 +176,11 @@
 
     url_transfer (const std::string& url, std::ostream& os);
 
-    url_transfer (const url_transfer& h) : rep (h.rep)
-    {
-      rep->count++;
-    }
-
-    url_transfer& operator = (const url_transfer& h)
-    {
-      if (this != &h)
-        {
-          if (--rep->count == 0)
-            delete rep;
+    url_transfer (const url_transfer& h) = default;
 
-          rep = h.rep;
-          rep->count++;
-        }
+    url_transfer& operator = (const url_transfer& h) = default;
 
-      return *this;
-    }
-
-    ~url_transfer (void)
-    {
-      if (--rep->count == 0)
-        delete rep;
-    }
+    ~url_transfer (void) = default;
 
     bool is_valid (void) const { return rep->is_valid (); }
 
@@ -286,7 +265,7 @@
 
   private:
 
-    base_url_transfer *rep;
+    std::shared_ptr<base_url_transfer> rep;
   };
 }