comparison libinterp/corefcn/load-path.h @ 31607:aac27ad79be6 stable

maint: Re-indent code after switch to using namespace macros. * build-env.h, build-env.in.cc, Cell.h, __betainc__.cc, __eigs__.cc, __ftp__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __magick_read__.cc, __pchip_deriv__.cc, amd.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, dasrt.cc, data.cc, debug.cc, defaults.cc, defaults.h, det.cc, display.cc, display.h, dlmread.cc, dynamic-ld.cc, dynamic-ld.h, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, gsvd.cc, gtk-manager.cc, gtk-manager.h, help.cc, help.h, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-hdf5.cc, ls-mat4.cc, ls-mat5.cc, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mexproto.h, mxarray.h, mxtypes.in.h, oct-errno.in.cc, oct-hdf5-types.cc, oct-hist.cc, oct-hist.h, oct-map.cc, oct-map.h, oct-opengl.h, oct-prcstrm.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.h, octave-default-image.h, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-output.cc, psi.cc, qr.cc, quadcc.cc, rand.cc, regexp.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xpow.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfns.cc, svd.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, __delaunayn__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audioread.cc, convhulln.cc, gzip.cc, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.h, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-java.cc, ov-lazy-idx.cc, ov-legacy-range.cc, ov-magic-int.cc, ov-mex-fcn.cc, ov-mex-fcn.h, ov-null-mat.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, ovl.h, octave.cc, octave.h, op-b-sbm.cc, op-bm-sbm.cc, op-cs-scm.cc, op-fm-fcm.cc, op-fs-fcm.cc, op-s-scm.cc, op-scm-cs.cc, op-scm-s.cc, op-sm-cs.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, oct-lvalue.cc, oct-lvalue.h, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h: Re-indent code after switch to using namespace macros.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 18:02:15 -0800
parents e88a07dec498
children 597f3ee61a48
comparison
equal deleted inserted replaced
31605:e88a07dec498 31607:aac27ad79be6
39 #include "pathsearch.h" 39 #include "pathsearch.h"
40 #include "str-vec.h" 40 #include "str-vec.h"
41 41
42 OCTAVE_BEGIN_NAMESPACE(octave) 42 OCTAVE_BEGIN_NAMESPACE(octave)
43 43
44 class 44 class
45 OCTINTERP_API 45 OCTINTERP_API
46 load_path 46 load_path
47 {
48 public:
49
50 load_path (interpreter& interp);
51
52 typedef void (*hook_fcn_ptr) (const std::string& dir);
53
54 load_path (const load_path&) = delete;
55
56 load_path& operator = (const load_path&) = delete;
57
58 ~load_path (void) = default;
59
60 void initialize (bool set_initial_path = false);
61
62 void clear (void);
63
64 void set (const std::string& p, bool warn = false, bool is_init = false);
65
66 void append (const std::string& dir, bool warn = false);
67
68 void prepend (const std::string& dir, bool warn = false);
69
70 bool remove (const std::string& dir);
71
72 void update (void);
73
74 bool contains_canonical (const std::string& dir_name) const;
75
76 bool contains_file_in_dir (const std::string& file_name,
77 const std::string& dir_name);
78
79 std::string find_method (const std::string& class_name,
80 const std::string& meth,
81 std::string& dir_name,
82 const std::string& pack_name = "")
83 {
84 return get_package (pack_name).find_method (class_name, meth, dir_name);
85 }
86
87 std::string find_method (const std::string& class_name,
88 const std::string& meth,
89 const std::string& pack_name = "")
90 {
91 std::string dir_name;
92 return find_method (class_name, meth, dir_name, pack_name);
93 }
94
95 std::list<std::string> methods (const std::string& class_name,
96 const std::string& pack_name = "")
97 {
98 return get_package (pack_name).methods (class_name);
99 }
100
101 std::list<std::string> overloads (const std::string& meth) const;
102
103 bool find_package (const std::string& package_name) const
104 {
105 return (m_package_map.find (package_name) != m_package_map.end ());
106 }
107
108 std::list<std::string>
109 get_all_package_names (bool only_top_level = true) const;
110
111 std::string find_fcn (const std::string& fcn, std::string& dir_name,
112 const std::string& pack_name = "")
113 {
114 return get_package (pack_name).find_fcn (fcn, dir_name);
115 }
116
117 std::string find_fcn (const std::string& fcn,
118 const std::string& pack_name = "")
119 {
120 std::string dir_name;
121 return find_fcn (fcn, dir_name, pack_name);
122 }
123
124 std::string find_private_fcn (const std::string& dir,
125 const std::string& fcn,
126 const std::string& pack_name = "")
127 {
128 return get_package (pack_name).find_private_fcn (dir, fcn);
129 }
130
131 std::string find_fcn_file (const std::string& fcn,
132 const std::string& pack_name = "")
133 {
134 std::string dir_name;
135 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
136 }
137
138 std::string find_oct_file (const std::string& fcn,
139 const std::string& pack_name = "")
140 {
141 std::string dir_name;
142 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
143 }
144
145 std::string find_mex_file (const std::string& fcn,
146 const std::string& pack_name = "")
147 {
148 std::string dir_name;
149 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
150 }
151
152 std::string find_file (const std::string& file) const;
153
154 std::string find_dir (const std::string& dir) const;
155
156 string_vector find_matching_dirs (const std::string& dir) const;
157
158 std::string find_first_of (const string_vector& files) const;
159
160 string_vector find_all_first_of (const string_vector& files) const;
161
162 string_vector dirs (void) const;
163
164 std::list<std::string> dir_list (void) const;
165
166 string_vector files (const std::string& dir, bool omit_exts = false) const;
167
168 string_vector fcn_names (void) const;
169
170 std::string path (void) const;
171
172 void display (std::ostream& os) const;
173
174 std::function<void (const std::string&)> get_add_hook (void)
175 {
176 return add_hook;
177 }
178
179 std::function<void (const std::string&)> get_remove_hook (void)
180 {
181 return remove_hook;
182 }
183
184 void set_add_hook (const std::function<void (const std::string&)>& f)
185 {
186 add_hook = f;
187 }
188
189 void set_remove_hook (const std::function<void (const std::string&)>& f)
190 {
191 remove_hook = f;
192 }
193
194 void read_dir_config (const std::string& dir) const;
195
196 void execute_pkg_add (const std::string& dir);
197 void execute_pkg_del (const std::string& dir);
198
199 void set_command_line_path (const std::string& p)
200 {
201 if (m_command_line_path.empty ())
202 m_command_line_path = p;
203 else
204 m_command_line_path += directory_path::path_sep_str () + p;
205 }
206
207 std::string get_command_line_path (void) const
208 {
209 return m_command_line_path;
210 }
211
212 std::string system_path (void) const { return s_sys_path; }
213
214 static const int M_FILE = 1;
215 static const int OCT_FILE = 2;
216 static const int MEX_FILE = 4;
217
218 private:
219
220 class dir_info
47 { 221 {
48 public: 222 public:
49 223
50 load_path (interpreter& interp); 224 // <FCN_NAME, TYPE>
51 225 typedef std::map<std::string, int> fcn_file_map_type;
52 typedef void (*hook_fcn_ptr) (const std::string& dir); 226
53 227 typedef fcn_file_map_type::const_iterator const_fcn_file_map_iterator;
54 load_path (const load_path&) = delete; 228 typedef fcn_file_map_type::iterator fcn_file_map_iterator;
55 229
56 load_path& operator = (const load_path&) = delete; 230 struct class_info
57
58 ~load_path (void) = default;
59
60 void initialize (bool set_initial_path = false);
61
62 void clear (void);
63
64 void set (const std::string& p, bool warn = false, bool is_init = false);
65
66 void append (const std::string& dir, bool warn = false);
67
68 void prepend (const std::string& dir, bool warn = false);
69
70 bool remove (const std::string& dir);
71
72 void update (void);
73
74 bool contains_canonical (const std::string& dir_name) const;
75
76 bool contains_file_in_dir (const std::string& file_name,
77 const std::string& dir_name);
78
79 std::string find_method (const std::string& class_name,
80 const std::string& meth,
81 std::string& dir_name,
82 const std::string& pack_name = "")
83 {
84 return get_package (pack_name).find_method (class_name, meth, dir_name);
85 }
86
87 std::string find_method (const std::string& class_name,
88 const std::string& meth,
89 const std::string& pack_name = "")
90 {
91 std::string dir_name;
92 return find_method (class_name, meth, dir_name, pack_name);
93 }
94
95 std::list<std::string> methods (const std::string& class_name,
96 const std::string& pack_name = "")
97 {
98 return get_package (pack_name).methods (class_name);
99 }
100
101 std::list<std::string> overloads (const std::string& meth) const;
102
103 bool find_package (const std::string& package_name) const
104 {
105 return (m_package_map.find (package_name) != m_package_map.end ());
106 }
107
108 std::list<std::string>
109 get_all_package_names (bool only_top_level = true) const;
110
111 std::string find_fcn (const std::string& fcn, std::string& dir_name,
112 const std::string& pack_name = "")
113 {
114 return get_package (pack_name).find_fcn (fcn, dir_name);
115 }
116
117 std::string find_fcn (const std::string& fcn,
118 const std::string& pack_name = "")
119 {
120 std::string dir_name;
121 return find_fcn (fcn, dir_name, pack_name);
122 }
123
124 std::string find_private_fcn (const std::string& dir,
125 const std::string& fcn,
126 const std::string& pack_name = "")
127 {
128 return get_package (pack_name).find_private_fcn (dir, fcn);
129 }
130
131 std::string find_fcn_file (const std::string& fcn,
132 const std::string& pack_name = "")
133 {
134 std::string dir_name;
135 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
136 }
137
138 std::string find_oct_file (const std::string& fcn,
139 const std::string& pack_name = "")
140 {
141 std::string dir_name;
142 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
143 }
144
145 std::string find_mex_file (const std::string& fcn,
146 const std::string& pack_name = "")
147 {
148 std::string dir_name;
149 return get_package (pack_name).find_fcn (fcn, dir_name, M_FILE);
150 }
151
152 std::string find_file (const std::string& file) const;
153
154 std::string find_dir (const std::string& dir) const;
155
156 string_vector find_matching_dirs (const std::string& dir) const;
157
158 std::string find_first_of (const string_vector& files) const;
159
160 string_vector find_all_first_of (const string_vector& files) const;
161
162 string_vector dirs (void) const;
163
164 std::list<std::string> dir_list (void) const;
165
166 string_vector files (const std::string& dir, bool omit_exts = false) const;
167
168 string_vector fcn_names (void) const;
169
170 std::string path (void) const;
171
172 void display (std::ostream& os) const;
173
174 std::function<void (const std::string&)> get_add_hook (void)
175 {
176 return add_hook;
177 }
178
179 std::function<void (const std::string&)> get_remove_hook (void)
180 {
181 return remove_hook;
182 }
183
184 void set_add_hook (const std::function<void (const std::string&)>& f)
185 {
186 add_hook = f;
187 }
188
189 void set_remove_hook (const std::function<void (const std::string&)>& f)
190 {
191 remove_hook = f;
192 }
193
194 void read_dir_config (const std::string& dir) const;
195
196 void execute_pkg_add (const std::string& dir);
197 void execute_pkg_del (const std::string& dir);
198
199 void set_command_line_path (const std::string& p)
200 {
201 if (m_command_line_path.empty ())
202 m_command_line_path = p;
203 else
204 m_command_line_path += directory_path::path_sep_str () + p;
205 }
206
207 std::string get_command_line_path (void) const
208 {
209 return m_command_line_path;
210 }
211
212 std::string system_path (void) const { return s_sys_path; }
213
214 static const int M_FILE = 1;
215 static const int OCT_FILE = 2;
216 static const int MEX_FILE = 4;
217
218 private:
219
220 class dir_info
221 { 231 {
222 public: 232 public:
223 233 class_info (void) : method_file_map (), private_file_map () { }
224 // <FCN_NAME, TYPE> 234
225 typedef std::map<std::string, int> fcn_file_map_type; 235 class_info (const class_info& ci)
226 236 : method_file_map (ci.method_file_map),
227 typedef fcn_file_map_type::const_iterator const_fcn_file_map_iterator; 237 private_file_map (ci.private_file_map)
228 typedef fcn_file_map_type::iterator fcn_file_map_iterator; 238 { }
229 239
230 struct class_info 240 class_info& operator = (const class_info& ci)
231 { 241 {
232 public: 242 if (this != &ci)
233 class_info (void) : method_file_map (), private_file_map () { }
234
235 class_info (const class_info& ci)
236 : method_file_map (ci.method_file_map),
237 private_file_map (ci.private_file_map)
238 { }
239
240 class_info& operator = (const class_info& ci)
241 {
242 if (this != &ci)
243 {
244 method_file_map = ci.method_file_map;
245 private_file_map = ci.private_file_map;
246 }
247 return *this;
248 }
249
250 ~class_info (void) = default;
251
252 fcn_file_map_type method_file_map;
253 fcn_file_map_type private_file_map;
254 };
255
256 // <CLASS_NAME, CLASS_INFO>
257 typedef std::map<std::string, class_info> method_file_map_type;
258
259 typedef method_file_map_type::const_iterator const_method_file_map_iterator;
260 typedef method_file_map_type::iterator method_file_map_iterator;
261
262 // <PACKAGE_NAME, DIR_INFO>
263 typedef std::map<std::string, dir_info> package_dir_map_type;
264
265 typedef package_dir_map_type::const_iterator const_package_dir_map_iterator;
266 typedef package_dir_map_type::iterator package_dir_map_iterator;
267
268 // This default constructor is only provided so we can create a
269 // std::map of dir_info objects. You should not use this
270 // constructor for any other purpose.
271 dir_info (void) = default;
272
273 dir_info (const std::string& d)
274 : dir_name (d), abs_dir_name (), is_relative (false),
275 dir_mtime (), dir_time_last_checked (), all_files (), fcn_files (),
276 private_file_map (), method_file_map (), package_dir_map ()
277 {
278 initialize ();
279 }
280
281 dir_info (const dir_info&) = default;
282
283 ~dir_info (void) = default;
284
285 dir_info& operator = (const dir_info&) = default;
286
287 bool update (void);
288
289 std::string dir_name;
290 std::string abs_dir_name;
291 bool is_relative;
292 sys::time dir_mtime;
293 sys::time dir_time_last_checked;
294 string_vector all_files;
295 string_vector fcn_files;
296 fcn_file_map_type private_file_map;
297 method_file_map_type method_file_map;
298 package_dir_map_type package_dir_map;
299
300 bool is_package (const std::string& name) const;
301
302 private:
303
304 void initialize (void);
305
306 void get_file_list (const std::string& d);
307
308 void get_private_file_map (const std::string& d);
309
310 void get_method_file_map (const std::string& d,
311 const std::string& class_name);
312
313 void get_package_dir (const std::string& d,
314 const std::string& package_name);
315
316 friend fcn_file_map_type get_fcn_files (const std::string& d);
317 };
318
319 class file_info
320 {
321 public:
322
323 file_info (const std::string& d, int t) : dir_name (d), types (t) { }
324
325 file_info (const file_info& fi)
326 : dir_name (fi.dir_name), types (fi.types) { }
327
328 ~file_info (void) = default;
329
330 file_info& operator = (const file_info& fi)
331 {
332 if (&fi != this)
333 { 243 {
334 dir_name = fi.dir_name; 244 method_file_map = ci.method_file_map;
335 types = fi.types; 245 private_file_map = ci.private_file_map;
336 } 246 }
337
338 return *this; 247 return *this;
339 } 248 }
340 249
341 std::string dir_name; 250 ~class_info (void) = default;
342 int types; 251
252 fcn_file_map_type method_file_map;
253 fcn_file_map_type private_file_map;
343 }; 254 };
344 255
345 // We maintain two ways of looking at the same information. 256 // <CLASS_NAME, CLASS_INFO>
346 // 257 typedef std::map<std::string, class_info> method_file_map_type;
347 // First, a list of directories and the set of "public" files and 258
348 // private files (those found in the special "private" subdirectory) 259 typedef method_file_map_type::const_iterator const_method_file_map_iterator;
349 // in each directory. 260 typedef method_file_map_type::iterator method_file_map_iterator;
350 // 261
351 // Second, a map from filenames (the union of all "public" files for all 262 // <PACKAGE_NAME, DIR_INFO>
352 // directories, but without filename extensions) to a list of 263 typedef std::map<std::string, dir_info> package_dir_map_type;
353 // corresponding information (directory name and file types). This 264
354 // way, we can quickly find shadowed filenames and look up all 265 typedef package_dir_map_type::const_iterator const_package_dir_map_iterator;
355 // overloaded functions (in the "@" directories used to implement 266 typedef package_dir_map_type::iterator package_dir_map_iterator;
356 // classes). 267
357 268 // This default constructor is only provided so we can create a
358 typedef std::list<dir_info> dir_info_list_type; 269 // std::map of dir_info objects. You should not use this
359 270 // constructor for any other purpose.
360 typedef dir_info_list_type::const_iterator const_dir_info_list_iterator; 271 dir_info (void) = default;
361 typedef dir_info_list_type::iterator dir_info_list_iterator; 272
362 273 dir_info (const std::string& d)
363 typedef std::map<std::string, dir_info> abs_dir_cache_type; 274 : dir_name (d), abs_dir_name (), is_relative (false),
364 275 dir_mtime (), dir_time_last_checked (), all_files (), fcn_files (),
365 typedef abs_dir_cache_type::const_iterator const_abs_dir_cache_iterator; 276 private_file_map (), method_file_map (), package_dir_map ()
366 typedef abs_dir_cache_type::iterator abs_dir_cache_iterator;
367
368 typedef std::list<file_info> file_info_list_type;
369
370 typedef file_info_list_type::const_iterator const_file_info_list_iterator;
371 typedef file_info_list_type::iterator file_info_list_iterator;
372
373 // <FCN_NAME, FILE_INFO_LIST>
374 typedef std::map<std::string, file_info_list_type> fcn_map_type;
375
376 typedef fcn_map_type::const_iterator const_fcn_map_iterator;
377 typedef fcn_map_type::iterator fcn_map_iterator;
378
379 // <DIR_NAME, <FCN_NAME, TYPES>>
380 typedef std::map<std::string, dir_info::fcn_file_map_type>
381 private_fcn_map_type;
382
383 typedef private_fcn_map_type::const_iterator const_private_fcn_map_iterator;
384 typedef private_fcn_map_type::iterator private_fcn_map_iterator;
385
386 // <CLASS_NAME, <FCN_NAME, FILE_INFO_LIST>>
387 typedef std::map<std::string, fcn_map_type> method_map_type;
388
389 typedef method_map_type::const_iterator const_method_map_iterator;
390 typedef method_map_type::iterator method_map_iterator;
391
392 class package_info
393 { 277 {
394 public: 278 initialize ();
395 279 }
396 package_info (const std::string& package_name = "") 280
397 : m_package_name (package_name), m_dir_list (), m_fcn_map (), 281 dir_info (const dir_info&) = default;
398 m_private_fcn_map (), 282
399 m_method_map () 283 ~dir_info (void) = default;
400 { } 284
401 285 dir_info& operator = (const dir_info&) = default;
402 package_info (const package_info& l) 286
403 : m_package_name (l.m_package_name), m_dir_list (l.m_dir_list), 287 bool update (void);
404 m_private_fcn_map (l.m_private_fcn_map), m_method_map (l.m_method_map) 288
405 { } 289 std::string dir_name;
406 290 std::string abs_dir_name;
407 ~package_info (void) = default; 291 bool is_relative;
408 292 sys::time dir_mtime;
409 package_info& operator = (const package_info& l) 293 sys::time dir_time_last_checked;
294 string_vector all_files;
295 string_vector fcn_files;
296 fcn_file_map_type private_file_map;
297 method_file_map_type method_file_map;
298 package_dir_map_type package_dir_map;
299
300 bool is_package (const std::string& name) const;
301
302 private:
303
304 void initialize (void);
305
306 void get_file_list (const std::string& d);
307
308 void get_private_file_map (const std::string& d);
309
310 void get_method_file_map (const std::string& d,
311 const std::string& class_name);
312
313 void get_package_dir (const std::string& d,
314 const std::string& package_name);
315
316 friend fcn_file_map_type get_fcn_files (const std::string& d);
317 };
318
319 class file_info
320 {
321 public:
322
323 file_info (const std::string& d, int t) : dir_name (d), types (t) { }
324
325 file_info (const file_info& fi)
326 : dir_name (fi.dir_name), types (fi.types) { }
327
328 ~file_info (void) = default;
329
330 file_info& operator = (const file_info& fi)
331 {
332 if (&fi != this)
333 {
334 dir_name = fi.dir_name;
335 types = fi.types;
336 }
337
338 return *this;
339 }
340
341 std::string dir_name;
342 int types;
343 };
344
345 // We maintain two ways of looking at the same information.
346 //
347 // First, a list of directories and the set of "public" files and
348 // private files (those found in the special "private" subdirectory)
349 // in each directory.
350 //
351 // Second, a map from filenames (the union of all "public" files for all
352 // directories, but without filename extensions) to a list of
353 // corresponding information (directory name and file types). This
354 // way, we can quickly find shadowed filenames and look up all
355 // overloaded functions (in the "@" directories used to implement
356 // classes).
357
358 typedef std::list<dir_info> dir_info_list_type;
359
360 typedef dir_info_list_type::const_iterator const_dir_info_list_iterator;
361 typedef dir_info_list_type::iterator dir_info_list_iterator;
362
363 typedef std::map<std::string, dir_info> abs_dir_cache_type;
364
365 typedef abs_dir_cache_type::const_iterator const_abs_dir_cache_iterator;
366 typedef abs_dir_cache_type::iterator abs_dir_cache_iterator;
367
368 typedef std::list<file_info> file_info_list_type;
369
370 typedef file_info_list_type::const_iterator const_file_info_list_iterator;
371 typedef file_info_list_type::iterator file_info_list_iterator;
372
373 // <FCN_NAME, FILE_INFO_LIST>
374 typedef std::map<std::string, file_info_list_type> fcn_map_type;
375
376 typedef fcn_map_type::const_iterator const_fcn_map_iterator;
377 typedef fcn_map_type::iterator fcn_map_iterator;
378
379 // <DIR_NAME, <FCN_NAME, TYPES>>
380 typedef std::map<std::string, dir_info::fcn_file_map_type>
381 private_fcn_map_type;
382
383 typedef private_fcn_map_type::const_iterator const_private_fcn_map_iterator;
384 typedef private_fcn_map_type::iterator private_fcn_map_iterator;
385
386 // <CLASS_NAME, <FCN_NAME, FILE_INFO_LIST>>
387 typedef std::map<std::string, fcn_map_type> method_map_type;
388
389 typedef method_map_type::const_iterator const_method_map_iterator;
390 typedef method_map_type::iterator method_map_iterator;
391
392 class package_info
393 {
394 public:
395
396 package_info (const std::string& package_name = "")
397 : m_package_name (package_name), m_dir_list (), m_fcn_map (),
398 m_private_fcn_map (),
399 m_method_map ()
400 { }
401
402 package_info (const package_info& l)
403 : m_package_name (l.m_package_name), m_dir_list (l.m_dir_list),
404 m_private_fcn_map (l.m_private_fcn_map), m_method_map (l.m_method_map)
405 { }
406
407 ~package_info (void) = default;
408
409 package_info& operator = (const package_info& l)
410 {
411 if (&l != this)
412 {
413 m_package_name = l.m_package_name;
414 m_dir_list = l.m_dir_list;
415 m_fcn_map = l.m_fcn_map;
416 m_private_fcn_map = l.m_private_fcn_map;
417 m_method_map = l.m_method_map;
418 }
419
420 return *this;
421 }
422
423 void add (const dir_info& di, bool at_end, bool updating)
424 {
425 if (at_end)
426 m_dir_list.push_back (di.dir_name);
427 else
428 m_dir_list.push_front (di.dir_name);
429
430 add_to_fcn_map (di, at_end, updating);
431
432 add_to_private_fcn_map (di);
433
434 add_to_method_map (di, at_end);
435 }
436
437 void move (const dir_info& di, bool at_end);
438
439 void remove (const dir_info& di);
440
441 void clear (void)
442 {
443 m_dir_list.clear ();
444
445 m_fcn_map.clear ();
446
447 m_private_fcn_map.clear ();
448
449 m_method_map.clear ();
450 }
451
452 void display (std::ostream& out) const;
453
454 std::string
455 find_fcn (const std::string& fcn, std::string& dir_name,
456 int type = M_FILE | OCT_FILE | MEX_FILE) const;
457
458 std::string
459 find_private_fcn (const std::string& dir, const std::string& fcn,
460 int type = M_FILE | OCT_FILE | MEX_FILE) const;
461
462 std::string
463 find_method (const std::string& class_name, const std::string& meth,
464 std::string& dir_name,
465 int type = M_FILE | OCT_FILE | MEX_FILE) const;
466
467 std::list<std::string> methods (const std::string& class_name) const;
468
469 void overloads (const std::string& meth, std::list<std::string>& l) const;
470
471 string_vector fcn_names (void) const;
472
473 private:
474
475 void add_to_fcn_map (const dir_info& di, bool at_end, bool updating);
476
477 void add_to_private_fcn_map (const dir_info& di);
478
479 void add_to_method_map (const dir_info& di, bool at_end);
480
481 void move_fcn_map (const std::string& dir,
482 const string_vector& fcn_files, bool at_end);
483
484 void move_method_map (const std::string& dir, bool at_end);
485
486 void remove_fcn_map (const std::string& dir,
487 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
493 bool check_file_type (std::string& fname, int type, int possible_types,
494 const std::string& fcn, const char *who) const;
495
496 void print_types (std::ostream& os, int types) const;
497
498 void print_fcn_list (std::ostream& os,
499 const dir_info::fcn_file_map_type& lst) const;
500
501 std::string m_package_name;
502
503 std::list<std::string> m_dir_list;
504
505 fcn_map_type m_fcn_map;
506
507 private_fcn_map_type m_private_fcn_map;
508
509 method_map_type m_method_map;
510 };
511
512 // <PACKAGE_NAME, PACKAGE_INFO>
513 typedef std::map<std::string, package_info> package_map_type;
514
515 typedef package_map_type::const_iterator const_package_map_iterator;
516 typedef package_map_type::iterator package_map_iterator;
517
518 std::function<void (const std::string&)> add_hook;
519
520 std::function<void (const std::string&)> remove_hook;
521
522 void execute_pkg_add_or_del (const std::string& dir,
523 const std::string& script_file);
524
525 const_dir_info_list_iterator find_dir_info (const std::string& dir) const;
526 dir_info_list_iterator find_dir_info (const std::string& dir);
527
528 bool contains (const std::string& dir) const;
529
530 void move (dir_info_list_iterator i, bool at_end);
531
532 void move (const dir_info& di, bool at_end, const std::string& pname = "");
533
534 void remove (const dir_info& di, const std::string& pname = "");
535
536 void add (const std::string& dir, bool at_end, bool warn);
537
538 void add (const dir_info& di, bool at_end, const std::string& pname = "",
539 bool updating = false);
540
541 bool is_package (const std::string& name) const;
542
543 package_info& get_package (const std::string& name)
544 {
545 if (! name.empty () && is_package (name))
410 { 546 {
411 if (&l != this) 547 package_map_iterator l = m_package_map.find (name);
412 { 548
413 m_package_name = l.m_package_name; 549 if (l == m_package_map.end ())
414 m_dir_list = l.m_dir_list; 550 l = m_package_map.insert (m_package_map.end (),
415 m_fcn_map = l.m_fcn_map; 551 package_map_type::value_type (name, package_info (name)));
416 m_private_fcn_map = l.m_private_fcn_map; 552
417 m_method_map = l.m_method_map; 553 return l->second;
418 }
419
420 return *this;
421 } 554 }
422 555
423 void add (const dir_info& di, bool at_end, bool updating) 556 return m_top_level_package;
424 { 557 }
425 if (at_end) 558
426 m_dir_list.push_back (di.dir_name); 559 string_vector get_file_list (const dir_info::fcn_file_map_type& lst) const;
427 else 560
428 m_dir_list.push_front (di.dir_name); 561 friend dir_info::fcn_file_map_type get_fcn_files (const std::string& d);
429 562
430 add_to_fcn_map (di, at_end, updating); 563 //--------
431 564
432 add_to_private_fcn_map (di); 565 static std::string s_sys_path;
433 566
434 add_to_method_map (di, at_end); 567 static abs_dir_cache_type s_abs_dir_cache;
435 } 568
436 569 interpreter& m_interpreter;
437 void move (const dir_info& di, bool at_end); 570
438 571 package_map_type m_package_map;
439 void remove (const dir_info& di); 572
440 573 package_info m_top_level_package;
441 void clear (void) 574
442 { 575 dir_info_list_type m_dir_info_list;
443 m_dir_list.clear (); 576
444 577 std::set<std::string> m_init_dirs;
445 m_fcn_map.clear (); 578
446 579 std::string m_command_line_path;
447 m_private_fcn_map.clear (); 580
448 581 };
449 m_method_map.clear (); 582
450 } 583 extern std::string
451 584 genpath (const std::string& dir, const string_vector& skip = "private");
452 void display (std::ostream& out) const;
453
454 std::string
455 find_fcn (const std::string& fcn, std::string& dir_name,
456 int type = M_FILE | OCT_FILE | MEX_FILE) const;
457
458 std::string
459 find_private_fcn (const std::string& dir, const std::string& fcn,
460 int type = M_FILE | OCT_FILE | MEX_FILE) const;
461
462 std::string
463 find_method (const std::string& class_name, const std::string& meth,
464 std::string& dir_name,
465 int type = M_FILE | OCT_FILE | MEX_FILE) const;
466
467 std::list<std::string> methods (const std::string& class_name) const;
468
469 void overloads (const std::string& meth, std::list<std::string>& l) const;
470
471 string_vector fcn_names (void) const;
472
473 private:
474
475 void add_to_fcn_map (const dir_info& di, bool at_end, bool updating);
476
477 void add_to_private_fcn_map (const dir_info& di);
478
479 void add_to_method_map (const dir_info& di, bool at_end);
480
481 void move_fcn_map (const std::string& dir,
482 const string_vector& fcn_files, bool at_end);
483
484 void move_method_map (const std::string& dir, bool at_end);
485
486 void remove_fcn_map (const std::string& dir,
487 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
493 bool check_file_type (std::string& fname, int type, int possible_types,
494 const std::string& fcn, const char *who) const;
495
496 void print_types (std::ostream& os, int types) const;
497
498 void print_fcn_list (std::ostream& os,
499 const dir_info::fcn_file_map_type& lst) const;
500
501 std::string m_package_name;
502
503 std::list<std::string> m_dir_list;
504
505 fcn_map_type m_fcn_map;
506
507 private_fcn_map_type m_private_fcn_map;
508
509 method_map_type m_method_map;
510 };
511
512 // <PACKAGE_NAME, PACKAGE_INFO>
513 typedef std::map<std::string, package_info> package_map_type;
514
515 typedef package_map_type::const_iterator const_package_map_iterator;
516 typedef package_map_type::iterator package_map_iterator;
517
518 std::function<void (const std::string&)> add_hook;
519
520 std::function<void (const std::string&)> remove_hook;
521
522 void execute_pkg_add_or_del (const std::string& dir,
523 const std::string& script_file);
524
525 const_dir_info_list_iterator find_dir_info (const std::string& dir) const;
526 dir_info_list_iterator find_dir_info (const std::string& dir);
527
528 bool contains (const std::string& dir) const;
529
530 void move (dir_info_list_iterator i, bool at_end);
531
532 void move (const dir_info& di, bool at_end, const std::string& pname = "");
533
534 void remove (const dir_info& di, const std::string& pname = "");
535
536 void add (const std::string& dir, bool at_end, bool warn);
537
538 void add (const dir_info& di, bool at_end, const std::string& pname = "",
539 bool updating = false);
540
541 bool is_package (const std::string& name) const;
542
543 package_info& get_package (const std::string& name)
544 {
545 if (! name.empty () && is_package (name))
546 {
547 package_map_iterator l = m_package_map.find (name);
548
549 if (l == m_package_map.end ())
550 l = m_package_map.insert (m_package_map.end (),
551 package_map_type::value_type (name, package_info (name)));
552
553 return l->second;
554 }
555
556 return m_top_level_package;
557 }
558
559 string_vector get_file_list (const dir_info::fcn_file_map_type& lst) const;
560
561 friend dir_info::fcn_file_map_type get_fcn_files (const std::string& d);
562
563 //--------
564
565 static std::string s_sys_path;
566
567 static abs_dir_cache_type s_abs_dir_cache;
568
569 interpreter& m_interpreter;
570
571 package_map_type m_package_map;
572
573 package_info m_top_level_package;
574
575 dir_info_list_type m_dir_info_list;
576
577 std::set<std::string> m_init_dirs;
578
579 std::string m_command_line_path;
580
581 };
582
583 extern std::string
584 genpath (const std::string& dir, const string_vector& skip = "private");
585 585
586 OCTAVE_END_NAMESPACE(octave) 586 OCTAVE_END_NAMESPACE(octave)
587 587
588 #endif 588 #endif