diff libinterp/corefcn/octave-link.h @ 27262:d67f369b3074

use shared_ptr to manage octave_link_events object * octave-link.h, octave-link.cc (octave_link::instance): Now a shared_ptr<octave_link_events> object. Change all uses. (octave_link::enable): (octave_link::connect_link): (octave_link::disconnect_link): Delete. * interpreter-qobject.h, interpreter-qobject.cc (interpreter_qobject::m_qt_link): Now a shared_ptr<octave_qt_link_events> object. Change all uses. (interpreter_qobject::execute): Also enable link after connecting. * interpreter.cc (interpreter::cleanup): Disable m_octave_link instead of disconnecting.
author John W. Eaton <jwe@octave.org>
date Thu, 18 Jul 2019 09:58:41 -0400
parents dccdc3b001a2
children
line wrap: on
line diff
--- a/libinterp/corefcn/octave-link.h	Wed Jul 17 14:09:20 2019 -0400
+++ b/libinterp/corefcn/octave-link.h	Thu Jul 18 09:58:41 2019 -0400
@@ -28,6 +28,7 @@
 #include "octave-config.h"
 
 #include <list>
+#include <memory>
 #include <string>
 
 #include "oct-mutex.h"
@@ -212,16 +213,13 @@
 
   virtual ~octave_link (void);
 
-  void connect_link (octave_link_events *obj);
-
-  octave_link_events * disconnect_link (bool delete_instance = true);
+  // OBJ should be an object of a class that is derived from the base
+  // class octave_link_events, or nullptr to disconnect and delete the
+  // previous link.
 
-  bool enable (void)
-  {
-    bool retval = link_enabled;
-    link_enabled = true;
-    return retval;
-  }
+  void connect_link (const std::shared_ptr<octave_link_events>& obj);
+
+  bool enable (void);
 
   bool disable (void)
   {
@@ -525,9 +523,10 @@
 
 private:
 
-  octave_link_events *instance;
+  // Using a shared_ptr to manage the link_events object ensures that it
+  // will be valid until it is no longer needed.
 
-  bool instance_ok (void) { return instance != nullptr; }
+  std::shared_ptr<octave_link_events> instance;
 
 protected: