00001 // This is core/vul/vul_file_iterator.h 00002 #ifndef vul_file_iterator_h_ 00003 #define vul_file_iterator_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief class to iterate through directories and/or "glob" patterns (*.*) 00010 // \author awf@robots.ox.ac.uk 00011 // \date 27 Nov 00 00012 // 00013 // \verbatim 00014 // Modifications 00015 // PDA (Manchester) 21/03/2001: Tidied up the documentation 00016 // Peter Vanroose 27/05/2001: Corrected the documentation 00017 // Ian Scott 12/06/2003: Added filen?m[abc].* notation to unix and dos version 00018 // \endverbatim 00019 00020 #include <vcl_string.h> 00021 00022 struct vul_file_iterator_data; 00023 00024 //: Iterate through directories and/or "glob" patterns (*.*) 00025 // It is efficient to use 00026 // \code 00027 // for (vul_file_iterator fn="/dir/*"; fn; ++fn) { 00028 // ... use fn() as filename 00029 // } 00030 // \endcode 00031 // simply to list the contents of a directory. If you really 00032 // want just the *.ext files, it is efficient to use 00033 // \code 00034 // for (vul_file_iterator fn="/dir/*.ext"; fn; ++fn) { 00035 // ... use fn() as filename 00036 // } 00037 // \endcode 00038 // rather than opendir/glob/etc. 00039 // 00040 // Valid glob patterns are unix-like - '?' matches precisely one character 00041 // '*' matches any sequence (including empty), [abc] matches either 'a' or 'b' or 'c' 00042 00043 class vul_file_iterator 00044 { 00045 VCL_SAFE_BOOL_DEFINE; 00046 public: 00047 00048 vul_file_iterator() : p(0) {} 00049 00050 //: Initialize, and scan to get first file from "glob" 00051 vul_file_iterator(char const* glob); 00052 00053 //: Initialize, and scan to get first file from "glob" 00054 vul_file_iterator(vcl_string const& glob); 00055 00056 ~vul_file_iterator(); 00057 00058 //: Ask if done. 00059 // Won't spin the disk 00060 operator safe_bool() const; 00061 00062 //: Inverse boolean value 00063 bool operator!() const; 00064 00065 //: Return the currently pointed-to pathname. 00066 // Won't spin the disk 00067 char const* operator()(); 00068 00069 //: Return the non-directory part of the current pathname. 00070 char const* filename(); 00071 00072 //: Return the match for the i'th glob wildcard character (* or ?). 00073 // Uses the most recent glob result. 00074 char const* match(int i); 00075 00076 //: Increment to the next file 00077 // Will spin the disk 00078 vul_file_iterator& operator++(); 00079 00080 //: Run a new match 00081 void reset(char const* glob); 00082 00083 protected: 00084 vul_file_iterator_data* p; 00085 00086 private: 00087 // postfix++ privatized. 00088 vul_file_iterator operator++(int) { return vul_file_iterator(); } 00089 }; 00090 00091 #endif // vul_file_iterator_h_
1.5.1