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