1782
|
1 // dir-ops.h -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1996 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
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 struct DIR; |
|
32 |
|
33 class |
|
34 dir_entry |
|
35 { |
|
36 public: |
|
37 |
|
38 dir_entry (const string& n = string ()) : name (n), dir (0) |
1879
|
39 { |
|
40 if (! name.empty ()) |
|
41 open (); |
|
42 } |
1782
|
43 |
|
44 dir_entry (const dir_entry& d) { copy (d); } |
|
45 |
|
46 dir_entry& operator = (const dir_entry& d) |
|
47 { |
|
48 copy (d); |
|
49 return *this; |
|
50 } |
|
51 |
|
52 ~dir_entry (void) { close (); } |
|
53 |
|
54 bool open (const string& = string ()); |
|
55 |
|
56 string_vector read (void); |
|
57 |
|
58 void close (void); |
|
59 |
|
60 bool ok (void) const { return dir && ! fail; } |
|
61 |
|
62 operator void* () const { return ok () ? (void *) -1 : (void *) 0; } |
|
63 |
|
64 string error (void) const { return ok () ? string () : errmsg; } |
|
65 |
|
66 private: |
|
67 |
|
68 // Name of the directory. |
|
69 string name; |
|
70 |
|
71 // A pointer to the contents of the directory. |
|
72 DIR *dir; |
|
73 |
|
74 // TRUE means the open for this directory failed. |
|
75 bool fail; |
|
76 |
|
77 // If a failure occurs, this contains the system error text. |
|
78 string errmsg; |
|
79 |
|
80 void copy (const dir_entry&); |
|
81 }; |
|
82 |
|
83 #endif |
|
84 |
|
85 /* |
|
86 ;;; Local Variables: *** |
|
87 ;;; mode: C++ *** |
|
88 ;;; page-delimiter: "^/\\*" *** |
|
89 ;;; End: *** |
|
90 */ |