changeset 27503:1bc237447e56

use shared_ptr to manage base_reader object * input.h (input_reader::m_rep): Use shared_ptr object. (class input_reader): Use default copy constructor, assignment operator and destructor. (base_reader::m_count): Delete data member and all uses.
author John W. Eaton <jwe@octave.org>
date Wed, 16 Oct 2019 10:56:10 -0400
parents f62f1170ad98
children 7a31b25e3252
files libinterp/corefcn/input.h
diffstat 1 files changed, 7 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/input.h	Wed Oct 16 08:45:39 2019 -0400
+++ b/libinterp/corefcn/input.h	Wed Oct 16 10:56:10 2019 -0400
@@ -29,10 +29,10 @@
 
 #include <cstdio>
 
+#include <memory>
 #include <string>
 
 #include "hook-fcn.h"
-#include "oct-refcount.h"
 #include "oct-time.h"
 #include "ovl.h"
 #include "pager.h"
@@ -198,11 +198,11 @@
     friend class input_reader;
 
     base_reader (interpreter& interp)
-      : m_interpreter (interp), m_count (1), m_pflag (0)
+      : m_interpreter (interp), m_pflag (0)
     { }
 
     base_reader (const base_reader& x)
-      : m_interpreter (x.m_interpreter), m_count (1), m_pflag (x.m_pflag)
+      : m_interpreter (x.m_interpreter), m_pflag (x.m_pflag)
     { }
 
     virtual ~base_reader (void) = default;
@@ -240,8 +240,6 @@
 
   private:
 
-    refcount<octave_idx_type> m_count;
-
     int m_pflag;
 
     static const std::string s_in_src;
@@ -257,28 +255,11 @@
 
     input_reader (interpreter& interp, const std::string& str);
 
-    input_reader (const input_reader& ir)
-    {
-      m_rep = ir.m_rep;
-      m_rep->m_count++;
-    }
+    input_reader (const input_reader& ir) = default;
 
-    input_reader& operator = (const input_reader& ir)
-    {
-      if (&ir != this)
-        {
-          m_rep = ir.m_rep;
-          m_rep->m_count++;
-        }
+    input_reader& operator = (const input_reader& ir) = default;
 
-      return *this;
-    }
-
-    ~input_reader (void)
-    {
-      if (--m_rep->m_count == 0)
-        delete m_rep;
-    }
+    ~input_reader (void) = default;
 
     void reset (void) { return m_rep->reset (); }
 
@@ -317,7 +298,7 @@
 
   private:
 
-    base_reader *m_rep;
+    std::shared_ptr<base_reader> m_rep;
   };
 }