Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

sumfile.hpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /** 00021 * \file sumfile.hpp 00022 * Classes that encapsulate sums files. 00023 */ 00024 00025 00026 #ifndef INC_SUMFILE_HPP 00027 #define INC_SUMFILE_HPP 00028 00029 00030 //--------------------------------------------------------------------------- 00031 // For compilers that support precompilation, includes "wx.h". 00032 #include <wx/wxprec.h> 00033 00034 #ifdef __BORLANDC__ 00035 #pragma hdrstop 00036 #endif 00037 00038 #ifndef WX_PRECOMP 00039 // Include your minimal set of headers here, or wx.h 00040 #include <wx/wx.h> 00041 #endif 00042 #include <wx/dynarray.h> 00043 #include <wx/filename.h> 00044 #include <wx/hashmap.h> 00045 00046 #include <climits> 00047 00048 #include "checksum.hpp" 00049 //--------------------------------------------------------------------------- 00050 00051 00052 /** 00053 * Data on a checksum. 00054 */ 00055 class ChecksumData 00056 { 00057 public: 00058 /// States available for a checksum. 00059 enum State 00060 { 00061 NotVerified = 0, // Checksum has not been verified. 00062 Verified, // Checksum has been verified and corresponds. 00063 Invalid, // Checksum has been verified and not corresponds. 00064 NotFound // The file has been not found. 00065 }; 00066 00067 /// Number of elements in the state enum. 00068 #define CD_STATE_COUNT 4 00069 00070 protected: 00071 wxFileName fileName; ///< Name of the file. 00072 wxString sum; ///< String that contains the sum value. 00073 State state; ///< State of the checksum. 00074 00075 // Clones the source instance in this instance. 00076 void clone(const ChecksumData& source); 00077 00078 public: 00079 // Default constructor. 00080 ChecksumData(); 00081 00082 // Copy constructor. 00083 ChecksumData(const ChecksumData& source); 00084 00085 // Assignment operator. 00086 ChecksumData& operator=(const ChecksumData& source); 00087 00088 // Constructor. 00089 ChecksumData(const wxFileName& fn, const wxString& strSum, const State st = NotVerified); 00090 00091 // Constructor. 00092 ChecksumData(const wxString& fn, const wxString& strSum, const State st = NotVerified); 00093 00094 // Gets the file name. 00095 wxFileName getFileName() const; 00096 00097 // Sets the file name. 00098 void setFileName(const wxFileName& fn); 00099 00100 // Sets the file name. 00101 void setFileName(const wxString& fn); 00102 00103 // Gets the checksum value. 00104 wxString getChecksum() const; 00105 00106 // Sets the checksum value. 00107 void setChecksum(const wxString& strSum); 00108 00109 // Gets the state of the checksum. 00110 State getState() const; 00111 00112 // Sets the state of the checksum. 00113 void setState(const State newState); 00114 }; 00115 //--------------------------------------------------------------------------- 00116 00117 00118 /// A hash map of checksum data with integer key. 00119 WX_DECLARE_HASH_MAP(long, ChecksumData, wxIntegerHash, wxIntegerEqual, MChecksumData); 00120 00121 /// An array of long values 00122 WX_DEFINE_ARRAY_LONG(long, MChecksumDataKeys); 00123 //--------------------------------------------------------------------------- 00124 00125 00126 /** 00127 * A sum file. 00128 */ 00129 class SumFile 00130 { 00131 private: 00132 static long idGen; ///< Value for unique identifiers generation. 00133 MChecksumData checksums; ///< The checksums that are contained in the file. 00134 wxString fileName; ///< Name of the checksum file. Empty for none. 00135 bool modified; ///< Indicates that the file has been modified. 00136 00137 00138 protected: 00139 // Gets a new unique identifier. 00140 static long getID(); 00141 00142 // Clones the source instance in this instance. 00143 void clone(const SumFile& source); 00144 00145 private: 00146 // Copy constructor. 00147 SumFile(const SumFile& source); 00148 00149 // Assignment operator. 00150 virtual SumFile& operator=(const SumFile& source); 00151 00152 public: 00153 // Default constructor. 00154 SumFile(); 00155 00156 /** 00157 * Returns an instance of a class that permits to compute the checksum 00158 * value. 00159 * 00160 * The calling function is responsible of the deletion of the instance with 00161 * the <CODE>delete</CODE> operator. 00162 * 00163 * @return An instance of a class that permits to compute the checksum value. 00164 */ 00165 virtual Checksum* getChecksumCalculator() const = 0; 00166 00167 /** 00168 * Returns the type of the file. 00169 * 00170 * @return The type of the file. 00171 */ 00172 virtual wxString getFileType() const = 0; 00173 00174 00175 /** 00176 * Reads the checksums from a file. 00177 * 00178 * After the reading of the file, the state of the file should be unmodified 00179 * and on success, the checksum file name must be the given one (absolute 00180 * path). 00181 * 00182 * The paths of the files in the ChecksumData must be relative to the path of 00183 * <CODE>fileName</CODE>. 00184 * 00185 * @param fileName The file name from which the checksums are read. 00186 * @return <CODE>true</CODE> if the file has been read successfully, 00187 * <CODE>false</CODE> otherwise. 00188 */ 00189 virtual bool read(const wxFileName& fileName) = 0; 00190 00191 /** 00192 * Writes the checksums in a file. 00193 * 00194 * After the writing of the file, the state of the file should be unmodified 00195 * and the file name must be modified to <CODE>fileName</CODE>. 00196 * The paths of the files in the ChecksumData must be relative to the path of 00197 * <CODE>fileName</CODE>. 00198 * 00199 * @param fileName The file name in which the checksums are written. 00200 * @return <CODE>true</CODE> if the checksums have been written successfully, 00201 * <CODE>false</CODE> otherwise. 00202 */ 00203 virtual bool write(const wxFileName& fileName) = 0; 00204 00205 // Resets the sum file. 00206 virtual void reset(); 00207 00208 00209 // Gets the name of the checksum file. Empty for none. 00210 wxString getFileName() const; 00211 00212 // Sets the name of the checksum file. Empty for none. 00213 void setFileName(const wxString& newFileName); 00214 00215 00216 // Indicates whether the file has been modified. 00217 bool getModified() const; 00218 00219 // Sets the "modified" state of the file. 00220 void setModified(const bool newModifiedState); 00221 00222 00223 // Gets all the keys of the checksum data. 00224 void getChecksumDataKeys(MChecksumDataKeys& keys) const; 00225 00226 // Returns the number of checksum data in file. 00227 size_t getChecksumDataCount() const; 00228 00229 // Returns the checksum data of the given key. 00230 ChecksumData getChecksumData(const long key) const; 00231 00232 // Gets the checksum data of the given key. 00233 void getChecksumData(const long key, ChecksumData& checksumData) const; 00234 00235 // Sets the checksum data of the given key. 00236 bool setChecksumData(const long key, const ChecksumData& checksumData); 00237 00238 // Sets the checksum state of the given key. 00239 bool setChecksumState(const long key, const ChecksumData::State state); 00240 00241 // Adds a checksum data in the file. 00242 long addChecksumData(const ChecksumData& checksumData); 00243 00244 // Removes a checksum data in the file. 00245 bool removeChecksumData(const long key); 00246 00247 00248 // Returns an iterator pointing at the first element of the checksums data. 00249 MChecksumData::const_iterator getChecksumDataBegin() const; 00250 00251 // Returns an iterator pointing at the one-after-the-last element of the checksums data. 00252 MChecksumData::const_iterator getChecksumDataEnd() const; 00253 00254 protected: 00255 // Returns an iterator pointing at the first element of the checksums data. 00256 MChecksumData::iterator getChecksumDataBeginI(); 00257 00258 // Returns an iterator pointing at the one-after-the-last element of the checksums data. 00259 MChecksumData::iterator getChecksumDataEndI(); 00260 00261 public: 00262 // Gets the path format that is used in the given file. 00263 wxPathFormat getPathFormat(const wxFileName& fileName, const wxString& commentChars = wxT(";"), const unsigned int maxLinesToRead = UINT_MAX) const; 00264 }; 00265 //--------------------------------------------------------------------------- 00266 00267 /// Array of <CODE>SumFile*</CODE>. 00268 WX_DEFINE_ARRAY(SumFile*, ArraySumFile); 00269 //--------------------------------------------------------------------------- 00270 00271 #endif // INC_SUMFILE_HPP 00272

Generated on Sun May 30 13:37:45 2004 for wxChecksums by doxygen 1.3.7