00001 /* 00002 * Copyright (C) 2001-2002 Peter J Jones (pjones@pmade.org) 00003 * All Rights Reserved 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in 00013 * the documentation and/or other materials provided with the 00014 * distribution. 00015 * 3. Neither the name of the Author nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00021 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00022 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 00023 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00026 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00027 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00028 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00029 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00030 * SUCH DAMAGE. 00031 */ 00032 00033 /** @file 00034 * This file contains the definition of the sord::directory class. 00035 **/ 00036 00037 #ifndef __sord_directory_h__ 00038 #define __sord_directory_h__ 00039 00040 #include <sord/entry.h> 00041 #include <iterator> 00042 00043 namespace sord { 00044 class dimpl; // forward declaration 00045 00046 /** 00047 * The sord::directory class is used to iterate over the entires 00048 * in a directory. 00049 **/ 00050 class directory { 00051 public: 00052 //#################################################################### 00053 /** 00054 * sord::directory constructor 00055 * 00056 * @param path The path to the directory to open 00057 * @author Peter Jones 00058 **/ 00059 //#################################################################### 00060 explicit directory (const char *path); 00061 00062 //#################################################################### 00063 /** 00064 * sord::directory constructor 00065 * 00066 * @param e A sord::entry that refers to a directory to open 00067 * @author Peter Jones 00068 **/ 00069 //#################################################################### 00070 explicit directory (const entry &e); 00071 00072 //#################################################################### 00073 /** 00074 * sord::directory destructor 00075 * 00076 * @author Peter Jones 00077 **/ 00078 //#################################################################### 00079 ~directory (void); 00080 00081 /// directory iterator 00082 class const_iterator { 00083 public: 00084 typedef entry value_type; 00085 typedef std::ptrdiff_t difference_type; 00086 typedef value_type* pointer; 00087 typedef value_type& reference; 00088 typedef std::forward_iterator_tag iterator_category; 00089 00090 00091 const reference operator* (void) const; 00092 const pointer operator-> (void) const; 00093 00094 /** 00095 * Only prefix increment is supported so that you cannot make a copy 00096 * of a directory iterator. 00097 **/ 00098 const_iterator& operator++ (void); 00099 00100 friend bool operator== (const const_iterator &lhs, const const_iterator &rhs); 00101 friend bool operator!= (const const_iterator &lhs, const const_iterator &rhs); 00102 private: 00103 explicit const_iterator (dimpl *parent); 00104 void set_parent (dimpl *parent); 00105 mutable dimpl *parent_; 00106 00107 friend class directory; 00108 friend class dimpl; 00109 00110 // don't allow copy construction or assignment 00111 const_iterator (const const_iterator &other); 00112 const_iterator& operator= (const const_iterator &other); 00113 const_iterator operator++ (int); 00114 }; // end sord::directory::const_iterator class 00115 00116 //#################################################################### 00117 /** 00118 * Get an iterator to the begining of the directory listing. 00119 * 00120 * @return A const_iterator that points to the start of the directory 00121 * @author Peter Jones 00122 **/ 00123 //#################################################################### 00124 const_iterator& begin (void) const; 00125 00126 //#################################################################### 00127 /** 00128 * Get an end iterator for the directory listing. 00129 * 00130 * @return A const_iterator that points one element past the end. 00131 * @author Peter Jones 00132 **/ 00133 //#################################################################### 00134 const_iterator& end (void) const; 00135 00136 //#################################################################### 00137 /** 00138 * Get the name of this directory. This may or may not be the same as 00139 * the name you gave in the constructor. 00140 * 00141 * @return The name of this directory. 00142 * @author Peter Jones 00143 **/ 00144 //#################################################################### 00145 const char* get_name (void) const; 00146 00147 //#################################################################### 00148 /** 00149 * Find out if the directory opened was vaild. 00150 * 00151 * @return True if the directory was NOT VAILD; false if it was vaild. 00152 * @author Peter Jones 00153 **/ 00154 //#################################################################### 00155 bool operator! (void) const; 00156 private: 00157 dimpl *pimpl_; // private implementation 00158 00159 // don't allow copy construction or assignment 00160 directory (const directory&); 00161 directory& operator= (const directory&); 00162 }; // end sord::directory class 00163 00164 } // end sord namespace 00165 #endif