Octave-Forge - Extra packages for GNU Octave | |
Home · Packages · Developers · Documentation · FAQ · Bugs · Mailing Lists · Links · Code |
00001 /* 00002 00003 Copyright (C) 1996, 1997, 1998, 2000, 2005, 2006, 2007 John W. Eaton 00004 00005 This file is part of Octave. 00006 00007 Octave is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 3 of the License, or (at your 00010 option) any later version. 00011 00012 Octave is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Octave; see the file COPYING. If not, see 00019 <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #if !defined (octave_dir_ops_h) 00024 #define octave_dir_ops_h 1 00025 00026 #include <string> 00027 00028 #include "str-vec.h" 00029 00030 class 00031 OCTAVE_API 00032 dir_entry 00033 { 00034 public: 00035 00036 dir_entry (const std::string& n = std::string ()) : name (n), dir (0) 00037 { 00038 if (! name.empty ()) 00039 open (); 00040 } 00041 00042 dir_entry (const dir_entry& d) { copy (d); } 00043 00044 dir_entry& operator = (const dir_entry& d) 00045 { 00046 if (this != &d) 00047 copy (d); 00048 00049 return *this; 00050 } 00051 00052 ~dir_entry (void) { close (); } 00053 00054 bool open (const std::string& = std::string ()); 00055 00056 string_vector read (void); 00057 00058 void close (void); 00059 00060 bool ok (void) const { return dir && ! fail; } 00061 00062 operator bool () const { return ok (); } 00063 00064 std::string error (void) const { return ok () ? std::string () : errmsg; } 00065 00066 private: 00067 00068 // Name of the directory. 00069 std::string name; 00070 00071 // A pointer to the contents of the directory. We use void here to 00072 // avoid possible conflicts with the way some systems declare the 00073 // type DIR. 00074 void *dir; 00075 00076 // TRUE means the open for this directory failed. 00077 bool fail; 00078 00079 // If a failure occurs, this contains the system error text. 00080 std::string errmsg; 00081 00082 void copy (const dir_entry&); 00083 }; 00084 00085 #endif 00086 00087 /* 00088 ;;; Local Variables: *** 00089 ;;; mode: C++ *** 00090 ;;; End: *** 00091 */