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 |
|
26 #include <string> |
|
27 |
|
28 #include "Map.h" |
|
29 |
3255
|
30 #include "oct-time.h" |
|
31 |
2232
|
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) |
3255
|
43 : timestamp (static_cast<time_t> (0)), fcn_file_names (), |
|
44 fcn_file_names_no_suffix () |
3523
|
45 { update (std::string ()); } |
2432
|
46 |
3523
|
47 file_name_cache_elt (const std::string& dir_name) |
3255
|
48 : timestamp (static_cast<time_t> (0)), fcn_file_names (), |
|
49 fcn_file_names_no_suffix () |
|
50 { update (dir_name); } |
2232
|
51 |
|
52 file_name_cache_elt (const file_name_cache_elt& elt) |
3255
|
53 { |
|
54 timestamp = elt.timestamp; |
|
55 fcn_file_names = elt.fcn_file_names; |
|
56 fcn_file_names_no_suffix = elt.fcn_file_names_no_suffix; |
|
57 } |
2232
|
58 |
|
59 file_name_cache_elt& operator = (const file_name_cache_elt& elt) |
3255
|
60 { |
|
61 if (&elt != this) |
|
62 { |
|
63 timestamp = elt.timestamp; |
|
64 fcn_file_names = elt.fcn_file_names; |
|
65 fcn_file_names_no_suffix = elt.fcn_file_names_no_suffix; |
|
66 } |
|
67 return *this; |
|
68 } |
2232
|
69 |
|
70 ~file_name_cache_elt (void) { } |
|
71 |
|
72 int length (void) { return fcn_file_names.length (); } |
|
73 |
3523
|
74 bool update (const std::string& dir_name); |
2232
|
75 |
|
76 // The time we last read this directory. |
3255
|
77 octave_time timestamp; |
2232
|
78 |
|
79 // The list of file names in this directory. |
|
80 string_vector fcn_file_names; |
|
81 |
|
82 // The list of file names in this directory without the .m or .oct |
|
83 // suffixes. |
|
84 string_vector fcn_file_names_no_suffix; |
|
85 }; |
|
86 |
|
87 class |
|
88 octave_fcn_file_name_cache |
|
89 { |
|
90 protected: |
|
91 |
|
92 octave_fcn_file_name_cache (void) |
|
93 : cache (file_name_cache_elt ()) |
3523
|
94 { update (std::string ()); } |
2232
|
95 |
|
96 public: |
|
97 |
|
98 ~octave_fcn_file_name_cache (void) { } |
|
99 |
3523
|
100 bool update (const std::string& path); |
2233
|
101 |
|
102 static string_vector list (bool no_suffix = false) |
3523
|
103 { return list (std::string (), no_suffix); } |
2232
|
104 |
3523
|
105 static string_vector list (const std::string& path, bool no_suffix = false); |
2232
|
106 |
2233
|
107 static string_vector list_no_suffix (void) |
|
108 { return list (true); } |
|
109 |
3523
|
110 static string_vector list_no_suffix (const std::string& path) |
2233
|
111 { return list (path, true); } |
2232
|
112 |
|
113 private: |
|
114 |
2370
|
115 static octave_fcn_file_name_cache* instance; |
2232
|
116 |
|
117 // An associative array of all the directory names in the load path |
|
118 // and the corresponding cache elements. |
|
119 CHMap<file_name_cache_elt> cache; |
|
120 |
3523
|
121 string_vector do_list (const std::string& path, bool no_suffix); |
2232
|
122 }; |
|
123 |
|
124 #endif |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; End: *** |
|
130 */ |