24 #if !defined (octave_load_path_h)
25 #define octave_load_path_h 1
42 : loader_map (), default_loader (), dir_info_list (), init_dirs () { }
46 typedef void (*hook_fcn_ptr) (
const std::string& dir);
59 instance->do_clear ();
62 static void set (
const std::string& p,
bool warn =
false)
65 instance->do_set (p, warn);
68 static void append (
const std::string& dir,
bool warn =
false)
71 instance->do_append (dir, warn);
74 static void prepend (
const std::string& dir,
bool warn =
false)
77 instance->do_prepend (dir, warn);
80 static bool remove (
const std::string& dir)
82 return instance_ok () ? instance->do_remove (dir) :
false;
88 instance->do_update ();
93 return instance_ok () ? instance->do_contains_canonical (dir_name) :
false;
96 static std::string
find_method (
const std::string& class_name,
97 const std::string& meth,
98 std::string& dir_name,
99 const std::string& pack_name = std::string ())
101 return instance_ok ()
102 ? instance->get_loader (pack_name).find_method (class_name, meth,
108 const std::string& meth,
109 const std::string& pack_name = std::string ())
111 std::string dir_name;
112 return find_method (class_name, meth, dir_name, pack_name);
115 static std::list<std::string>
methods (
const std::string& class_name,
116 const std::string& pack_name = std::string ())
118 return instance_ok ()
119 ? instance->get_loader(pack_name).methods (class_name)
120 : std::list<std::string> ();
123 static std::list<std::string>
overloads (
const std::string& meth)
125 return instance_ok ()
126 ? instance->do_overloads (meth) : std::list<std::string> ();
131 return instance_ok ()
132 ? instance->do_find_package (package_name) :
false;
135 static std::list<std::string>
138 return instance_ok ()
139 ? instance->do_get_all_package_names (only_top_level)
140 : std::list<std::string> ();
143 static std::string
find_fcn (
const std::string& fcn, std::string& dir_name,
144 const std::string& pack_name = std::string ())
146 return instance_ok ()
147 ? instance->get_loader (pack_name).find_fcn (fcn, dir_name)
151 static std::string
find_fcn (
const std::string& fcn,
152 const std::string& pack_name = std::string ())
154 std::string dir_name;
155 return find_fcn (fcn, dir_name, pack_name);
159 const std::string& fcn,
160 const std::string& pack_name = std::string ())
162 return instance_ok ()
163 ? instance->get_loader (pack_name).find_private_fcn (dir, fcn)
168 const std::string& pack_name = std::string ())
170 std::string dir_name;
172 return instance_ok ()
173 ? instance->get_loader (pack_name).find_fcn (fcn, dir_name, M_FILE)
178 const std::string& pack_name = std::string ())
180 std::string dir_name;
182 return instance_ok ()
183 ? instance->get_loader (pack_name).find_fcn (fcn, dir_name, M_FILE)
188 const std::string& pack_name = std::string ())
190 std::string dir_name;
192 return instance_ok ()
193 ? instance->get_loader (pack_name).find_fcn (fcn, dir_name, M_FILE)
199 return instance_ok ()
200 ? instance->do_find_file (file) : std::string ();
203 static std::string
find_dir (
const std::string& dir)
205 return instance_ok ()
206 ? instance->do_find_dir (dir) : std::string ();
211 return instance_ok ()
217 return instance_ok () ?
218 instance->do_find_first_of (files) : std::string ();
223 return instance_ok () ?
229 return instance_ok () ? instance->do_dirs () :
string_vector ();
234 return instance_ok ()
235 ? instance->do_dir_list () : std::list<std::string> ();
240 return instance_ok ()
246 return instance_ok () ? instance->do_fcn_names () :
string_vector ();
251 return instance_ok () ? instance->do_path () : std::string ();
257 instance->do_display (os);
274 return instance_ok () ? instance->do_get_command_line_path ()
280 return instance_ok () ? instance->do_system_path () : std::string ();
285 static const int M_FILE = 1;
286 static const int OCT_FILE = 2;
287 static const int MEX_FILE = 4;
301 class_info (
void) : method_file_map (), private_file_map () { }
304 : method_file_map (ci.method_file_map),
305 private_file_map (ci.private_file_map) { }
339 : dir_name (), abs_dir_name (), is_relative (false),
340 dir_mtime (), dir_time_last_checked (),
341 all_files (), fcn_files (), private_file_map (), method_file_map (),
346 : dir_name (d), abs_dir_name (), is_relative (false),
347 dir_mtime (), dir_time_last_checked (),
348 all_files (), fcn_files (), private_file_map (), method_file_map (),
355 : dir_name (di.dir_name), abs_dir_name (di.abs_dir_name),
356 is_relative (di.is_relative),
357 dir_mtime (di.dir_mtime),
358 dir_time_last_checked (di.dir_time_last_checked),
359 all_files (di.all_files), fcn_files (di.fcn_files),
360 private_file_map (di.private_file_map),
361 method_file_map (di.method_file_map),
362 package_dir_map (di.package_dir_map) { }
398 bool is_package (
const std::string& name)
const;
406 void get_private_file_map (
const std::string&
d);
408 void get_method_file_map (
const std::string&
d,
409 const std::string& class_name);
411 void get_package_dir (
const std::string&
d,
412 const std::string& package_name);
421 file_info (
const std::string&
d,
int t) : dir_name (d), types (t) { }
424 : dir_name (fi.dir_name), types (fi.types) { }
478 typedef std::map<std::string, dir_info::fcn_file_map_type>
493 loader (
const std::string& pfx = std::string ())
494 : prefix (pfx), dir_list (), fcn_map (), private_fcn_map (),
498 : prefix (l.prefix), dir_list (l.dir_list),
499 private_fcn_map (l.private_fcn_map), method_map (l.method_map) { }
524 add_to_fcn_map (di, at_end);
526 add_to_private_fcn_map (di);
528 add_to_method_map (di, at_end);
531 void move (
const dir_info& di,
bool at_end);
541 private_fcn_map.clear ();
546 void display (std::ostream& out)
const;
548 std::string find_fcn (
const std::string& fcn,
549 std::string& dir_name,
550 int type = M_FILE | OCT_FILE | MEX_FILE)
const;
552 std::string find_private_fcn (
const std::string& dir,
553 const std::string& fcn,
554 int type = M_FILE | OCT_FILE | MEX_FILE)
const;
556 std::string find_method (
const std::string& class_name,
557 const std::string& meth,
558 std::string& dir_name,
559 int type = M_FILE | OCT_FILE | MEX_FILE)
const;
561 std::list<std::string> methods (
const std::string& class_name)
const;
563 void overloads (
const std::string& meth, std::list<std::string>& l)
const;
568 void add_to_fcn_map (
const dir_info& di,
bool at_end);
570 void add_to_private_fcn_map (
const dir_info& di);
572 void add_to_method_map (
const dir_info& di,
bool at_end);
574 void move_fcn_map (
const std::string& dir,
577 void move_method_map (
const std::string& dir,
bool at_end);
579 void remove_fcn_map (
const std::string& dir,
582 void remove_private_fcn_map (
const std::string& dir);
584 void remove_method_map (
const std::string& dir);
626 static bool instance_ok (
void);
628 const_dir_info_list_iterator find_dir_info (
const std::string& dir)
const;
629 dir_info_list_iterator find_dir_info (
const std::string& dir);
631 bool contains (
const std::string& dir)
const;
633 bool do_contains_canonical (
const std::string& dir)
const;
635 void do_move (dir_info_list_iterator i,
bool at_end);
637 void move (
const dir_info& di,
bool at_end,
638 const std::string& pname = std::string ());
641 const std::string& pname = std::string ());
645 void do_clear (
void);
647 void do_set (
const std::string& p,
bool warn,
bool is_init =
false);
649 void do_append (
const std::string& dir,
bool warn);
651 void do_prepend (
const std::string& dir,
bool warn);
653 void do_add (
const std::string& dir,
bool at_end,
bool warn);
655 bool do_remove (
const std::string& dir);
657 void do_update (
void)
const;
660 check_file_type (std::string& fname,
int type,
int possible_types,
661 const std::string& fcn,
const char *who);
663 bool is_package (
const std::string& name)
const;
667 if (! name.empty () && is_package (name))
669 loader_map_iterator l = loader_map.find (name);
671 if (l == loader_map.end ())
672 l = loader_map.insert (loader_map.end (),
673 loader_map_type::value_type (name,
loader (name)));
678 return default_loader;
681 std::list<std::string> do_overloads (
const std::string& meth)
const;
685 return (loader_map.find (package_name) != loader_map.end ());
688 std::list<std::string> do_get_all_package_names (
bool only_top_level)
const;
690 std::string do_find_file (
const std::string& file)
const;
692 std::string do_find_dir (
const std::string& dir)
const;
694 string_vector do_find_matching_dirs (
const std::string& dir)
const;
696 std::string do_find_first_of (
const string_vector& files)
const;
702 std::list<std::string> do_dir_list (
void)
const;
704 string_vector do_files (
const std::string& dir,
bool omit_exts)
const;
708 std::string do_path (
void)
const;
710 friend void print_types (std::ostream& os,
int types);
715 print_fcn_list (std::ostream& os,
const dir_info::fcn_file_map_type& lst);
717 void do_display (std::ostream& os)
const;
724 void add (
const dir_info& di,
bool at_end,
725 const std::string& pname = std::string ())
const;
727 friend dir_info::fcn_file_map_type
get_fcn_files (
const std::string&
d);
fcn_map_type::iterator fcn_map_iterator
std::string do_get_command_line_path(void) const
static std::string system_path(void)
std::set< std::string > init_dirs
method_file_map_type method_file_map
static string_vector find_matching_dirs(const std::string &dir)
fcn_file_map_type private_file_map
static std::string find_private_fcn(const std::string &dir, const std::string &fcn, const std::string &pack_name=std::string())
file_info(const std::string &d, int t)
method_map_type::iterator method_map_iterator
static void display(std::ostream &os)
std::map< std::string, fcn_map_type > method_map_type
static std::string path_sep_str(void)
static void prepend(const std::string &dir, bool warn=false)
std::map< std::string, int > fcn_file_map_type
static std::string command_line_path
dir_info_list_type::iterator dir_info_list_iterator
static void append(const std::string &dir, bool warn=false)
std::map< std::string, loader > loader_map_type
std::map< std::string, dir_info > package_dir_map_type
static std::string find_fcn(const std::string &fcn, std::string &dir_name, const std::string &pack_name=std::string())
loader & get_loader(const std::string &name) const
std::string genpath(const std::string &dir, const string_vector &skip="private")
static std::string find_file(const std::string &file)
static std::string find_first_of(const string_vector &files)
file_info_list_type::const_iterator const_file_info_list_iterator
fcn_file_map_type private_file_map
dir_info_list_type dir_info_list
std::string do_system_path(void) const
private_fcn_map_type::const_iterator const_private_fcn_map_iterator
static abs_dir_cache_type abs_dir_cache
private_fcn_map_type::iterator private_fcn_map_iterator
package_dir_map_type::iterator package_dir_map_iterator
static void set_command_line_path(const std::string &p)
static std::string find_mex_file(const std::string &fcn, const std::string &pack_name=std::string())
method_map_type::const_iterator const_method_map_iterator
static string_vector files(const std::string &dir, bool omit_exts=false)
void print_fcn_list(std::ostream &os, const load_path::dir_info::fcn_file_map_type &lst)
void execute_pkg_add(const std::string &dir)
F77_RET_T const double const double double * d
octave_time dir_time_last_checked
static std::string find_method(const std::string &class_name, const std::string &meth, const std::string &pack_name=std::string())
void execute_pkg_del(const std::string &dir)
method_file_map_type::iterator method_file_map_iterator
static std::string find_oct_file(const std::string &fcn, const std::string &pack_name=std::string())
static hook_fcn_ptr remove_hook
std::list< file_info > file_info_list_type
static void cleanup_instance(void)
static std::list< std::string > command_line_path
static string_vector fcn_names(void)
method_map_type method_map
std::map< std::string, file_info_list_type > fcn_map_type
std::list< std::string > dir_list
F77_RET_T const double const double * f
static hook_fcn_ptr add_hook
loader(const std::string &pfx=std::string())
string_vector get_file_list(const load_path::dir_info::fcn_file_map_type &lst)
private_fcn_map_type private_fcn_map
fcn_file_map_type::const_iterator const_fcn_file_map_iterator
static std::string sys_path
std::map< std::string, dir_info > abs_dir_cache_type
void add(const dir_info &di, bool at_end)
static void initialize(bool set_initial_path=false)
class_info(const class_info &ci)
dir_info_list_type::const_iterator const_dir_info_list_iterator
static std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name=std::string())
std::list< dir_info > dir_info_list_type
static bool contains_canonical(const std::string &dir_name)
file_info_list_type::iterator file_info_list_iterator
loader_map_type::iterator loader_map_iterator
abs_dir_cache_type::iterator abs_dir_cache_iterator
package_dir_map_type::const_iterator const_package_dir_map_iterator
static load_path * instance
load_path::dir_info::fcn_file_map_type get_fcn_files(const std::string &d)
static std::list< std::string > methods(const std::string &class_name, const std::string &pack_name=std::string())
static std::string find_fcn_file(const std::string &fcn, const std::string &pack_name=std::string())
method_file_map_type::const_iterator const_method_file_map_iterator
void print_types(std::ostream &os, int types)
static bool set_initial_path
static std::list< std::string > overloads(const std::string &meth)
file_info(const file_info &fi)
dir_info(const std::string &d)
abs_dir_cache_type::const_iterator const_abs_dir_cache_iterator
fcn_map_type::const_iterator const_fcn_map_iterator
fcn_file_map_type method_file_map
static string_vector dirs(void)
fcn_file_map_type::iterator fcn_file_map_iterator
static std::list< std::string > dir_list(void)
bool do_find_package(const std::string &package_name) const
static void set_remove_hook(hook_fcn_ptr f)
static std::string find_dir(const std::string &dir)
package_dir_map_type package_dir_map
static std::string find_fcn(const std::string &fcn, const std::string &pack_name=std::string())
loader_map_type::const_iterator const_loader_map_iterator
static void set(const std::string &p, bool warn=false)
static std::string get_command_line_path(void)
loader_map_type loader_map
static void initialize(void)
std::map< std::string, dir_info::fcn_file_map_type > private_fcn_map_type
static std::string path(void)
std::map< std::string, class_info > method_file_map_type
static string_vector find_all_first_of(const string_vector &files)
static bool find_package(const std::string &package_name)
static std::list< std::string > get_all_package_names(bool only_top_level=true)
static void set_add_hook(hook_fcn_ptr f)
dir_info(const dir_info &di)