Mercurial > hg > octave-lyh
annotate liboctave/file-ops.h @ 8009:d936b21b3a6b
file_ops: use singleton class for static data members
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 05 Aug 2008 12:14:16 -0400 |
parents | a2ab20ba78f7 |
children | 0ef13e15319b |
rev | line source |
---|---|
1765 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2005, 2006, 2007 John W. Eaton |
1765 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1765 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1765 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_file_ops_h) | |
24 #define octave_file_ops_h 1 | |
25 | |
26 #include <string> | |
27 | |
2283 | 28 #ifdef HAVE_SYS_TYPES_H |
29 #include <sys/types.h> | |
30 #endif | |
31 | |
3040 | 32 #include "str-vec.h" |
33 | |
2926 | 34 struct |
6108 | 35 OCTAVE_API |
2926 | 36 file_ops |
1765 | 37 { |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
38 public: |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
39 |
3504 | 40 static int mkdir (const std::string&, mode_t); |
41 static int mkdir (const std::string&, mode_t, std::string&); | |
1765 | 42 |
3504 | 43 static int mkfifo (const std::string&, mode_t); |
44 static int mkfifo (const std::string&, mode_t, std::string&); | |
1765 | 45 |
3710 | 46 static int link (const std::string&, const std::string&); |
47 static int link (const std::string&, const std::string&, std::string&); | |
48 | |
49 static int symlink (const std::string&, const std::string&); | |
50 static int symlink (const std::string&, const std::string&, std::string&); | |
51 | |
52 static int readlink (const std::string&, std::string&); | |
53 static int readlink (const std::string&, std::string&, std::string&); | |
54 | |
3504 | 55 static int rename (const std::string&, const std::string&); |
56 static int rename (const std::string&, const std::string&, std::string&); | |
1765 | 57 |
3504 | 58 static int rmdir (const std::string&); |
59 static int rmdir (const std::string&, std::string&); | |
1765 | 60 |
5476 | 61 static int recursive_rmdir (const std::string&); |
62 static int recursive_rmdir (const std::string&, std::string&); | |
63 | |
5138 | 64 static std::string canonicalize_file_name (const std::string&); |
65 static std::string canonicalize_file_name (const std::string&, std::string&); | |
66 | |
3504 | 67 static std::string tempnam (const std::string&, const std::string&); |
3710 | 68 static std::string tempnam (const std::string&, const std::string&, |
69 std::string&); | |
1765 | 70 |
3504 | 71 typedef std::string (*tilde_expansion_hook) (const std::string&); |
3040 | 72 |
73 static tilde_expansion_hook tilde_expansion_preexpansion_hook; | |
74 | |
75 static tilde_expansion_hook tilde_expansion_failure_hook; | |
76 | |
77 static string_vector tilde_additional_prefixes; | |
78 | |
79 static string_vector tilde_additional_suffixes; | |
80 | |
3504 | 81 static std::string tilde_expand (const std::string&); |
2926 | 82 static string_vector tilde_expand (const string_vector&); |
1778 | 83 |
2926 | 84 static int umask (mode_t); |
2668 | 85 |
3504 | 86 static int unlink (const std::string&); |
87 static int unlink (const std::string&, std::string&); | |
4097 | 88 |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
89 static bool is_dir_sep (char c) |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
90 { |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
91 std::string tmp = dir_sep_chars (); |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
92 return tmp.find (c) != NPOS; |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
93 } |
4101 | 94 |
7272 | 95 static std::string concat (const std::string&, const std::string&); |
96 | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
97 static char dir_sep_char (void) |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
98 { |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
99 return static_members::dir_sep_char (); |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
100 } |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
101 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
102 static std::string dir_sep_str (void) |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
103 { |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
104 return static_members::dir_sep_str (); |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
105 } |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
106 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
107 static std::string dir_sep_chars (void) |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
108 { |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
109 return static_members::dir_sep_chars (); |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
110 } |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
111 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
112 private: |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
113 |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
114 // Use a singleton class for these data members instead of just |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
115 // making them static members of the dir_path class so that we can |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
116 // ensure proper initialization. |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
117 |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
118 class static_members |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
119 { |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
120 public: |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
121 |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
122 static_members (void); |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
123 |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
124 static char dir_sep_char (void) |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
125 { |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
126 return instance_ok () ? instance->xdir_sep_char : 0; |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
127 } |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
128 |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
129 static std::string dir_sep_str (void) |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
130 { |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
131 return instance_ok () ? instance->xdir_sep_str : std::string (); |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
132 } |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
133 |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
134 static std::string dir_sep_chars (void) |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
135 { |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
136 return instance_ok () ? instance->xdir_sep_chars : std::string (); |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
137 } |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
138 |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
139 private: |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
140 |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
141 // The real thing. |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
142 static static_members *instance; |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
143 |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
144 // No copying! |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
145 |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
146 static_members (const static_members&); |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
147 |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
148 static_members& operator = (const static_members&); |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
149 |
8009
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
150 static bool instance_ok (void); |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
151 |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
152 char xdir_sep_char; |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
153 std::string xdir_sep_str; |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
154 std::string xdir_sep_chars; |
d936b21b3a6b
file_ops: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
155 }; |
2926 | 156 }; |
1765 | 157 |
158 #endif | |
159 | |
160 /* | |
161 ;;; Local Variables: *** | |
162 ;;; mode: C++ *** | |
163 ;;; End: *** | |
164 */ |