changeset 30139:71d738ed015d

maint: use "m_" prefix for member variables in class event_manager. * event-manager.cc, event-manager.h: Use "m_" prefix for member variables in class event_manager. Re-order event_manager class to have public/protected/private ordering.
author Rik <rik@octave.org>
date Tue, 07 Sep 2021 16:00:42 -0700
parents 938794bc82b7
children 606652e9f446
files libinterp/corefcn/event-manager.cc libinterp/corefcn/event-manager.h
diffstat 2 files changed, 98 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/event-manager.cc	Tue Sep 07 15:26:47 2021 -0700
+++ b/libinterp/corefcn/event-manager.cc	Tue Sep 07 16:00:42 2021 -0700
@@ -65,10 +65,10 @@
   }
 
   event_manager::event_manager (interpreter& interp)
-    : m_interpreter (interp), instance (new interpreter_events ()),
-      m_qt_event_handlers (),
-      event_queue_mutex (new mutex ()), gui_event_queue (),
-      debugging (false), link_enabled (true)
+    : m_event_queue_mutex (new mutex ()), m_gui_event_queue (),
+      m_debugging (false), m_link_enabled (true),
+      m_interpreter (interp), m_instance (new interpreter_events ()),
+      m_qt_event_handlers ()
   {
     push_event_queue ();
     command_editor::add_event_hook (readline_event_hook);
@@ -76,7 +76,7 @@
 
   event_manager::~event_manager (void)
   {
-    delete event_queue_mutex;
+    delete m_event_queue_mutex;
   }
 
   // Programming Note: It is possible to disable the link without deleting
@@ -91,15 +91,15 @@
     if (! obj)
       disable ();
 
-    instance = obj;
+    m_instance = obj;
   }
 
   bool event_manager::enable (void)
   {
-    bool retval = link_enabled;
+    bool retval = m_link_enabled;
 
-    if (instance)
-      link_enabled = true;
+    if (m_instance)
+      m_link_enabled = true;
     else
       warning ("event_manager: must have connected link to enable");
 
@@ -113,9 +113,9 @@
         if (disable_flag)
           disable ();
 
-        event_queue_mutex->lock ();
-        std::shared_ptr<event_queue> evq = gui_event_queue.top ();
-        event_queue_mutex->unlock ();
+        m_event_queue_mutex->lock ();
+        std::shared_ptr<event_queue> evq = m_gui_event_queue.top ();
+        m_event_queue_mutex->unlock ();
 
         evq->run ();
       }
@@ -125,9 +125,9 @@
   {
     if (enabled ())
       {
-        event_queue_mutex->lock ();
-        std::shared_ptr<event_queue> evq = gui_event_queue.top ();
-        event_queue_mutex->unlock ();
+        m_event_queue_mutex->lock ();
+        std::shared_ptr<event_queue> evq = m_gui_event_queue.top ();
+        m_event_queue_mutex->unlock ();
 
         evq->discard ();
       }
@@ -136,7 +136,7 @@
   void event_manager::push_event_queue (void)
   {
     std::shared_ptr<event_queue> evq (new event_queue ());
-    gui_event_queue.push (evq);
+    m_gui_event_queue.push (evq);
   }
 
   void event_manager::pop_event_queue (void)
@@ -150,15 +150,15 @@
     // debug session just after a dbcont command was added but before it
     // executed and brought us here, for example.
 
-    std::shared_ptr<event_queue> evq = gui_event_queue.top ();
-    gui_event_queue.pop ();
+    std::shared_ptr<event_queue> evq = m_gui_event_queue.top ();
+    m_gui_event_queue.pop ();
   }
 
   void event_manager::post_event (const fcn_callback& fcn)
   {
     if (enabled ())
       {
-        std::shared_ptr<event_queue> evq = gui_event_queue.top ();
+        std::shared_ptr<event_queue> evq = m_gui_event_queue.top ();
         evq->add (fcn);
       }
   }
@@ -167,7 +167,7 @@
   {
     if (enabled ())
       {
-        std::shared_ptr<event_queue> evq = gui_event_queue.top ();
+        std::shared_ptr<event_queue> evq = m_gui_event_queue.top ();
         evq->add (std::bind (meth, std::ref (m_interpreter)));
       }
   }
