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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2232
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_fn_cache_h) |
|
25 #define octave_fn_cache_h 1 |
|
26 |
|
27 #include <string> |
4215
|
28 #include <map> |
2232
|
29 |
3255
|
30 #include "oct-time.h" |
|
31 |
2232
|
32 class string_vector; |
|
33 |
5775
|
34 // FIXME -- this should maybe be nested in the |
2232
|
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 |
4215
|
92 octave_fcn_file_name_cache (void) : cache () { update (std::string ()); } |
2232
|
93 |
|
94 public: |
|
95 |
|
96 ~octave_fcn_file_name_cache (void) { } |
|
97 |
3523
|
98 bool update (const std::string& path); |
2233
|
99 |
|
100 static string_vector list (bool no_suffix = false) |
3523
|
101 { return list (std::string (), no_suffix); } |
2232
|
102 |
3523
|
103 static string_vector list (const std::string& path, bool no_suffix = false); |
2232
|
104 |
2233
|
105 static string_vector list_no_suffix (void) |
|
106 { return list (true); } |
|
107 |
3523
|
108 static string_vector list_no_suffix (const std::string& path) |
2233
|
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. |
4215
|
117 std::map<std::string, file_name_cache_elt> cache; |
2232
|
118 |
3523
|
119 string_vector do_list (const std::string& path, bool no_suffix); |
2232
|
120 }; |
|
121 |
|
122 #endif |
|
123 |
|
124 /* |
|
125 ;;; Local Variables: *** |
|
126 ;;; mode: C++ *** |
|
127 ;;; End: *** |
|
128 */ |