comparison src/load-path.h @ 15008:ff9a638a5555

preserve order of path elements when doing "path (new_path)" * load-path.cc, load-path.h (load_path::do_clear): Delete argument. Simply clear dir_info_list. (load_path::do_set, load_path::do_append, load_path::do_add): Eliminate is_init argument. (load_path::dir_info::is_init): Delete data member and all uses. (load_path::init_dirs): New data member. (load_path::do_set): Store default path elements in list and set. Warn about altering default load path. Preserve order of path elements.
author John W. Eaton <jwe@octave.org>
date Tue, 24 Jul 2012 13:13:45 -0400
parents f7afecdd87ef
children
comparison
equal deleted inserted replaced
15007:8f0e3c5bfa5f 15008:ff9a638a5555
37 load_path 37 load_path
38 { 38 {
39 protected: 39 protected:
40 40
41 load_path (void) 41 load_path (void)
42 : dir_info_list (), fcn_map (), private_fcn_map (), method_map () { } 42 : dir_info_list (), fcn_map (), private_fcn_map (), method_map (),
43 init_dirs () { }
43 44
44 public: 45 public:
45 46
46 typedef void (*hook_fcn_ptr) (const std::string& dir); 47 typedef void (*hook_fcn_ptr) (const std::string& dir);
47 48
54 } 55 }
55 56
56 static void clear (void) 57 static void clear (void)
57 { 58 {
58 if (instance_ok ()) 59 if (instance_ok ())
59 { 60 instance->do_clear ();
60 std::set<std::string> no_new_elts;
61 instance->do_clear (no_new_elts);
62 }
63 } 61 }
64 62
65 static void set (const std::string& p, bool warn = false) 63 static void set (const std::string& p, bool warn = false)
66 { 64 {
67 if (instance_ok ()) 65 if (instance_ok ())
295 // This default constructor is only provided so we can create a 293 // This default constructor is only provided so we can create a
296 // std::map of dir_info objects. You should not use this 294 // std::map of dir_info objects. You should not use this
297 // constructor for any other purpose. 295 // constructor for any other purpose.
298 dir_info (void) 296 dir_info (void)
299 : dir_name (), abs_dir_name (), is_relative (false), 297 : dir_name (), abs_dir_name (), is_relative (false),
300 is_init (false), dir_mtime (), dir_time_last_checked (), 298 dir_mtime (), dir_time_last_checked (),
301 all_files (), fcn_files (), private_file_map (), method_file_map () 299 all_files (), fcn_files (), private_file_map (), method_file_map ()
302 { } 300 { }
303 301
304 dir_info (const std::string& d) 302 dir_info (const std::string& d)
305 : dir_name (d), abs_dir_name (), is_relative (false), 303 : dir_name (d), abs_dir_name (), is_relative (false),
306 is_init (false), dir_mtime (), dir_time_last_checked (), 304 dir_mtime (), dir_time_last_checked (),
307 all_files (), fcn_files (), private_file_map (), method_file_map () 305 all_files (), fcn_files (), private_file_map (), method_file_map ()
308 { 306 {
309 initialize (); 307 initialize ();
310 } 308 }
311 309
312 dir_info (const dir_info& di) 310 dir_info (const dir_info& di)
313 : dir_name (di.dir_name), abs_dir_name (di.abs_dir_name), 311 : dir_name (di.dir_name), abs_dir_name (di.abs_dir_name),
314 is_relative (di.is_relative), 312 is_relative (di.is_relative),
315 is_init (di.is_init),
316 dir_mtime (di.dir_mtime), 313 dir_mtime (di.dir_mtime),
317 dir_time_last_checked (di.dir_time_last_checked), 314 dir_time_last_checked (di.dir_time_last_checked),
318 all_files (di.all_files), fcn_files (di.fcn_files), 315 all_files (di.all_files), fcn_files (di.fcn_files),
319 private_file_map (di.private_file_map), 316 private_file_map (di.private_file_map),
320 method_file_map (di.method_file_map) { } 317 method_file_map (di.method_file_map) { }
326 if (&di != this) 323 if (&di != this)
327 { 324 {
328 dir_name = di.dir_name; 325 dir_name = di.dir_name;
329 abs_dir_name = di.abs_dir_name; 326 abs_dir_name = di.abs_dir_name;
330 is_relative = di.is_relative; 327 is_relative = di.is_relative;
331 is_init = di.is_init;
332 dir_mtime = di.dir_mtime; 328 dir_mtime = di.dir_mtime;
333 dir_time_last_checked = di.dir_time_last_checked; 329 dir_time_last_checked = di.dir_time_last_checked;
334 all_files = di.all_files; 330 all_files = di.all_files;
335 fcn_files = di.fcn_files; 331 fcn_files = di.fcn_files;
336 private_file_map = di.private_file_map; 332 private_file_map = di.private_file_map;
343 void update (void); 339 void update (void);
344 340
345 std::string dir_name; 341 std::string dir_name;
346 std::string abs_dir_name; 342 std::string abs_dir_name;
347 bool is_relative; 343 bool is_relative;
348 bool is_init; //Was this directory set by init? Warn when clearing it.
349 octave_time dir_mtime; 344 octave_time dir_mtime;
350 octave_time dir_time_last_checked; 345 octave_time dir_time_last_checked;
351 string_vector all_files; 346 string_vector all_files;
352 string_vector fcn_files; 347 string_vector fcn_files;
353 fcn_file_map_type private_file_map; 348 fcn_file_map_type private_file_map;
445 440
446 mutable private_fcn_map_type private_fcn_map; 441 mutable private_fcn_map_type private_fcn_map;
447 442
448 mutable method_map_type method_map; 443 mutable method_map_type method_map;
449 444
445 mutable std::set<std::string> init_dirs;
446
450 static load_path *instance; 447 static load_path *instance;
451 448
452 static void cleanup_instance (void) { delete instance; instance = 0; } 449 static void cleanup_instance (void) { delete instance; instance = 0; }
453 450
454 static hook_fcn_ptr add_hook; 451 static hook_fcn_ptr add_hook;
475 472
476 void move (std::list<dir_info>::iterator i, bool at_end); 473 void move (std::list<dir_info>::iterator i, bool at_end);
477 474
478 void do_initialize (bool set_initial_path); 475 void do_initialize (bool set_initial_path);
479 476
480 void do_clear (std::set<std::string>& new_elts); 477 void do_clear (void);
481 478
482 void do_set (const std::string& p, bool warn, bool is_init=false); 479 void do_set (const std::string& p, bool warn, bool is_init = false);
483 480
484 void do_append (const std::string& dir, bool warn, bool is_init=false); 481 void do_append (const std::string& dir, bool warn);
485 482
486 void do_prepend (const std::string& dir, bool warn); 483 void do_prepend (const std::string& dir, bool warn);
487 484
488 void do_add (const std::string& dir, bool at_end, bool warn, 485 void do_add (const std::string& dir, bool at_end, bool warn);
489 bool is_init=false);
490 486
491 void remove_fcn_map (const std::string& dir, const string_vector& fcn_files); 487 void remove_fcn_map (const std::string& dir, const string_vector& fcn_files);
492 488
493 void remove_private_fcn_map (const std::string& dir); 489 void remove_private_fcn_map (const std::string& dir);
494 490