1782
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1782
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1782
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_dir_ops_h) |
|
25 #define octave_dir_ops_h 1 |
|
26 |
|
27 #include <string> |
|
28 |
|
29 #include "str-vec.h" |
|
30 |
|
31 class |
6108
|
32 OCTAVE_API |
1782
|
33 dir_entry |
|
34 { |
|
35 public: |
|
36 |
3504
|
37 dir_entry (const std::string& n = std::string ()) : name (n), dir (0) |
1879
|
38 { |
|
39 if (! name.empty ()) |
|
40 open (); |
|
41 } |
1782
|
42 |
|
43 dir_entry (const dir_entry& d) { copy (d); } |
|
44 |
|
45 dir_entry& operator = (const dir_entry& d) |
|
46 { |
1929
|
47 if (this != &d) |
|
48 copy (d); |
|
49 |
1782
|
50 return *this; |
|
51 } |
|
52 |
|
53 ~dir_entry (void) { close (); } |
|
54 |
3504
|
55 bool open (const std::string& = std::string ()); |
1782
|
56 |
|
57 string_vector read (void); |
|
58 |
|
59 void close (void); |
|
60 |
|
61 bool ok (void) const { return dir && ! fail; } |
|
62 |
3145
|
63 operator bool () const { return ok (); } |
1782
|
64 |
3504
|
65 std::string error (void) const { return ok () ? std::string () : errmsg; } |
1782
|
66 |
|
67 private: |
|
68 |
|
69 // Name of the directory. |
3504
|
70 std::string name; |
1782
|
71 |
1929
|
72 // A pointer to the contents of the directory. We use void here to |
|
73 // avoid possible conflicts with the way some systems declare the |
|
74 // type DIR. |
|
75 void *dir; |
1782
|
76 |
|
77 // TRUE means the open for this directory failed. |
|
78 bool fail; |
|
79 |
|
80 // If a failure occurs, this contains the system error text. |
3504
|
81 std::string errmsg; |
1782
|
82 |
|
83 void copy (const dir_entry&); |
|
84 }; |
|
85 |
|
86 #endif |
|
87 |
|
88 /* |
|
89 ;;; Local Variables: *** |
|
90 ;;; mode: C++ *** |
|
91 ;;; End: *** |
|
92 */ |