Mercurial > hg > octave-nkf
comparison src/load-path.h @ 7336:745a8299c2b5
[project @ 2007-12-28 20:56:55 by jwe]
author | jwe |
---|---|
date | Fri, 28 Dec 2007 20:56:58 +0000 |
parents | a1dbe9d80eee |
children | dd5cc5016487 |
comparison
equal
deleted
inserted
replaced
7335:58f5fab3ebe5 | 7336:745a8299c2b5 |
---|---|
35 OCTINTERP_API | 35 OCTINTERP_API |
36 load_path | 36 load_path |
37 { | 37 { |
38 protected: | 38 protected: |
39 | 39 |
40 load_path (void) : dir_info_list (), fcn_map () { } | 40 load_path (void) : dir_info_list (), fcn_map (), method_map () { } |
41 | 41 |
42 public: | 42 public: |
43 | 43 |
44 typedef void (*hook_function_ptr) (const std::string& dir); | 44 typedef void (*hook_fcn_ptr) (const std::string& dir); |
45 | 45 |
46 ~load_path (void) { } | 46 ~load_path (void) { } |
47 | 47 |
48 static void initialize (bool set_initial_path = false) | 48 static void initialize (bool set_initial_path = false) |
49 { | 49 { |
84 { | 84 { |
85 if (instance_ok ()) | 85 if (instance_ok ()) |
86 instance->do_update (); | 86 instance->do_update (); |
87 } | 87 } |
88 | 88 |
89 static std::string find_method (const std::string& class_name, | |
90 const std::string& meth, | |
91 std::string& dir_name) | |
92 { | |
93 return instance_ok () | |
94 ? instance->do_find_method (class_name, meth, dir_name) : std::string (); | |
95 } | |
96 | |
97 static std::string find_method (const std::string& class_name, | |
98 const std::string& meth) | |
99 { | |
100 std::string dir_name; | |
101 return find_method (class_name, meth, dir_name); | |
102 } | |
103 | |
104 static std::list<std::string> methods (const std::string& class_name) | |
105 { | |
106 return instance_ok () | |
107 ? instance->do_methods (class_name) : std::list<std::string> (); | |
108 } | |
109 | |
110 static std::string find_fcn (const std::string& fcn, std::string& dir_name) | |
111 { | |
112 return instance_ok () | |
113 ? instance->do_find_fcn (fcn, dir_name) : std::string (); | |
114 } | |
115 | |
89 static std::string find_fcn (const std::string& fcn) | 116 static std::string find_fcn (const std::string& fcn) |
90 { | 117 { |
91 return instance_ok () | 118 std::string dir_name; |
92 ? instance->do_find_fcn (fcn) : std::string (); | 119 return find_fcn (fcn, dir_name); |
120 } | |
121 | |
122 static std::string find_private_fcn (const std::string& dir, | |
123 const std::string& fcn) | |
124 { | |
125 return instance_ok () | |
126 ? instance->do_find_private_fcn (dir, fcn) : std::string (); | |
93 } | 127 } |
94 | 128 |
95 static std::string find_fcn_file (const std::string& fcn) | 129 static std::string find_fcn_file (const std::string& fcn) |
96 { | 130 { |
131 std::string dir_name; | |
132 | |
97 return instance_ok () ? | 133 return instance_ok () ? |
98 instance->do_find_fcn (fcn, M_FILE) : std::string (); | 134 instance->do_find_fcn (fcn, dir_name, M_FILE) : std::string (); |
99 } | 135 } |
100 | 136 |
101 static std::string find_oct_file (const std::string& fcn) | 137 static std::string find_oct_file (const std::string& fcn) |
102 { | 138 { |
139 std::string dir_name; | |
140 | |
103 return instance_ok () ? | 141 return instance_ok () ? |
104 instance->do_find_fcn (fcn, OCT_FILE) : std::string (); | 142 instance->do_find_fcn (fcn, dir_name, OCT_FILE) : std::string (); |
105 } | 143 } |
106 | 144 |
107 static std::string find_mex_file (const std::string& fcn) | 145 static std::string find_mex_file (const std::string& fcn) |
108 { | 146 { |
147 std::string dir_name; | |
148 | |
109 return instance_ok () ? | 149 return instance_ok () ? |
110 instance->do_find_fcn (fcn, MEX_FILE) : std::string (); | 150 instance->do_find_fcn (fcn, dir_name, MEX_FILE) : std::string (); |
111 } | 151 } |
112 | 152 |
113 static std::string find_file (const std::string& file) | 153 static std::string find_file (const std::string& file) |
114 { | 154 { |
115 return instance_ok () | 155 return instance_ok () |
158 { | 198 { |
159 if (instance_ok ()) | 199 if (instance_ok ()) |
160 instance->do_display (os); | 200 instance->do_display (os); |
161 } | 201 } |
162 | 202 |
163 static void set_add_hook (hook_function_ptr f) { add_hook = f; } | 203 static void set_add_hook (hook_fcn_ptr f) { add_hook = f; } |
164 | 204 |
165 static void set_remove_hook (hook_function_ptr f) { remove_hook = f; } | 205 static void set_remove_hook (hook_fcn_ptr f) { remove_hook = f; } |
166 | 206 |
167 static void set_command_line_path (const std::string& p) | 207 static void set_command_line_path (const std::string& p) |
168 { | 208 { |
169 if (command_line_path.empty ()) | 209 if (command_line_path.empty ()) |
170 command_line_path = p; | 210 command_line_path = p; |
185 | 225 |
186 class dir_info | 226 class dir_info |
187 { | 227 { |
188 public: | 228 public: |
189 | 229 |
230 // <FCN_NAME, TYPE> | |
231 typedef std::map<std::string, int> fcn_file_map_type; | |
232 | |
233 typedef fcn_file_map_type::const_iterator const_fcn_file_map_iterator; | |
234 typedef fcn_file_map_type::iterator fcn_file_map_iterator; | |
235 | |
236 // <CLASS_NAME, <FCN_NAME, TYPE>> | |
237 typedef std::map<std::string, fcn_file_map_type> method_file_map_type; | |
238 | |
239 typedef method_file_map_type::const_iterator const_method_file_map_iterator; | |
240 typedef method_file_map_type::iterator method_file_map_iterator; | |
241 | |
190 dir_info (const std::string& d) : dir_name (d) { initialize (); } | 242 dir_info (const std::string& d) : dir_name (d) { initialize (); } |
191 | 243 |
192 dir_info (const dir_info& di) | 244 dir_info (const dir_info& di) |
193 : dir_name (di.dir_name), is_relative (di.is_relative), | 245 : dir_name (di.dir_name), is_relative (di.is_relative), |
194 dir_mtime (di.dir_mtime), all_files (di.all_files), | 246 dir_mtime (di.dir_mtime), all_files (di.all_files), |
195 fcn_files (di.fcn_files), | 247 fcn_files (di.fcn_files), |
196 private_function_map (di.private_function_map) { } | 248 private_file_map (di.private_file_map), |
249 method_file_map (di.method_file_map) { } | |
197 | 250 |
198 ~dir_info (void) { } | 251 ~dir_info (void) { } |
199 | 252 |
200 dir_info& operator = (const dir_info& di) | 253 dir_info& operator = (const dir_info& di) |
201 { | 254 { |
204 dir_name = di.dir_name; | 257 dir_name = di.dir_name; |
205 is_relative = di.is_relative; | 258 is_relative = di.is_relative; |
206 dir_mtime = di.dir_mtime; | 259 dir_mtime = di.dir_mtime; |
207 all_files = di.all_files; | 260 all_files = di.all_files; |
208 fcn_files = di.fcn_files; | 261 fcn_files = di.fcn_files; |
209 private_function_map = di.private_function_map; | 262 private_file_map = di.private_file_map; |
263 method_file_map = di.method_file_map; | |
210 } | 264 } |
211 | 265 |
212 return *this; | 266 return *this; |
213 } | 267 } |
214 | 268 |
217 std::string dir_name; | 271 std::string dir_name; |
218 bool is_relative; | 272 bool is_relative; |
219 octave_time dir_mtime; | 273 octave_time dir_mtime; |
220 string_vector all_files; | 274 string_vector all_files; |
221 string_vector fcn_files; | 275 string_vector fcn_files; |
222 std::map<std::string, int> private_function_map; | 276 fcn_file_map_type private_file_map; |
277 method_file_map_type method_file_map; | |
223 | 278 |
224 private: | 279 private: |
225 | 280 |
226 void initialize (void); | 281 void initialize (void); |
227 | 282 |
228 bool get_file_list (const std::string& d); | 283 void get_file_list (const std::string& d); |
229 | 284 |
230 void get_private_function_map (const std::string& d); | 285 void get_private_file_map (const std::string& d); |
286 | |
287 void get_method_file_map (const std::string& d, | |
288 const std::string& class_name); | |
289 | |
290 friend fcn_file_map_type get_fcn_files (const std::string& d); | |
231 }; | 291 }; |
232 | 292 |
233 class file_info | 293 class file_info |
234 { | 294 { |
235 public: | 295 public: |
261 // First, a list of directories and the set of "public" files and | 321 // First, a list of directories and the set of "public" files and |
262 // private files (those found in the special "private" subdirectory) | 322 // private files (those found in the special "private" subdirectory) |
263 // in each directory. | 323 // in each directory. |
264 // | 324 // |
265 // Second, a map from file names (the union of all "public" files for all | 325 // Second, a map from file names (the union of all "public" files for all |
266 // directories, but without filename exteinsions) to a list of | 326 // directories, but without filename extensions) to a list of |
267 // corresponding information (directory name and file types). This | 327 // corresponding information (directory name and file types). This |
268 // way, we can quickly find shadowed file names and look up all | 328 // way, we can quickly find shadowed file names and look up all |
269 // overloaded functions (in the "@" directories used to implement | 329 // overloaded functions (in the "@" directories used to implement |
270 // classes). | 330 // classes). |
271 | 331 |
272 mutable std::list<dir_info> dir_info_list; | 332 typedef std::list<dir_info> dir_info_list_type; |
273 | 333 |
274 mutable std::map<std::string, std::list<file_info> > fcn_map; | 334 typedef dir_info_list_type::const_iterator const_dir_info_list_iterator; |
335 typedef dir_info_list_type::iterator dir_info_list_iterator; | |
336 | |
337 typedef std::list<file_info> file_info_list_type; | |
338 | |
339 typedef file_info_list_type::const_iterator const_file_info_list_iterator; | |
340 typedef file_info_list_type::iterator file_info_list_iterator; | |
341 | |
342 // <FCN_NAME, FILE_INFO_LIST> | |
343 typedef std::map<std::string, file_info_list_type> fcn_map_type; | |
344 | |
345 typedef fcn_map_type::const_iterator const_fcn_map_iterator; | |
346 typedef fcn_map_type::iterator fcn_map_iterator; | |
347 | |
348 // <DIR_NAME, <FCN_NAME, TYPE>> | |
349 typedef std::map<std::string, dir_info::fcn_file_map_type> private_fcn_map_type; | |
350 | |
351 typedef private_fcn_map_type::const_iterator const_private_fcn_map_iterator; | |
352 typedef private_fcn_map_type::iterator private_fcn_map_iterator; | |
353 | |
354 // <CLASS_NAME, <FCN_NAME, FILE_INFO_LIST>> | |
355 typedef std::map<std::string, fcn_map_type> method_map_type; | |
356 | |
357 typedef method_map_type::const_iterator const_method_map_iterator; | |
358 typedef method_map_type::iterator method_map_iterator; | |
359 | |
360 mutable dir_info_list_type dir_info_list; | |
361 | |
362 mutable fcn_map_type fcn_map; | |
363 | |
364 mutable private_fcn_map_type private_fcn_map; | |
365 | |
366 mutable method_map_type method_map; | |
275 | 367 |
276 static load_path *instance; | 368 static load_path *instance; |
277 | 369 |
278 static hook_function_ptr add_hook; | 370 static hook_fcn_ptr add_hook; |
279 | 371 |
280 static hook_function_ptr remove_hook; | 372 static hook_fcn_ptr remove_hook; |
281 | 373 |
282 static std::string command_line_path; | 374 static std::string command_line_path; |
283 | 375 |
284 static std::string sys_path; | 376 static std::string sys_path; |
285 | 377 |
286 static bool instance_ok (void); | 378 static bool instance_ok (void); |
287 | |
288 typedef std::list<dir_info>::const_iterator const_dir_info_list_iterator; | |
289 typedef std::list<dir_info>::iterator dir_info_list_iterator; | |
290 | |
291 typedef std::map<std::string, std::list<file_info> >::const_iterator const_fcn_map_iterator; | |
292 typedef std::map<std::string, std::list<file_info> >::iterator fcn_map_iterator; | |
293 | |
294 typedef std::list<file_info>::const_iterator const_file_info_list_iterator; | |
295 typedef std::list<file_info>::iterator file_info_list_iterator; | |
296 | 379 |
297 const_dir_info_list_iterator find_dir_info (const std::string& dir) const; | 380 const_dir_info_list_iterator find_dir_info (const std::string& dir) const; |
298 dir_info_list_iterator find_dir_info (const std::string& dir); | 381 dir_info_list_iterator find_dir_info (const std::string& dir); |
299 | 382 |
300 bool contains (const std::string& dir) const; | 383 bool contains (const std::string& dir) const; |
301 | 384 |
385 void move_fcn_map (const std::string& dir, | |
386 const string_vector& fcn_files, bool at_end); | |
387 | |
388 void move_method_map (const std::string& dir, bool at_end); | |
389 | |
302 void move (std::list<dir_info>::iterator i, bool at_end); | 390 void move (std::list<dir_info>::iterator i, bool at_end); |
303 | 391 |
304 void do_initialize (bool set_initial_path); | 392 void do_initialize (bool set_initial_path); |
305 | 393 |
306 void do_clear (void); | 394 void do_clear (void); |
311 | 399 |
312 void do_prepend (const std::string& dir, bool warn); | 400 void do_prepend (const std::string& dir, bool warn); |
313 | 401 |
314 void do_add (const std::string& dir, bool at_end, bool warn); | 402 void do_add (const std::string& dir, bool at_end, bool warn); |
315 | 403 |
404 void remove_fcn_map (const std::string& dir, const string_vector& fcn_files); | |
405 | |
406 void remove_private_fcn_map (const std::string& dir); | |
407 | |
408 void remove_method_map (const std::string& dir); | |
409 | |
316 bool do_remove (const std::string& dir); | 410 bool do_remove (const std::string& dir); |
317 | 411 |
318 void do_update (void) const; | 412 void do_update (void) const; |
319 | 413 |
414 static bool | |
415 check_file_type (std::string& fname, int type, int possible_types, | |
416 const std::string& fcn, const char *who); | |
417 | |
320 std::string do_find_fcn (const std::string& fcn, | 418 std::string do_find_fcn (const std::string& fcn, |
419 std::string& dir_name, | |
321 int type = M_FILE | OCT_FILE | MEX_FILE) const; | 420 int type = M_FILE | OCT_FILE | MEX_FILE) const; |
322 | 421 |
422 std::string do_find_private_fcn (const std::string& dir, | |
423 const std::string& fcn, | |
424 int type = M_FILE | OCT_FILE | MEX_FILE) const; | |
425 | |
426 std::string do_find_method (const std::string& class_name, | |
427 const std::string& meth, | |
428 std::string& dir_name, | |
429 int type = M_FILE | OCT_FILE | MEX_FILE) const; | |
430 | |
431 std::list<std::string> do_methods (const std::string& class_name) const; | |
432 | |
323 std::string do_find_file (const std::string& file) const; | 433 std::string do_find_file (const std::string& file) const; |
324 | 434 |
325 std::string do_find_first_of (const string_vector& files) const; | 435 std::string do_find_first_of (const string_vector& files) const; |
326 | 436 |
327 string_vector do_find_all_first_of (const string_vector& files) const; | 437 string_vector do_find_all_first_of (const string_vector& files) const; |
334 | 444 |
335 string_vector do_fcn_names (void) const; | 445 string_vector do_fcn_names (void) const; |
336 | 446 |
337 std::string do_path (void) const; | 447 std::string do_path (void) const; |
338 | 448 |
449 friend void print_types (std::ostream& os, int types); | |
450 | |
451 friend string_vector get_file_list (const dir_info::fcn_file_map_type& lst); | |
452 | |
453 friend void | |
454 print_fcn_list (std::ostream& os, const dir_info::fcn_file_map_type& lst); | |
455 | |
339 void do_display (std::ostream& os) const; | 456 void do_display (std::ostream& os) const; |
340 | 457 |
341 std::string do_system_path (void) const { return sys_path; } | 458 std::string do_system_path (void) const { return sys_path; } |
342 | 459 |
343 void add_to_fcn_map (const dir_info& di, bool at_end) const; | 460 void add_to_fcn_map (const dir_info& di, bool at_end) const; |
461 | |
462 void add_to_private_fcn_map (const dir_info& di) const; | |
463 | |
464 void add_to_method_map (const dir_info& di, bool at_end) const; | |
465 | |
466 friend dir_info::fcn_file_map_type get_fcn_files (const std::string& d); | |
344 }; | 467 }; |
345 | 468 |
346 extern std::string | 469 extern std::string |
347 genpath (const std::string& dir, const string_vector& skip = "private"); | 470 genpath (const std::string& dir, const string_vector& skip = "private"); |
348 | 471 |