Mercurial > octave
annotate liboctave/file-ops.h @ 8007:a2ab20ba78f7
make file_ops a proper singleton class
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 04 Aug 2008 23:44:50 -0400 |
parents | 05ee52d7fad6 |
children | d936b21b3a6b |
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 protected: |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
39 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
40 file_ops (void); |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
41 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
42 public: |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
43 |
3504 | 44 static int mkdir (const std::string&, mode_t); |
45 static int mkdir (const std::string&, mode_t, std::string&); | |
1765 | 46 |
3504 | 47 static int mkfifo (const std::string&, mode_t); |
48 static int mkfifo (const std::string&, mode_t, std::string&); | |
1765 | 49 |
3710 | 50 static int link (const std::string&, const std::string&); |
51 static int link (const std::string&, const std::string&, std::string&); | |
52 | |
53 static int symlink (const std::string&, const std::string&); | |
54 static int symlink (const std::string&, const std::string&, std::string&); | |
55 | |
56 static int readlink (const std::string&, std::string&); | |
57 static int readlink (const std::string&, std::string&, std::string&); | |
58 | |
3504 | 59 static int rename (const std::string&, const std::string&); |
60 static int rename (const std::string&, const std::string&, std::string&); | |
1765 | 61 |
3504 | 62 static int rmdir (const std::string&); |
63 static int rmdir (const std::string&, std::string&); | |
1765 | 64 |
5476 | 65 static int recursive_rmdir (const std::string&); |
66 static int recursive_rmdir (const std::string&, std::string&); | |
67 | |
5138 | 68 static std::string canonicalize_file_name (const std::string&); |
69 static std::string canonicalize_file_name (const std::string&, std::string&); | |
70 | |
3504 | 71 static std::string tempnam (const std::string&, const std::string&); |
3710 | 72 static std::string tempnam (const std::string&, const std::string&, |
73 std::string&); | |
1765 | 74 |
3504 | 75 typedef std::string (*tilde_expansion_hook) (const std::string&); |
3040 | 76 |
77 static tilde_expansion_hook tilde_expansion_preexpansion_hook; | |
78 | |
79 static tilde_expansion_hook tilde_expansion_failure_hook; | |
80 | |
81 static string_vector tilde_additional_prefixes; | |
82 | |
83 static string_vector tilde_additional_suffixes; | |
84 | |
3504 | 85 static std::string tilde_expand (const std::string&); |
2926 | 86 static string_vector tilde_expand (const string_vector&); |
1778 | 87 |
2926 | 88 static int umask (mode_t); |
2668 | 89 |
3504 | 90 static int unlink (const std::string&); |
91 static int unlink (const std::string&, std::string&); | |
4097 | 92 |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
93 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
|
94 { |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
95 return instance_ok () ? instance->do_is_dir_sep (c) : false; |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
96 } |
4101 | 97 |
7272 | 98 static std::string concat (const std::string&, const std::string&); |
99 | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
100 static char dir_sep_char (void) |
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 return instance_ok () ? instance->xdir_sep_char : 0; |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
103 } |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
104 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
105 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
|
106 { |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
107 return instance_ok () ? instance->xdir_sep_str : std::string (); |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
108 } |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
109 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
110 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
|
111 { |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
112 return instance_ok () ? instance->xdir_sep_chars : std::string (); |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
113 } |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
114 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
115 private: |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
116 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
117 // No copying! |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
118 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
119 file_ops (const file_ops&); |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
120 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
121 file_ops& operator = (const file_ops&); |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
122 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
123 // The real thing. |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
124 static file_ops *instance; |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
125 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
126 static bool instance_ok (void); |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
127 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
128 char xdir_sep_char; |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
129 std::string xdir_sep_str; |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
130 std::string xdir_sep_chars; |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
131 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
132 bool do_is_dir_sep (char c) { return xdir_sep_chars.find (c) != NPOS; } |
2926 | 133 }; |
1765 | 134 |
135 #endif | |
136 | |
137 /* | |
138 ;;; Local Variables: *** | |
139 ;;; mode: C++ *** | |
140 ;;; End: *** | |
141 */ |