Mercurial > hg > octave-lyh
annotate 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 |
rev | line source |
---|---|
5832 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
3 Copyright (C) 2006-2012 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
4 Copyright (C) 2010 VZLU Prague |
5832 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5832 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5832 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_load_path_h) | |
25 #define octave_load_path_h 1 | |
26 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
27 #include <iosfwd> |
5832 | 28 #include <list> |
29 #include <map> | |
30 #include <string> | |
31 | |
5835 | 32 #include "pathsearch.h" |
5832 | 33 #include "str-vec.h" |
34 | |
35 class | |
6241 | 36 OCTINTERP_API |
5832 | 37 load_path |
38 { | |
39 protected: | |
40 | |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8950
diff
changeset
|
41 load_path (void) |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
42 : dir_info_list (), fcn_map (), private_fcn_map (), method_map (), |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
43 init_dirs () { } |
5832 | 44 |
45 public: | |
46 | |
7336 | 47 typedef void (*hook_fcn_ptr) (const std::string& dir); |
5832 | 48 |
49 ~load_path (void) { } | |
50 | |
6365 | 51 static void initialize (bool set_initial_path = false) |
5832 | 52 { |
53 if (instance_ok ()) | |
6365 | 54 instance->do_initialize (set_initial_path); |
5832 | 55 } |
56 | |
57 static void clear (void) | |
58 { | |
59 if (instance_ok ()) | |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
60 instance->do_clear (); |
5832 | 61 } |
62 | |
5867 | 63 static void set (const std::string& p, bool warn = false) |
5832 | 64 { |
65 if (instance_ok ()) | |
5867 | 66 instance->do_set (p, warn); |
5832 | 67 } |
68 | |
5867 | 69 static void append (const std::string& dir, bool warn = false) |
5832 | 70 { |
71 if (instance_ok ()) | |
5867 | 72 instance->do_append (dir, warn); |
5832 | 73 } |
74 | |
5867 | 75 static void prepend (const std::string& dir, bool warn = false) |
5832 | 76 { |
77 if (instance_ok ()) | |
5867 | 78 instance->do_prepend (dir, warn); |
5832 | 79 } |
80 | |
81 static bool remove (const std::string& dir) | |
82 { | |
83 return instance_ok () ? instance->do_remove (dir) : false; | |
84 } | |
85 | |
86 static void update (void) | |
87 { | |
88 if (instance_ok ()) | |
89 instance->do_update (); | |
90 } | |
91 | |
7336 | 92 static std::string find_method (const std::string& class_name, |
10313 | 93 const std::string& meth, |
94 std::string& dir_name) | |
7336 | 95 { |
96 return instance_ok () | |
97 ? instance->do_find_method (class_name, meth, dir_name) : std::string (); | |
98 } | |
99 | |
100 static std::string find_method (const std::string& class_name, | |
10313 | 101 const std::string& meth) |
7336 | 102 { |
103 std::string dir_name; | |
104 return find_method (class_name, meth, dir_name); | |
105 } | |
106 | |
107 static std::list<std::string> methods (const std::string& class_name) | |
108 { | |
109 return instance_ok () | |
110 ? instance->do_methods (class_name) : std::list<std::string> (); | |
111 } | |
112 | |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
113 static std::list<std::string> overloads (const std::string& meth) |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
114 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
115 return instance_ok () |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
116 ? instance->do_overloads (meth) : std::list<std::string> (); |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
117 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
118 |
7336 | 119 static std::string find_fcn (const std::string& fcn, std::string& dir_name) |
120 { | |
121 return instance_ok () | |
122 ? instance->do_find_fcn (fcn, dir_name) : std::string (); | |
123 } | |
124 | |
5832 | 125 static std::string find_fcn (const std::string& fcn) |
126 { | |
7336 | 127 std::string dir_name; |
128 return find_fcn (fcn, dir_name); | |
129 } | |
130 | |
131 static std::string find_private_fcn (const std::string& dir, | |
10313 | 132 const std::string& fcn) |
7336 | 133 { |
5832 | 134 return instance_ok () |
7336 | 135 ? instance->do_find_private_fcn (dir, fcn) : std::string (); |
5832 | 136 } |
137 | |
138 static std::string find_fcn_file (const std::string& fcn) | |
139 { | |
7336 | 140 std::string dir_name; |
141 | |
5832 | 142 return instance_ok () ? |
7336 | 143 instance->do_find_fcn (fcn, dir_name, M_FILE) : std::string (); |
5832 | 144 } |
145 | |
146 static std::string find_oct_file (const std::string& fcn) | |
147 { | |
7336 | 148 std::string dir_name; |
149 | |
5832 | 150 return instance_ok () ? |
7336 | 151 instance->do_find_fcn (fcn, dir_name, OCT_FILE) : std::string (); |
5832 | 152 } |
153 | |
5864 | 154 static std::string find_mex_file (const std::string& fcn) |
155 { | |
7336 | 156 std::string dir_name; |
157 | |
5864 | 158 return instance_ok () ? |
7336 | 159 instance->do_find_fcn (fcn, dir_name, MEX_FILE) : std::string (); |
5864 | 160 } |
161 | |
5832 | 162 static std::string find_file (const std::string& file) |
163 { | |
164 return instance_ok () | |
165 ? instance->do_find_file (file) : std::string (); | |
166 } | |
167 | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
168 static std::string find_dir (const std::string& dir) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
169 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
170 return instance_ok () |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
171 ? instance->do_find_dir (dir) : std::string (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
172 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
173 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
174 static string_vector find_matching_dirs (const std::string& dir) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
175 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
176 return instance_ok () |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
177 ? instance->do_find_matching_dirs (dir) : string_vector (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
178 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
179 |
5832 | 180 static std::string find_first_of (const string_vector& files) |
181 { | |
182 return instance_ok () ? | |
183 instance->do_find_first_of (files) : std::string (); | |
184 } | |
185 | |
186 static string_vector find_all_first_of (const string_vector& files) | |
187 { | |
188 return instance_ok () ? | |
189 instance->do_find_all_first_of (files) : string_vector (); | |
190 } | |
191 | |
192 static string_vector dirs (void) | |
193 { | |
194 return instance_ok () ? instance->do_dirs () : string_vector (); | |
195 } | |
196 | |
197 static std::list<std::string> dir_list (void) | |
198 { | |
199 return instance_ok () | |
200 ? instance->do_dir_list () : std::list<std::string> (); | |
201 } | |
202 | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
203 static string_vector files (const std::string& dir, bool omit_exts = false) |
5832 | 204 { |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
205 return instance_ok () |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
206 ? instance->do_files (dir, omit_exts) : string_vector (); |
5832 | 207 } |
208 | |
209 static string_vector fcn_names (void) | |
210 { | |
211 return instance_ok () ? instance->do_fcn_names () : string_vector (); | |
212 } | |
213 | |
214 static std::string path (void) | |
215 { | |
216 return instance_ok () ? instance->do_path () : std::string (); | |
217 } | |
218 | |
219 static void display (std::ostream& os) | |
220 { | |
221 if (instance_ok ()) | |
222 instance->do_display (os); | |
223 } | |
224 | |
7336 | 225 static void set_add_hook (hook_fcn_ptr f) { add_hook = f; } |
5832 | 226 |
7336 | 227 static void set_remove_hook (hook_fcn_ptr f) { remove_hook = f; } |
5832 | 228 |
229 static void set_command_line_path (const std::string& p) | |
230 { | |
5835 | 231 if (command_line_path.empty ()) |
232 command_line_path = p; | |
233 else | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7971
diff
changeset
|
234 command_line_path += dir_path::path_sep_str () + p; |
5832 | 235 } |
236 | |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
237 static std::string get_command_line_path (void) |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
238 { |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
239 return instance_ok () ? instance->do_get_command_line_path () : std::string (); |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
240 } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
241 |
6626 | 242 static std::string system_path (void) |
243 { | |
6630 | 244 return instance_ok () ? instance->do_system_path () : std::string (); |
6626 | 245 } |
246 | |
5832 | 247 private: |
248 | |
249 static const int M_FILE = 1; | |
250 static const int OCT_FILE = 2; | |
5864 | 251 static const int MEX_FILE = 4; |
5832 | 252 |
253 class dir_info | |
254 { | |
255 public: | |
256 | |
7336 | 257 // <FCN_NAME, TYPE> |
258 typedef std::map<std::string, int> fcn_file_map_type; | |
259 | |
260 typedef fcn_file_map_type::const_iterator const_fcn_file_map_iterator; | |
261 typedef fcn_file_map_type::iterator fcn_file_map_iterator; | |
262 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
263 struct class_info |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
264 { |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
265 class_info (void) : method_file_map (), private_file_map () { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
266 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
267 class_info (const class_info& ci) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
268 : method_file_map (ci.method_file_map), |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
269 private_file_map (ci.private_file_map) { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
270 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
271 class_info& operator = (const class_info& ci) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
272 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
273 if (this != &ci) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
274 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
275 method_file_map = ci.method_file_map; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
276 private_file_map = ci.private_file_map; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
277 } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
278 return *this; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
279 } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
280 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
281 ~class_info (void) { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
282 |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
283 fcn_file_map_type method_file_map; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
284 fcn_file_map_type private_file_map; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
285 }; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
286 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
287 // <CLASS_NAME, CLASS_INFO> |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
288 typedef std::map<std::string, class_info> method_file_map_type; |
7336 | 289 |
290 typedef method_file_map_type::const_iterator const_method_file_map_iterator; | |
291 typedef method_file_map_type::iterator method_file_map_iterator; | |
292 | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
293 // This default constructor is only provided so we can create a |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
294 // std::map of dir_info objects. You should not use this |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
295 // constructor for any other purpose. |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
296 dir_info (void) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
297 : dir_name (), abs_dir_name (), is_relative (false), |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
298 dir_mtime (), dir_time_last_checked (), |
14376
7dd6ac033e69
Warn when the default path is overwritten
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
299 all_files (), fcn_files (), private_file_map (), method_file_map () |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
300 { } |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
301 |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
302 dir_info (const std::string& d) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
303 : dir_name (d), abs_dir_name (), is_relative (false), |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
304 dir_mtime (), dir_time_last_checked (), |
14376
7dd6ac033e69
Warn when the default path is overwritten
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
305 all_files (), fcn_files (), private_file_map (), method_file_map () |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
306 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
307 initialize (); |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10907
diff
changeset
|
308 } |
5832 | 309 |
310 dir_info (const dir_info& di) | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
311 : dir_name (di.dir_name), abs_dir_name (di.abs_dir_name), |
10313 | 312 is_relative (di.is_relative), |
313 dir_mtime (di.dir_mtime), | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
314 dir_time_last_checked (di.dir_time_last_checked), |
10313 | 315 all_files (di.all_files), fcn_files (di.fcn_files), |
316 private_file_map (di.private_file_map), | |
317 method_file_map (di.method_file_map) { } | |
5832 | 318 |
319 ~dir_info (void) { } | |
320 | |
321 dir_info& operator = (const dir_info& di) | |
322 { | |
323 if (&di != this) | |
10313 | 324 { |
325 dir_name = di.dir_name; | |
326 abs_dir_name = di.abs_dir_name; | |
327 is_relative = di.is_relative; | |
328 dir_mtime = di.dir_mtime; | |
329 dir_time_last_checked = di.dir_time_last_checked; | |
330 all_files = di.all_files; | |
331 fcn_files = di.fcn_files; | |
332 private_file_map = di.private_file_map; | |
333 method_file_map = di.method_file_map; | |
334 } | |
5832 | 335 |
336 return *this; | |
337 } | |
338 | |
339 void update (void); | |
340 | |
341 std::string dir_name; | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
342 std::string abs_dir_name; |
5832 | 343 bool is_relative; |
344 octave_time dir_mtime; | |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
345 octave_time dir_time_last_checked; |
5832 | 346 string_vector all_files; |
347 string_vector fcn_files; | |
7336 | 348 fcn_file_map_type private_file_map; |
349 method_file_map_type method_file_map; | |
5832 | 350 |
351 private: | |
352 | |
353 void initialize (void); | |
354 | |
7336 | 355 void get_file_list (const std::string& d); |
356 | |
357 void get_private_file_map (const std::string& d); | |
5832 | 358 |
7336 | 359 void get_method_file_map (const std::string& d, |
10313 | 360 const std::string& class_name); |
7336 | 361 |
362 friend fcn_file_map_type get_fcn_files (const std::string& d); | |
5832 | 363 }; |
364 | |
365 class file_info | |
366 { | |
367 public: | |
368 | |
369 file_info (const std::string& d, int t) : dir_name (d), types (t) { } | |
370 | |
371 file_info (const file_info& fi) | |
372 : dir_name (fi.dir_name), types (fi.types) { } | |
373 | |
374 ~file_info (void) { } | |
375 | |
376 file_info& operator = (const file_info& fi) | |
377 { | |
378 if (&fi != this) | |
10313 | 379 { |
380 dir_name = fi.dir_name; | |
381 types = fi.types; | |
382 } | |
5832 | 383 |
384 return *this; | |
385 } | |
386 | |
387 std::string dir_name; | |
388 int types; | |
389 }; | |
390 | |
391 // We maintain two ways of looking at the same information. | |
392 // | |
393 // First, a list of directories and the set of "public" files and | |
394 // private files (those found in the special "private" subdirectory) | |
395 // in each directory. | |
396 // | |
397 // Second, a map from file names (the union of all "public" files for all | |
7336 | 398 // directories, but without filename extensions) to a list of |
5832 | 399 // corresponding information (directory name and file types). This |
400 // way, we can quickly find shadowed file names and look up all | |
401 // overloaded functions (in the "@" directories used to implement | |
402 // classes). | |
403 | |
7336 | 404 typedef std::list<dir_info> dir_info_list_type; |
405 | |
406 typedef dir_info_list_type::const_iterator const_dir_info_list_iterator; | |
407 typedef dir_info_list_type::iterator dir_info_list_iterator; | |
408 | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
409 typedef std::map<std::string, dir_info> abs_dir_cache_type; |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
410 |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
411 typedef abs_dir_cache_type::const_iterator const_abs_dir_cache_iterator; |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
412 typedef abs_dir_cache_type::iterator abs_dir_cache_iterator; |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
413 |
7336 | 414 typedef std::list<file_info> file_info_list_type; |
415 | |
416 typedef file_info_list_type::const_iterator const_file_info_list_iterator; | |
417 typedef file_info_list_type::iterator file_info_list_iterator; | |
418 | |
419 // <FCN_NAME, FILE_INFO_LIST> | |
420 typedef std::map<std::string, file_info_list_type> fcn_map_type; | |
421 | |
422 typedef fcn_map_type::const_iterator const_fcn_map_iterator; | |
423 typedef fcn_map_type::iterator fcn_map_iterator; | |
5832 | 424 |
7336 | 425 // <DIR_NAME, <FCN_NAME, TYPE>> |
426 typedef std::map<std::string, dir_info::fcn_file_map_type> private_fcn_map_type; | |
427 | |
428 typedef private_fcn_map_type::const_iterator const_private_fcn_map_iterator; | |
429 typedef private_fcn_map_type::iterator private_fcn_map_iterator; | |
430 | |
431 // <CLASS_NAME, <FCN_NAME, FILE_INFO_LIST>> | |
432 typedef std::map<std::string, fcn_map_type> method_map_type; | |
433 | |
434 typedef method_map_type::const_iterator const_method_map_iterator; | |
435 typedef method_map_type::iterator method_map_iterator; | |
10907
6105ed2db9d7
load_path::dir_info::initialize: clear method_file_map before updating file list
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
436 |
7336 | 437 mutable dir_info_list_type dir_info_list; |
438 | |
439 mutable fcn_map_type fcn_map; | |
440 | |
441 mutable private_fcn_map_type private_fcn_map; | |
442 | |
443 mutable method_map_type method_map; | |
5832 | 444 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
445 mutable std::set<std::string> init_dirs; |
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
446 |
5832 | 447 static load_path *instance; |
448 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
449 static void cleanup_instance (void) { delete instance; instance = 0; } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
450 |
7336 | 451 static hook_fcn_ptr add_hook; |
5832 | 452 |
7336 | 453 static hook_fcn_ptr remove_hook; |
5832 | 454 |
455 static std::string command_line_path; | |
456 | |
6626 | 457 static std::string sys_path; |
458 | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
459 static abs_dir_cache_type abs_dir_cache; |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
460 |
5832 | 461 static bool instance_ok (void); |
462 | |
463 const_dir_info_list_iterator find_dir_info (const std::string& dir) const; | |
464 dir_info_list_iterator find_dir_info (const std::string& dir); | |
465 | |
466 bool contains (const std::string& dir) const; | |
467 | |
7336 | 468 void move_fcn_map (const std::string& dir, |
10313 | 469 const string_vector& fcn_files, bool at_end); |
7336 | 470 |
471 void move_method_map (const std::string& dir, bool at_end); | |
472 | |
5832 | 473 void move (std::list<dir_info>::iterator i, bool at_end); |
474 | |
6365 | 475 void do_initialize (bool set_initial_path); |
5832 | 476 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
477 void do_clear (void); |
5832 | 478 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
479 void do_set (const std::string& p, bool warn, bool is_init = false); |
5867 | 480 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
481 void do_append (const std::string& dir, bool warn); |
5832 | 482 |
5867 | 483 void do_prepend (const std::string& dir, bool warn); |
5832 | 484 |
15008
ff9a638a5555
preserve order of path elements when doing "path (new_path)"
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
485 void do_add (const std::string& dir, bool at_end, bool warn); |
5832 | 486 |
7336 | 487 void remove_fcn_map (const std::string& dir, const string_vector& fcn_files); |
488 | |
489 void remove_private_fcn_map (const std::string& dir); | |
490 | |
491 void remove_method_map (const std::string& dir); | |
492 | |
5832 | 493 bool do_remove (const std::string& dir); |
494 | |
495 void do_update (void) const; | |
496 | |
7336 | 497 static bool |
498 check_file_type (std::string& fname, int type, int possible_types, | |
10313 | 499 const std::string& fcn, const char *who); |
7336 | 500 |
5832 | 501 std::string do_find_fcn (const std::string& fcn, |
10313 | 502 std::string& dir_name, |
503 int type = M_FILE | OCT_FILE | MEX_FILE) const; | |
5832 | 504 |
7336 | 505 std::string do_find_private_fcn (const std::string& dir, |
10313 | 506 const std::string& fcn, |
507 int type = M_FILE | OCT_FILE | MEX_FILE) const; | |
7336 | 508 |
509 std::string do_find_method (const std::string& class_name, | |
10313 | 510 const std::string& meth, |
511 std::string& dir_name, | |
512 int type = M_FILE | OCT_FILE | MEX_FILE) const; | |
7336 | 513 |
514 std::list<std::string> do_methods (const std::string& class_name) const; | |
515 | |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
516 std::list<std::string> do_overloads (const std::string& meth) const; |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9261
diff
changeset
|
517 |
5832 | 518 std::string do_find_file (const std::string& file) const; |
519 | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
520 std::string do_find_dir (const std::string& dir) const; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8008
diff
changeset
|
521 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
522 string_vector do_find_matching_dirs (const std::string& dir) const; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
523 |
5832 | 524 std::string do_find_first_of (const string_vector& files) const; |
525 | |
526 string_vector do_find_all_first_of (const string_vector& files) const; | |
527 | |
528 string_vector do_dirs (void) const; | |
529 | |
530 std::list<std::string> do_dir_list (void) const; | |
531 | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
532 string_vector do_files (const std::string& dir, bool omit_exts) const; |
5832 | 533 |
534 string_vector do_fcn_names (void) const; | |
535 | |
536 std::string do_path (void) const; | |
537 | |
7336 | 538 friend void print_types (std::ostream& os, int types); |
539 | |
540 friend string_vector get_file_list (const dir_info::fcn_file_map_type& lst); | |
541 | |
542 friend void | |
543 print_fcn_list (std::ostream& os, const dir_info::fcn_file_map_type& lst); | |
544 | |
5832 | 545 void do_display (std::ostream& os) const; |
546 | |
6629 | 547 std::string do_system_path (void) const { return sys_path; } |
6626 | 548 |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
549 std::string do_get_command_line_path (void) const { return command_line_path; } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8329
diff
changeset
|
550 |
5832 | 551 void add_to_fcn_map (const dir_info& di, bool at_end) const; |
7336 | 552 |
553 void add_to_private_fcn_map (const dir_info& di) const; | |
554 | |
555 void add_to_method_map (const dir_info& di, bool at_end) const; | |
556 | |
557 friend dir_info::fcn_file_map_type get_fcn_files (const std::string& d); | |
5832 | 558 }; |
559 | |
560 extern std::string | |
561 genpath (const std::string& dir, const string_vector& skip = "private"); | |
562 | |
563 extern void execute_pkg_add (const std::string& dir); | |
564 extern void execute_pkg_del (const std::string& dir); | |
565 | |
566 #endif |