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