26 #if ! defined (octave_load_path_h)
27 #define octave_load_path_h 1
29 #include "octave-config.h"
52 typedef void (*hook_fcn_ptr) (
const std::string& dir);
54 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (
load_path)
58 void initialize (
bool set_initial_path =
false);
62 void set (
const std::string& p,
bool warn =
false,
bool is_init =
false);
64 void append (
const std::string& dir,
bool warn =
false);
66 void prepend (
const std::string& dir,
bool warn =
false);
68 bool remove (
const std::string& dir);
72 bool contains_canonical (
const std::string& dir_name)
const;
74 bool contains_file_in_dir (
const std::string& file_name,
75 const std::string& dir_name);
78 const std::string& meth,
79 std::string& dir_name,
80 const std::string& pack_name =
"")
82 return get_package (pack_name).find_method (class_name, meth, dir_name);
86 const std::string& meth,
87 const std::string& pack_name =
"")
90 return find_method (class_name, meth, dir_name, pack_name);
93 std::list<std::string>
methods (
const std::string& class_name,
94 const std::string& pack_name =
"")
96 return get_package (pack_name).methods (class_name);
99 std::list<std::string> overloads (
const std::string& meth)
const;
103 return (m_package_map.find (package_name) != m_package_map.end ());
106 std::list<std::string>
107 get_all_package_names (
bool only_top_level =
true)
const;
109 std::string
find_fcn (
const std::string& fcn, std::string& dir_name,
110 const std::string& pack_name =
"")
112 return get_package (pack_name).find_fcn (fcn, dir_name);
116 const std::string& pack_name =
"")
118 std::string dir_name;
119 return find_fcn (fcn, dir_name, pack_name);
123 const std::string& fcn,
124 const std::string& pack_name =
"")
126 return get_package (pack_name).find_private_fcn (dir, fcn);
130 const std::string& pack_name =
"")
132 std::string dir_name;
133 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
137 const std::string& pack_name =
"")
139 std::string dir_name;
140 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
144 const std::string& pack_name =
"")
146 std::string dir_name;
147 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
150 std::string find_file (
const std::string& file)
const;
152 std::string find_dir (
const std::string& dir)
const;
154 string_vector find_matching_dirs (
const std::string& dir)
const;
156 std::string find_first_of (
const string_vector& files)
const;
162 std::list<std::string> dir_list ()
const;
164 string_vector files (
const std::string& dir,
bool omit_exts =
false)
const;
168 std::string path ()
const;
170 void display (std::ostream& os)
const;
179 return m_remove_hook;
192 void read_dir_config (
const std::string& dir)
const;
194 void execute_pkg_add (
const std::string& dir);
195 void execute_pkg_del (
const std::string& dir);
199 if (m_command_line_path.empty ())
200 m_command_line_path = p;
207 return m_command_line_path;
214 static const int M_FILE = 1;
215 static const int OCT_FILE = 2;
216 static const int MEX_FILE = 4;
225 typedef std::map<std::string, int> fcn_file_map_type;
227 typedef fcn_file_map_type::const_iterator const_fcn_file_map_iterator;
228 typedef fcn_file_map_type::iterator fcn_file_map_iterator;
236 : method_file_map (ci.method_file_map),
237 private_file_map (ci.private_file_map)
257 typedef std::map<std::string, class_info> method_file_map_type;
259 typedef method_file_map_type::const_iterator const_method_file_map_iterator;
260 typedef method_file_map_type::iterator method_file_map_iterator;
263 typedef std::map<std::string, dir_info> package_dir_map_type;
265 typedef package_dir_map_type::const_iterator const_package_dir_map_iterator;
266 typedef package_dir_map_type::iterator package_dir_map_iterator;
271 dir_info () =
default;
273 dir_info (
const std::string&
d)
274 : dir_name (
d), abs_dir_name (), is_relative (false),
275 dir_mtime (), dir_time_last_checked (), all_files (), fcn_files (),
276 private_file_map (), method_file_map (), package_dir_map ()
281 dir_info (
const dir_info&) =
default;
283 ~dir_info () =
default;
285 dir_info& operator = (
const dir_info&) =
default;
289 std::string dir_name;
290 std::string abs_dir_name;
292 sys::file_time dir_mtime;
293 sys::file_time dir_time_last_checked;
296 fcn_file_map_type private_file_map;
297 method_file_map_type method_file_map;
298 package_dir_map_type package_dir_map;
300 bool is_package (
const std::string& name)
const;
306 void get_file_list (
const std::string&
d);
308 void get_private_file_map (
const std::string&
d);
310 void get_method_file_map (
const std::string&
d,
311 const std::string& class_name);
313 void get_package_dir (
const std::string&
d,
314 const std::string& package_name);
325 file_info (
const std::string&
d,
int t) : dir_name (
d), types (t) { }
328 : dir_name (fi.dir_name), types (fi.types) { }
336 dir_name = fi.dir_name;
343 std::string dir_name;
360 typedef std::list<dir_info> dir_info_list_type;
362 typedef dir_info_list_type::const_iterator const_dir_info_list_iterator;
363 typedef dir_info_list_type::iterator dir_info_list_iterator;
365 typedef std::map<std::string, dir_info> abs_dir_cache_type;
367 typedef abs_dir_cache_type::const_iterator const_abs_dir_cache_iterator;
368 typedef abs_dir_cache_type::iterator abs_dir_cache_iterator;
370 typedef std::list<file_info> file_info_list_type;
372 typedef file_info_list_type::const_iterator const_file_info_list_iterator;
373 typedef file_info_list_type::iterator file_info_list_iterator;
376 typedef std::map<std::string, file_info_list_type> fcn_map_type;
378 typedef fcn_map_type::const_iterator const_fcn_map_iterator;
379 typedef fcn_map_type::iterator fcn_map_iterator;
382 typedef std::map<std::string, dir_info::fcn_file_map_type>
383 private_fcn_map_type;
385 typedef private_fcn_map_type::const_iterator const_private_fcn_map_iterator;
386 typedef private_fcn_map_type::iterator private_fcn_map_iterator;
389 typedef std::map<std::string, fcn_map_type> method_map_type;
391 typedef method_map_type::const_iterator const_method_map_iterator;
392 typedef method_map_type::iterator method_map_iterator;
398 package_info (
const std::string& package_name =
"")
399 : m_package_name (package_name), m_dir_list (), m_fcn_map (),
400 m_private_fcn_map (),
404 package_info (
const package_info& l)
405 : m_package_name (l.m_package_name), m_dir_list (l.m_dir_list),
406 m_private_fcn_map (l.m_private_fcn_map), m_method_map (l.m_method_map)
409 ~package_info () =
default;
411 package_info& operator = (
const package_info& l)
415 m_package_name = l.m_package_name;
416 m_dir_list = l.m_dir_list;
417 m_fcn_map = l.m_fcn_map;
418 m_private_fcn_map = l.m_private_fcn_map;
419 m_method_map = l.m_method_map;
425 void add (
const dir_info& di,
bool at_end,
bool updating)
428 m_dir_list.push_back (di.dir_name);
430 m_dir_list.push_front (di.dir_name);
432 add_to_fcn_map (di, at_end, updating);
434 add_to_private_fcn_map (di);
436 add_to_method_map (di, at_end);
439 void move (
const dir_info& di,
bool at_end);
441 void remove (
const dir_info& di);
449 m_private_fcn_map.clear ();
451 m_method_map.clear ();
454 void display (std::ostream& out)
const;
457 find_fcn (
const std::string& fcn, std::string& dir_name,
458 int type = M_FILE | OCT_FILE | MEX_FILE)
const;
461 find_private_fcn (
const std::string& dir,
const std::string& fcn,
462 int type = M_FILE | OCT_FILE | MEX_FILE)
const;
465 find_method (
const std::string& class_name,
const std::string& meth,
466 std::string& dir_name,
467 int type = M_FILE | OCT_FILE | MEX_FILE)
const;
469 std::list<std::string> methods (
const std::string& class_name)
const;
471 void overloads (
const std::string& meth, std::list<std::string>& l)
const;
477 void add_to_fcn_map (
const dir_info& di,
bool at_end,
bool updating);
479 void add_to_private_fcn_map (
const dir_info& di);
481 void add_to_method_map (
const dir_info& di,
bool at_end);
483 void move_fcn_map (
const std::string& dir,
486 void move_method_map (
const std::string& dir,
bool at_end);
488 void remove_fcn_map (
const std::string& dir,
491 void remove_private_fcn_map (
const std::string& dir);
493 void remove_method_map (
const std::string& dir);
495 bool check_file_type (std::string& fname,
int type,
int possible_types,
496 const std::string& fcn,
const char *who)
const;
498 void print_types (std::ostream& os,
int types)
const;
500 void print_fcn_list (std::ostream& os,
501 const dir_info::fcn_file_map_type& lst)
const;
503 std::string m_package_name;
505 std::list<std::string> m_dir_list;
507 fcn_map_type m_fcn_map;
509 private_fcn_map_type m_private_fcn_map;
511 method_map_type m_method_map;
515 typedef std::map<std::string, package_info> package_map_type;
517 typedef package_map_type::const_iterator const_package_map_iterator;
518 typedef package_map_type::iterator package_map_iterator;
520 std::function<void (
const std::string&)> m_add_hook;
522 std::function<void (
const std::string&)> m_remove_hook;
524 void execute_pkg_add_or_del (
const std::string& dir,
525 const std::string& script_file);
527 const_dir_info_list_iterator find_dir_info (
const std::string& dir)
const;
528 dir_info_list_iterator find_dir_info (
const std::string& dir);
530 bool contains (
const std::string& dir)
const;
532 void move (dir_info_list_iterator i,
bool at_end);
534 void move (
const dir_info& di,
bool at_end,
const std::string& pname =
"");
536 void remove (
const dir_info& di,
const std::string& pname =
"");
538 void add (
const std::string& dir,
bool at_end,
bool warn);
540 void add (
const dir_info& di,
bool at_end,
const std::string& pname =
"",
541 bool updating =
false);
543 bool is_package (
const std::string& name)
const;
545 package_info& get_package (
const std::string& name)
547 if (! name.empty () && is_package (name))
549 package_map_iterator l = m_package_map.find (name);
551 if (l == m_package_map.end ())
552 l = m_package_map.insert (m_package_map.end (),
553 package_map_type::value_type (name, package_info (name)));
558 return m_top_level_package;
561 string_vector get_file_list (
const dir_info::fcn_file_map_type& lst)
const;
563 std::string find_private_file (
const std::string& fname)
const;
565 friend dir_info::fcn_file_map_type
get_fcn_files (
const std::string&
d);
569 static std::string s_sys_path;
571 static abs_dir_cache_type s_abs_dir_cache;
575 package_map_type m_package_map;
577 package_info m_top_level_package;
579 dir_info_list_type m_dir_info_list;
581 std::set<std::string> m_init_dirs;
583 std::string m_command_line_path;
590 OCTAVE_END_NAMESPACE(
octave)
static std::string path_sep_str()
file_info & operator=(const file_info &)=default
std::string find_mex_file(const std::string &fcn, const std::string &pack_name="")
std::function< void(const std::string &)> get_remove_hook()
void set_add_hook(const std::function< void(const std::string &)> &f)
std::string find_oct_file(const std::string &fcn, const std::string &pack_name="")
void set_remove_hook(const std::function< void(const std::string &)> &f)
bool find_package(const std::string &package_name) const
std::string find_method(const std::string &class_name, const std::string &meth, const std::string &pack_name="")
std::string find_fcn(const std::string &fcn, const std::string &pack_name="")
std::string system_path() const
std::string find_fcn(const std::string &fcn, std::string &dir_name, const std::string &pack_name="")
std::function< void(const std::string &)> get_add_hook()
std::string find_private_fcn(const std::string &dir, const std::string &fcn, const std::string &pack_name="")
std::string find_fcn_file(const std::string &fcn, const std::string &pack_name="")
std::list< std::string > methods(const std::string &class_name, const std::string &pack_name="")
void set_command_line_path(const std::string &p)
std::string get_command_line_path() const
std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE const F77_DBLE * f
std::string genpath(const std::string &dir, const string_vector &skip="private")
load_path::dir_info::fcn_file_map_type get_fcn_files(const std::string &d)
class_info(const class_info &ci)
fcn_file_map_type method_file_map
fcn_file_map_type private_file_map