Mercurial > octave
diff libinterp/corefcn/load-path.h @ 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 | 6652d3823428 |
children | b75d55b3dbb7 |
line wrap: on
line diff
--- a/libinterp/corefcn/load-path.h Thu May 03 01:13:32 2018 -0400 +++ b/libinterp/corefcn/load-path.h Thu May 03 01:40:27 2018 -0400 @@ -26,6 +26,7 @@ #include "octave-config.h" +#include <functional> #include <iosfwd> #include <list> #include <map> @@ -44,11 +45,7 @@ { public: - load_path (void) - : package_map (), top_level_package (), dir_info_list (), init_dirs (), - m_command_line_path (), add_hook (load_path::execute_pkg_add), - remove_hook (load_path::execute_pkg_del) - { } + load_path (void); typedef void (*hook_fcn_ptr) (const std::string& dir); @@ -169,14 +166,28 @@ void display (std::ostream& os) const; - hook_fcn_ptr get_add_hook (void) { return add_hook; } - hook_fcn_ptr get_remove_hook (void) { return remove_hook; } + std::function<void (const std::string&)> get_add_hook (void) + { + return add_hook; + } + + std::function<void (const std::string&)> get_remove_hook (void) + { + return remove_hook; + } - void set_add_hook (hook_fcn_ptr f) { add_hook = f; } - void set_remove_hook (hook_fcn_ptr f) { remove_hook = f; } + void set_add_hook (const std::function<void (const std::string&)>& f) + { + add_hook = f; + } - static void execute_pkg_add (const std::string& dir); - static void execute_pkg_del (const std::string& dir); + void set_remove_hook (const std::function<void (const std::string&)>& f) + { + remove_hook = f; + } + + void execute_pkg_add (const std::string& dir); + void execute_pkg_del (const std::string& dir); void set_command_line_path (const std::string& p) { @@ -510,9 +521,12 @@ static abs_dir_cache_type abs_dir_cache; - hook_fcn_ptr add_hook; + std::function<void (const std::string&)> add_hook; - hook_fcn_ptr remove_hook; + std::function<void (const std::string&)> remove_hook; + + void execute_pkg_add_or_del (const std::string& dir, + const std::string& script_file); const_dir_info_list_iterator find_dir_info (const std::string& dir) const; dir_info_list_iterator find_dir_info (const std::string& dir);