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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_dir_ops_h) |
|
24 #define octave_dir_ops_h 1 |
|
25 |
|
26 #include <string> |
|
27 |
|
28 #include "str-vec.h" |
|
29 |
|
30 class |
|
31 dir_entry |
|
32 { |
|
33 public: |
|
34 |
3504
|
35 dir_entry (const std::string& n = std::string ()) : name (n), dir (0) |
1879
|
36 { |
|
37 if (! name.empty ()) |
|
38 open (); |
|
39 } |
1782
|
40 |
|
41 dir_entry (const dir_entry& d) { copy (d); } |
|
42 |
|
43 dir_entry& operator = (const dir_entry& d) |
|
44 { |
1929
|
45 if (this != &d) |
|
46 copy (d); |
|
47 |
1782
|
48 return *this; |
|
49 } |
|
50 |
|
51 ~dir_entry (void) { close (); } |
|
52 |
3504
|
53 bool open (const std::string& = std::string ()); |
1782
|
54 |
|
55 string_vector read (void); |
|
56 |
|
57 void close (void); |
|
58 |
|
59 bool ok (void) const { return dir && ! fail; } |
|
60 |
3145
|
61 operator bool () const { return ok (); } |
1782
|
62 |
3504
|
63 std::string error (void) const { return ok () ? std::string () : errmsg; } |
1782
|
64 |
|
65 private: |
|
66 |
|
67 // Name of the directory. |
3504
|
68 std::string name; |
1782
|
69 |
1929
|
70 // A pointer to the contents of the directory. We use void here to |
|
71 // avoid possible conflicts with the way some systems declare the |
|
72 // type DIR. |
|
73 void *dir; |
1782
|
74 |
|
75 // TRUE means the open for this directory failed. |
|
76 bool fail; |
|
77 |
|
78 // If a failure occurs, this contains the system error text. |
3504
|
79 std::string errmsg; |
1782
|
80 |
|
81 void copy (const dir_entry&); |
|
82 }; |
|
83 |
|
84 #endif |
|
85 |
|
86 /* |
|
87 ;;; Local Variables: *** |
|
88 ;;; mode: C++ *** |
|
89 ;;; End: *** |
|
90 */ |