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