Mercurial > hg > octave-lyh
annotate liboctave/pathsearch.h @ 10396:a0b51ac0f88a
optimize accumdim with summation
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 05 Mar 2010 12:31:30 +0100 |
parents | cbc402e64d83 |
children | 331fcc41ca23 |
rev | line source |
---|---|
1786 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2005, 2006, 2007, 2008 |
7017 | 4 John W. Eaton |
1786 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1786 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1786 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_pathsearch_h) | |
25 #define octave_pathsearch_h 1 | |
26 | |
27 #include <string> | |
28 | |
29 #include "str-vec.h" | |
30 | |
31 class | |
6108 | 32 OCTAVE_API |
1786 | 33 dir_path |
34 { | |
35 public: | |
36 | |
3504 | 37 dir_path (const std::string& s = std::string (), |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
38 const std::string& d = std::string ()) |
3196 | 39 : p_orig (s), p_default (d), initialized (false) |
1786 | 40 { |
3174 | 41 if (! p_orig.empty ()) |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
42 init (); |
1786 | 43 } |
44 | |
45 dir_path (const dir_path& dp) | |
3196 | 46 : p_orig (dp.p_orig), p_default (dp.p_default), |
47 initialized (dp.initialized), p (dp.p), pv (dp.pv) | |
3174 | 48 { } |
1786 | 49 |
50 dir_path& operator = (const dir_path& dp) | |
51 { | |
3174 | 52 p_orig = dp.p_orig; |
3196 | 53 p_default = dp.p_default; |
3174 | 54 initialized = dp.initialized; |
1786 | 55 p = dp.p; |
56 pv = dp.pv; | |
57 return *this; | |
58 } | |
59 | |
60 ~dir_path (void) { } | |
61 | |
3504 | 62 void set (const std::string& s) |
1786 | 63 { |
64 initialized = false; | |
3174 | 65 p_orig = s; |
1786 | 66 init (); |
67 } | |
68 | |
69 string_vector elements (void); | |
70 string_vector all_directories (void); | |
71 | |
3504 | 72 std::string find_first (const std::string&); |
73 std::string find (const std::string& nm) { return find_first (nm); } | |
1786 | 74 |
3504 | 75 string_vector find_all (const std::string&); |
1786 | 76 |
4242 | 77 std::string find_first_of (const string_vector& names); |
78 string_vector find_all_first_of (const string_vector& names); | |
79 | |
3185 | 80 void rehash (void) |
81 { | |
82 initialized = false; | |
83 init (); | |
84 } | |
85 | |
8010 | 86 static char path_sep_char (void) |
87 { | |
88 return static_members::path_sep_char (); | |
89 } | |
90 | |
9266 | 91 static void path_sep_char (char c) |
92 { | |
93 static_members::path_sep_char (c); | |
94 } | |
95 | |
8010 | 96 static std::string path_sep_str (void) |
97 { | |
98 return static_members::path_sep_str (); | |
99 } | |
100 | |
101 static bool is_path_sep (char c) { return c == path_sep_char (); } | |
102 | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
103 private: |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
104 |
8010 | 105 // The colon separated list that we were given. |
106 std::string p_orig; | |
107 | |
108 // The default path. If specified, replaces leading, trailing, or | |
109 // doubled colons in p_orig. | |
110 std::string p_default; | |
111 | |
112 // TRUE means we've unpacked p. | |
113 bool initialized; | |
114 | |
115 // A version of the colon separate list on which we have performed | |
116 // tilde, variable, and possibly default path expansion. | |
117 std::string p; | |
118 | |
119 // The elements of the list. | |
120 string_vector pv; | |
121 | |
122 void init (void); | |
123 | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
124 // Use a singleton class for these data members instead of just |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
125 // making them static members of the dir_path class so that we can |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
126 // ensure proper initialization. |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
127 |
9402
cdfb9ad48080
Add exported symbols
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9266
diff
changeset
|
128 class OCTAVE_API static_members |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
129 { |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
130 public: |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
131 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
132 static_members (void); |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
133 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
134 static char path_sep_char (void) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
135 { |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
136 return instance_ok () ? instance->xpath_sep_char : 0; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
137 } |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
138 |
9266 | 139 static void path_sep_char (char c) |
140 { | |
141 if (instance_ok ()) | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
142 { |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
143 instance->xpath_sep_char = c; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
144 instance->xpath_sep_str = std::string (1, c); |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
145 } |
9266 | 146 } |
147 | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
148 static std::string path_sep_str (void) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
149 { |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
150 return instance_ok () ? instance->xpath_sep_str : std::string (); |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
151 } |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
152 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
153 private: |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
154 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
155 static static_members *instance; |
5777 | 156 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
157 static bool instance_ok (void); |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
158 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
159 // No copying! |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
160 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
161 static_members (const static_members&); |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
162 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
163 static_members& operator = (const static_members&); |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
164 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
165 char xpath_sep_char; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
166 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
167 std::string xpath_sep_str; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
168 }; |
1786 | 169 }; |
170 | |
171 #endif |