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::entry class. 00035 **/ 00036 00037 #ifndef __sord_entry_h__ 00038 #define __sord_entry_h__ 00039 00040 // system includes 00041 #include <ctime> 00042 00043 namespace sord { 00044 class dimpl; // forward declaration 00045 00046 /** 00047 * The sord::entry class is used to hold one directory 00048 * entry and to retreive information about that entry. 00049 **/ 00050 class entry { 00051 public: 00052 /// type for the entry mode 00053 typedef unsigned int mode_type; 00054 00055 /// type for the entry size 00056 typedef unsigned long size_type; 00057 00058 /// type for the entry times 00059 typedef std::time_t time_type; 00060 00061 /// all possible types that an entry might be 00062 enum type { 00063 type_pipe, ///< FIFO Pipe 00064 type_character, ///< Character Special 00065 type_directory, ///< Directory 00066 type_block, ///< Block Special 00067 type_regular, ///< Normal File 00068 type_symlink, ///< Symbolic Link 00069 type_socket ///< Domain Socket 00070 }; 00071 00072 /// enum to hold the mode bits 00073 enum mode_bits { 00074 mode_user_read = 0x000100, ///< readable by owner 00075 mode_user_write = 0x000080, ///< writeable by owner 00076 mode_user_execute = 0x000040, ///< executable by owner 00077 mode_group_read = 0x000020, ///< readable by group 00078 mode_group_write = 0x000010, ///< writeable by group 00079 mode_group_execute = 0x000008, ///< executable by group 00080 mode_other_read = 0x000004, ///< readable by everyone else 00081 mode_other_write = 0x000002, ///< writeable by everyone else 00082 mode_other_execute = 0x000001 ///< executable by everyone else 00083 }; 00084 00085 //#################################################################### 00086 /** 00087 * sord::entry class constructor. Given the name/path of a directory 00088 * entry, the constructor will load information about that entry. 00089 * 00090 * @param name The name of a directory entry to open. 00091 * @author Peter Jones 00092 **/ 00093 //#################################################################### 00094 explicit entry (const char *name); 00095 00096 //#################################################################### 00097 /** 00098 * Copy information about an entry from an existing entry. 00099 * 00100 * @param other The entry to copy information from. 00101 * @author Peter Jones 00102 **/ 00103 //#################################################################### 00104 entry (const entry &other); 00105 00106 //#################################################################### 00107 /** 00108 * Assignment operator. Reset this entries information to that of the 00109 * other entry. 00110 * 00111 * @param other The entry to copy information from. 00112 * @return description 00113 * @author Peter Jones 00114 **/ 00115 //#################################################################### 00116 entry& operator= (const entry &other); 00117 00118 //#################################################################### 00119 /** 00120 * Swap this entry with another one. 00121 * 00122 * @param other The other entry to swap information with. 00123 * @author Peter Jones 00124 **/ 00125 //#################################################################### 00126 void swap (entry &other); 00127 00128 //#################################################################### 00129 /** 00130 * sord::entry class destructor 00131 * 00132 * @author Peter Jones 00133 **/ 00134 //#################################################################### 00135 ~entry (void); 00136 00137 //#################################################################### 00138 /** 00139 * Get the name of this directory entry. The returned string contains 00140 * only the name of the entry with no path information. 00141 * 00142 * @return The name of the entry. 00143 * @author Peter Jones 00144 **/ 00145 //#################################################################### 00146 const char* get_name (void) const; 00147 00148 //#################################################################### 00149 /** 00150 * Get the path and name for this entry. The returned string contains 00151 * the name of the entry with absolute or relative path information. 00152 * 00153 * @param The path and name of the entry. 00154 * @return description 00155 * @author Peter Jones 00156 **/ 00157 //#################################################################### 00158 const char* get_path (void) const; 00159 00160 //#################################################################### 00161 /** 00162 * Get the entry type. 00163 * 00164 * @return The entry type. 00165 * @author Peter Jones 00166 **/ 00167 //#################################################################### 00168 type get_type (void) const; 00169 00170 //#################################################################### 00171 /** 00172 * Get the entry mode. 00173 * 00174 * @return The entry mode. 00175 * @author Peter Jones 00176 **/ 00177 //#################################################################### 00178 mode_type get_mode (void) const; 00179 00180 //#################################################################### 00181 /** 00182 * Get the time that the entry was last modified. 00183 * 00184 * @return The mtime. 00185 * @author Peter Jones 00186 **/ 00187 //#################################################################### 00188 time_type get_mtime (void) const; 00189 00190 //#################################################################### 00191 /** 00192 * Get the time that the entry was last accessed. 00193 * 00194 * @return The atime 00195 * @author Peter Jones 00196 **/ 00197 //#################################################################### 00198 time_type get_atime (void) const; 00199 00200 //#################################################################### 00201 /** 00202 * Get the size of the entry in bytes. 00203 * 00204 * @return The size of the entry. 00205 * @author Peter Jones 00206 **/ 00207 //#################################################################### 00208 size_type get_size (void) const; 00209 00210 //#################################################################### 00211 /** 00212 * Check to see if the entry is valid. 00213 * 00214 * @return True if the entry is INVALID; false if the entry is valid. 00215 * @author Peter Jones 00216 **/ 00217 //#################################################################### 00218 bool operator! (void) const; 00219 00220 private: 00221 struct pimpl; mutable pimpl *pimpl_; 00222 00223 entry (void); 00224 void set (const void *data, const char *path); 00225 friend class dimpl; 00226 }; // end entry class 00227 00228 } // end sord namespace 00229 #endif