@@ -178,7 +178,7 @@
       {
         tree_evaluator& tw = m_interpreter.get_evaluator ();
 
-        instance->set_workspace (tw.at_top_level (), debugging,
+        m_instance->set_workspace (tw.at_top_level (), m_debugging,
                                  tw.get_symbol_info (), true);
       }
   }
@@ -186,7 +186,7 @@
   void event_manager::set_history (void)
   {
     if (enabled ())
-      instance->set_history (command_history::list ());
+      m_instance->set_history (command_history::list ());
   }
 
 // FIXME: Should the following function be __event_manager_desktop__
--- a/libinterp/corefcn/event-manager.h	Tue Sep 07 15:26:47 2021 -0700
+++ b/libinterp/corefcn/event-manager.h	Tue Sep 07 16:00:42 2021 -0700
@@ -312,14 +312,14 @@
 
     bool disable (void)
     {
-      bool retval = link_enabled;
-      link_enabled = false;
+      bool retval = m_link_enabled;
+      m_link_enabled = false;
       return retval;
     }
 
     bool enabled (void) const
     {
-      return link_enabled;
+      return m_link_enabled;
     }
 
     // Make the Qt actions available for others.  This is a temporary
@@ -369,13 +369,13 @@
     void start_gui (bool gui_app = false)
     {
       if (enabled ())
-        instance->start_gui (gui_app);
+        m_instance->start_gui (gui_app);
     }
 
     void close_gui (void)
     {
       if (enabled ())
-        instance->close_gui ();
+        m_instance->close_gui ();
     }
 
     typedef std::list<std::pair<std::string, std::string>> filter_list;
@@ -386,8 +386,8 @@
                  const std::string& multimode)
     {
       return (enabled ()
-              ? instance->file_dialog (filter, title, filename, dirname,
-                                       multimode)
+              ? m_instance->file_dialog (filter, title, filename, dirname,
+                                         multimode)
               : std::list<std::string> ());
     }
 
@@ -399,7 +399,7 @@
                   const std::list<std::string>& defaults)
     {
       return (enabled ()
-              ? instance->input_dialog (prompt, title, nr, nc, defaults)
+              ? m_instance->input_dialog (prompt, title, nr, nc, defaults)
               : std::list<std::string> ());
     }
 
@@ -414,9 +414,9 @@
                  const std::string& cancel_string)
     {
       return (enabled ()
-              ? instance->list_dialog (list, mode, width, height,
-                                       initial_value, name, prompt,
-                                       ok_string, cancel_string)
+              ? m_instance->list_dialog (list, mode, width, height,
+                                         initial_value, name, prompt,
+                                         ok_string, cancel_string)
               : std::pair<std::list<int>, int> ());
     }
 
