2232
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2232
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_fn_cache_h) |
|
24 #define octave_fn_cache_h 1 |
|
25 |
2284
|
26 #include <ctime> |
|
27 |
2232
|
28 #include <string> |
|
29 |
|
30 #include "Map.h" |
|
31 |
|
32 class string_vector; |
|
33 |
|
34 // XXX FIXME XXX -- this should maybe be nested in the |
|
35 // octave_fcn_file_name_cache class... |
|
36 |
|
37 class |
|
38 file_name_cache_elt |
|
39 { |
|
40 public: |
|
41 |
2432
|
42 file_name_cache_elt (void) |
|
43 : timestamp (0), fcn_file_names (), fcn_file_names_no_suffix () |
|
44 { update (string ()); } |
|
45 |
|
46 file_name_cache_elt (const string& dir_name) |
2232
|
47 : timestamp (0), fcn_file_names (), fcn_file_names_no_suffix () |
|
48 { update (dir_name); } |
|
49 |
|
50 file_name_cache_elt (const file_name_cache_elt& elt) |
|
51 { |
|
52 timestamp = elt.timestamp; |
|
53 fcn_file_names = elt.fcn_file_names; |
|
54 fcn_file_names_no_suffix = elt.fcn_file_names_no_suffix; |
|
55 } |
|
56 |
|
57 file_name_cache_elt& operator = (const file_name_cache_elt& elt) |
|
58 { |
|
59 if (&elt != this) |
|
60 { |
|
61 timestamp = elt.timestamp; |
|
62 fcn_file_names = elt.fcn_file_names; |
|
63 fcn_file_names_no_suffix = elt.fcn_file_names_no_suffix; |
|
64 } |
|
65 return *this; |
|
66 } |
|
67 |
|
68 ~file_name_cache_elt (void) { } |
|
69 |
|
70 int length (void) { return fcn_file_names.length (); } |
|
71 |
|
72 bool update (const string& dir_name); |
|
73 |
|
74 // The time we last read this directory. |
|
75 time_t timestamp; |
|
76 |
|
77 // The list of file names in this directory. |
|
78 string_vector fcn_file_names; |
|
79 |
|
80 // The list of file names in this directory without the .m or .oct |
|
81 // suffixes. |
|
82 string_vector fcn_file_names_no_suffix; |
|
83 }; |
|
84 |
|
85 class |
|
86 octave_fcn_file_name_cache |
|
87 { |
|
88 protected: |
|
89 |
|
90 octave_fcn_file_name_cache (void) |
|
91 : cache (file_name_cache_elt ()) |
2432
|
92 { update (string ()); } |
2232
|
93 |
|
94 public: |
|
95 |
|
96 ~octave_fcn_file_name_cache (void) { } |
|
97 |
2432
|
98 bool update (const string& path); |
2233
|
99 |
|
100 static string_vector list (bool no_suffix = false) |
|
101 { return list (string (), no_suffix); } |
2232
|
102 |
2233
|
103 static string_vector list (const string& path, bool no_suffix = false); |
2232
|
104 |
2233
|
105 static string_vector list_no_suffix (void) |
|
106 { return list (true); } |
|
107 |
|
108 static string_vector list_no_suffix (const string& path) |
|
109 { return list (path, true); } |
2232
|
110 |
|
111 private: |
|
112 |
2370
|
113 static octave_fcn_file_name_cache* instance; |
2232
|
114 |
|
115 // An associative array of all the directory names in the load path |
|
116 // and the corresponding cache elements. |
|
117 CHMap<file_name_cache_elt> cache; |
|
118 |
2233
|
119 string_vector do_list (const string& path, bool no_suffix); |
2232
|
120 }; |
|
121 |
|
122 #endif |
|
123 |
|
124 /* |
|
125 ;;; Local Variables: *** |
|
126 ;;; mode: C++ *** |
|
127 ;;; End: *** |
|
128 */ |