diff libinterp/corefcn/load-path.cc @ 25344:4d3ce214da32

use std::function object for load-path add/remove hook functions * load-path.h, load-path.cc (load_path::add_hook, load_path::remove_hook): Now std::function objects. (load_path::load_path): Initialize them with lambda expressions. (load_path::get_add_hook, load_path::get_remove_hook): Return std::function objects. (load_path::set_add_hook, load_path::set_remove_hook): Accept std::function objects as parameters. (load_path::hook_fcn_ptr): Delete typedef. (execute_pkg_add_or_del): Now a load_path member function.
author John W. Eaton <jwe@octave.org>
date Thu, 03 May 2018 01:40:27 -0400
parents 4d7790d9793f
children b75d55b3dbb7
line wrap: on
line diff
--- a/libinterp/corefcn/load-path.cc	Thu May 03 01:13:32 2018 -0400
+++ b/libinterp/corefcn/load-path.cc	Thu May 03 01:40:27 2018 -0400
@@ -148,23 +148,6 @@
   return retval;
 }
 
-static void
-execute_pkg_add_or_del (const std::string& dir,
-                        const std::string& script_file)
-{
-  if (! octave_interpreter_ready)
-    return;
-
-  octave::unwind_protect frame;
-
-  std::string file = octave::sys::file_ops::concat (dir, script_file);
-
-  octave::sys::file_stat fs (file);
-
-  if (fs.exists ())
-    octave::source_file (file, "base");
-}
-
 // True if a path is contained in a path list separated by path_sep_char
 
 static bool
@@ -205,6 +188,13 @@
   std::string load_path::sys_path;
   load_path::abs_dir_cache_type load_path::abs_dir_cache;
 
+  load_path::load_path (void)
+    : package_map (), top_level_package (), dir_info_list (), init_dirs (),
+      m_command_line_path (),
+      add_hook ([this] (const std::string& dir) { this->execute_pkg_add (dir); }),
+      remove_hook ([this] (const std::string& dir) { this->execute_pkg_del (dir); })
+  { }
+
   void
   load_path::initialize (bool set_initial_path)
   {
@@ -845,6 +835,22 @@
     execute_pkg_add_or_del (dir, "PKG_DEL");
   }
 
+  void load_path::execute_pkg_add_or_del (const std::string& dir,
+                                          const std::string& script_file)
+  {
+    if (! octave_interpreter_ready)
+      return;
+
+    octave::unwind_protect frame;
+
+    std::string file = octave::sys::file_ops::concat (dir, script_file);
+
+    octave::sys::file_stat fs (file);
+
+    if (fs.exists ())
+      octave::source_file (file, "base");
+  }
+
   // FIXME: maybe we should also maintain a map to speed up this method of access.
 
   load_path::const_dir_info_list_iterator