@@ -426,22 +426,22 @@
                      const std::string& btn3, const std::string& btndef)
     {
       return (enabled ()
-              ? instance->question_dialog (msg, title, btn1,
-                                           btn2, btn3, btndef)
+              ? m_instance->question_dialog (msg, title, btn1,
+                                             btn2, btn3, btndef)
               : "");
     }
 
     void update_path_dialog (void)
     {
       if (application::is_gui_running () && enabled ())
-        instance->update_path_dialog ();
+        m_instance->update_path_dialog ();
     }
 
     bool show_preferences (void)
     {
       if (enabled ())
         {
-          instance->show_preferences ();
+          m_instance->show_preferences ();
           return true;
         }
       else
@@ -452,7 +452,7 @@
     {
       if (enabled ())
         {
-          instance->apply_preferences ();
+          m_instance->apply_preferences ();
           return true;
         }
       else
@@ -462,54 +462,54 @@
     void show_terminal_window (void)
     {
       if (enabled ())
-        instance->show_terminal_window ();
+        m_instance->show_terminal_window ();
     }
 
     bool show_documentation (const std::string& file)
     {
-      return enabled () ? instance->show_documentation (file) : false;
+      return enabled () ? m_instance->show_documentation (file) : false;
     }
 
     void show_file_browser (void)
     {
       if (enabled ())
-        instance->show_file_browser ();
+        m_instance->show_file_browser ();
     }
 
     void show_command_history (void)
     {
       if (enabled ())
-        instance->show_command_history ();
+        m_instance->show_command_history ();
     }
 
     void show_workspace (void)
     {
       if (enabled ())
-        instance->show_workspace ();
+        m_instance->show_workspace ();
     }
 
     void show_community_news (int serial = -1)
     {
       if (enabled ())
-        instance->show_community_news (serial);
+        m_instance->show_community_news (serial);
     }
 
     void show_release_notes (void)
     {
       if (enabled ())
-        instance->show_release_notes ();
+        m_instance->show_release_notes ();
     }
 
     bool edit_file (const std::string& file)
     {
-      return enabled () ? instance->edit_file (file) : false;
+      return enabled () ? m_instance->edit_file (file) : false;
     }
 
     bool edit_variable (const std::string& name, const octave_value& val)
     {
       if (enabled ())
         {
-          instance->edit_variable (name, val);
+          m_instance->edit_variable (name, val);
           return true;
         }
       else
@@ -521,59 +521,60 @@
       bool retval = true;
 
       if (enabled ())
-        retval = instance->confirm_shutdown ();
+        retval = m_instance->confirm_shutdown ();
 
       return retval;
     }
 
     bool prompt_new_edit_file (const std::string& file)
     {
-      return enabled () ? instance->prompt_new_edit_file (file) : false;
+      return enabled () ? m_instance->prompt_new_edit_file (file) : false;
     }
 
     int debug_cd_or_addpath_error (const std::string& file,
                                    const std::string& dir, bool addpath_option)
     {
       return (enabled ()
-              ? instance->debug_cd_or_addpath_error (file, dir, addpath_option)
+              ? m_instance->debug_cd_or_addpath_error (file, dir,
+                                                       addpath_option)
               : 0);
     }
 
     uint8NDArray get_named_icon (const std::string& icon_name)
     {
       return (enabled ()
-              ? instance->get_named_icon (icon_name) : uint8NDArray ());
+              ? m_instance->get_named_icon (icon_name) : uint8NDArray ());
     }
 
     std::string gui_preference (const std::string& key,
                                 const std::string& value)
     {
-      return enabled () ? instance->gui_preference (key, value) : "";
+      return enabled () ? m_instance->gui_preference (key, value) : "";
     }
 
     bool copy_image_to_clipboard (const std::string& file)
     {
-      return enabled () ? instance->copy_image_to_clipboard (file) : false;
+      return enabled () ? m_instance->copy_image_to_clipboard (file) : false;
     }
 
     virtual void focus_window (const std::string win_name)
     {
       if (enabled ())
-        instance->focus_window (win_name);
+        m_instance->focus_window (win_name);
     }
 
     // Preserves pending input.
     void execute_command_in_terminal (const std::string& command)
     {
       if (enabled ())
-        instance->execute_command_in_terminal (command);
+        m_instance->execute_command_in_terminal (command);
     }
 
     bool register_documentation (const std::string& file)
     {
       if (enabled ())
         {
-          instance->register_documentation (file);
+          m_instance->register_documentation (file);
           return true;
         }
       else
@@ -584,7 +585,7 @@
     {
       if (enabled ())
         {
-          instance->unregister_documentation (file);
+          m_instance->unregister_documentation (file);
           return true;
         }
       else
@@ -595,7 +596,7 @@
     {
       if (enabled ())
         {
-          instance->interpreter_output (msg);
+          m_instance->interpreter_output (msg);
           return true;
         }
       else
@@ -606,7 +607,7 @@
     {
       if (enabled ())
         {
-          instance->display_exception (ee, beep);
+          m_instance->display_exception (ee, beep);
           return true;
         }
       else
@@ -617,7 +618,7 @@
     {
       if (enabled ())
         {
-          instance->gui_status_update (feature, status);
+          m_instance->gui_status_update (feature, status);
           return true;
         }
       else
@@ -628,7 +629,7 @@
     {
       if (enabled ())
         {
-          instance->update_gui_lexer ();
+          m_instance->update_gui_lexer ();
           return true;
         }
       else
@@ -638,20 +639,20 @@
     void directory_changed (const std::string& dir)
     {
       if (enabled ())
-        instance->directory_changed (dir);
+        m_instance->directory_changed (dir);
     }
 
     // Methods for removing/renaming files which might be open in editor
     void file_remove (const std::string& old_name, const std::string& new_name)
     {
       if (application::is_gui_running () && enabled ())
-        instance->file_remove (old_name, new_name);
+        m_instance->file_remove (old_name, new_name);
     }
 
     void file_renamed (bool load_new)
     {
       if (application::is_gui_running () && enabled ())
-        instance->file_renamed (load_new);
+        m_instance->file_renamed (load_new);
     }
 
     OCTINTERP_API void set_workspace (void);
@@ -660,20 +661,20 @@
                         bool update_variable_editor = true)
     {
       if (enabled ())
-        instance->set_workspace (top_level, debugging, syminfo,
-                                 update_variable_editor);
+        m_instance->set_workspace (top_level, m_debugging, syminfo,
+                                   update_variable_editor);
     }
 
     void clear_workspace (void)
     {
       if (enabled ())
-        instance->clear_workspace ();
+        m_instance->clear_workspace ();
     }
 
     void update_prompt (const std::string& prompt)
     {
       if (enabled ())
-        instance->update_prompt (prompt);
+        m_instance->update_prompt (prompt);
     }
 
     OCTINTERP_API void set_history (void);
@@ -681,31 +682,31 @@
     void set_history (const string_vector& hist)
     {
       if (enabled ())
-        instance->set_history (hist);
+        m_instance->set_history (hist);
     }
 
     void append_history (const std::string& hist_entry)
     {
       if (enabled ())
-        instance->append_history (hist_entry);
+        m_instance->append_history (hist_entry);
     }
 
     void clear_history (void)
     {
       if (enabled ())
-        instance->clear_history ();
+        m_instance->clear_history ();
     }
 
     void pre_input_event (void)
     {
       if (enabled ())
-        instance->pre_input_event ();
+        m_instance->pre_input_event ();
     }
 
     void post_input_event (void)
     {
       if (enabled ())
-        instance->post_input_event ();
+        m_instance->post_input_event ();
     }
 
     void enter_debugger_event (const std::string& fcn_name,
@@ -713,25 +714,25 @@
     {
       if (enabled ())
         {
-          debugging = true;
+          m_debugging = true;
 
-          instance->enter_debugger_event (fcn_name, fcn_file_name, line);
+          m_instance->enter_debugger_event (fcn_name, fcn_file_name, line);
         }
     }
 
     void execute_in_debugger_event (const std::string& file, int line)
     {
       if (enabled ())
-        instance->execute_in_debugger_event (file, line);
+        m_instance->execute_in_debugger_event (file, line);
     }
 
     void exit_debugger_event (void)
     {
-      if (enabled () && debugging)
+      if (enabled () && m_debugging)
         {
-          debugging = false;
+          m_debugging = false;
 
-          instance->exit_debugger_event ();
+          m_instance->exit_debugger_event ();
         }
     }
 
@@ -739,30 +740,19 @@
                             int line, const std::string& cond = "")
     {
       if (enabled ())
-        instance->update_breakpoint (insert, file, line, cond);
+        m_instance->update_breakpoint (insert, file, line, cond);
     }
 
     void interpreter_interrupted (void)
     {
       if (enabled ())
-        instance->interpreter_interrupted ();
+        m_instance->interpreter_interrupted ();
     }
 
-  private:
-
-    interpreter& m_interpreter;
-
-    // Using a shared_ptr to manage the link_events object ensures that it
-    // will be valid until it is no longer needed.
-
-    std::shared_ptr<interpreter_events> instance;
-
-    std::shared_ptr<interpreter_events> m_qt_event_handlers;
-
   protected:
 
     // Semaphore to lock access to the event queue.
-    mutex *event_queue_mutex;
+    mutex *m_event_queue_mutex;
 
     // Event Queue.  We use a stack so that we can handle evaluation in
     // the debugger when we are executing in server mode.  In server
@@ -774,10 +764,22 @@
     // (dbcont or dbstep, for example) we pop the queue and return to
     // the previous point of execution.
 
-    std::stack<std::shared_ptr <event_queue>> gui_event_queue;
+    std::stack<std::shared_ptr <event_queue>> m_gui_event_queue;
+
+    bool m_debugging;
+    bool m_link_enabled;
+
+  private:
 
-    bool debugging;
-    bool link_enabled;
+    interpreter& m_interpreter;
+
+    // Using a shared_ptr to manage the link_events object ensures that it
+    // will be valid until it is no longer needed.
+
+    std::shared_ptr<interpreter_events> m_instance;
+
+    std::shared_ptr<interpreter_events> m_qt_event_handlers;
+
   };
 
 OCTAVE_NAMESPACE_END