Mercurial > octave
annotate liboctave/util/pathsearch.h @ 23743:e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
* dirfns.cc (Fpathsep): Don't allow pathsep to be changed.
* pathsearch.h, pathsearch.cc (directory_path::static_members):
Eliminate singleton class.
(directory_path::path_sep_char (char)): Delete. Don't allow path
separator character to be changed.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 07 Jul 2017 07:21:20 -0400 |
parents | be7b884ac589 |
children | 194eb4bd202b |
rev | line source |
---|---|
1786 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 John W. Eaton |
1786 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 (at your option) any later version. |
1786 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 GNU General Public License for more details. |
1786 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1786 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_pathsearch_h) |
1786 | 24 #define octave_pathsearch_h 1 |
25 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
27 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
28 #include <list> |
1786 | 29 #include <string> |
30 | |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
31 namespace octave |
1786 | 32 { |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
33 class |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
34 OCTAVE_API |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
35 directory_path |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
36 { |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
37 public: |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
38 |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
39 directory_path (const std::string& s = "", const std::string& d = ""); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
40 |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
41 directory_path (const directory_path& dp) = default; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
42 |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
43 directory_path& operator = (const directory_path& dp) = default; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
44 |
22868
87e3163f6c87
use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
45 ~directory_path (void) = default; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
46 |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
47 void set (const std::string& s) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
48 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
49 m_initialized = false; |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
50 m_orig_path = s; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
51 init (); |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
52 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
53 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
54 std::list<std::string> elements (void); |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
55 |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
56 std::list<std::string> all_directories (void); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
57 |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
58 std::string find_first (const std::string&); |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
59 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
60 std::string find (const std::string& nm) { return find_first (nm); } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
61 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
62 std::list<std::string> find_all (const std::string&); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
63 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
64 std::string find_first_of (const std::list<std::string>& names); |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
65 |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
66 std::list<std::string> |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
67 find_all_first_of (const std::list<std::string>& names); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
68 |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
69 void rehash (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
70 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
71 m_initialized = false; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
72 init (); |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
73 } |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
74 |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
75 static char path_sep_char (void); |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
76 |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
77 // static void path_sep_char (char c); |
9266 | 78 |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
79 static std::string path_sep_str (void); |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
80 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
81 static bool is_path_sep (char c) { return c == path_sep_char (); } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
82 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
83 private: |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
84 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
85 // The colon separated list that we were given. |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
86 std::string m_orig_path; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
87 |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
88 // The default path. If specified, replaces leading, trailing, or |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
89 // doubled colons in p_orig. |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
90 std::string m_default_path; |
5777 | 91 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
92 // TRUE means we've unpacked the path p. |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
93 bool m_initialized; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
94 |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
95 // A version of the colon separate list on which we have performed |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
96 // tilde, variable, and possibly default path expansion. |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
97 std::string m_expanded_path; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
98 |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
99 // The elements of the list. |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21752
diff
changeset
|
100 std::list<std::string> m_path_elements; |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
101 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
102 void init (void); |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
103 }; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
104 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
105 |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
106 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
107 |
23615
be7b884ac589
use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
108 OCTAVE_DEPRECATED (4.2, "use 'octave::directory_path' instead") |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
109 typedef octave::directory_path dir_path; |
1786 | 110 |
111 #endif | |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
112 |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
113 #endif |