annotate src/fn-cache.h @ 5307:4c8a2e4e0717

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