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

checksumfactory.cpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Written by 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 checksumfactory.cpp 00022 * Utility classes to compute and verify the checksums. 00023 */ 00024 00025 00026 //--------------------------------------------------------------------------- 00027 // For compilers that support precompilation, includes "wx.h". 00028 #include <wx/wxprec.h> 00029 00030 #ifdef __BORLANDC__ 00031 #pragma hdrstop 00032 #endif 00033 00034 #ifndef WX_PRECOMP 00035 // Include your minimal set of headers here, or wx.h 00036 #include <wx/wx.h> 00037 #endif 00038 00039 #include "checksumfactory.hpp" 00040 #include "checksum.hpp" 00041 #include "sumfile.hpp" 00042 #include "md5file.hpp" 00043 #include "sfvfile.hpp" 00044 00045 #include "compat.hpp" 00046 //--------------------------------------------------------------------------- 00047 00048 00049 /// The C++ standard namespace. 00050 using namespace std; 00051 00052 00053 //########################################################################### 00054 // SumFileFactory::SumFileEntry members 00055 //########################################################################### 00056 00057 /** 00058 * Clones the source instance in this instance. 00059 * 00060 * @param source Source instance. 00061 */ 00062 void SumFileFactory::SumFileEntry::clone(const SumFileEntry& source) 00063 { 00064 if (this != &source) 00065 { 00066 this->fnctGetSumFile = source.fnctGetSumFile; 00067 this->name = source.name; 00068 this->descr = source.descr; 00069 this->fileExt = source.fileExt; 00070 } 00071 } 00072 //--------------------------------------------------------------------------- 00073 00074 00075 00076 00077 //########################################################################### 00078 // SumFileFactory members 00079 //########################################################################### 00080 00081 // Static attributes of the SumFileFactory class 00082 SumFileFactory::SumFileEntries SumFileFactory::sumFilesTypes; 00083 //--------------------------------------------------------------------------- 00084 00085 00086 /** 00087 * Initializes the static members of the class. 00088 * 00089 * The name the type of the checksums' file should be the same as the one 00090 * returned by <CODE>checksums_file_type::getFileType()</CODE>. 00091 */ 00092 void SumFileFactory::initialize() 00093 { 00094 sumFilesTypes[SumFileFactory::ftSFV] = SumFileEntry(SFVFile::getNewInstance, wxT("SFV"), _("SFV checksums' file"), wxT("sfv")); 00095 sumFilesTypes[SumFileFactory::ftMD5] = SumFileEntry(MD5File::getNewInstance, wxT("MD5"), _("MD5 checksums' file"), wxT("md5")); 00096 } 00097 //--------------------------------------------------------------------------- 00098 00099 00100 /** 00101 * Gets all the identifers of the available checksums' file types. 00102 * 00103 * @return All the identifers of the available checksums' file types. 00104 */ 00105 wxArrayInt SumFileFactory::getAvailableSumFiles() 00106 { 00107 wxArrayInt res; 00108 00109 const SumFileEntries& sft = sumFilesTypes; 00110 for (SumFileEntries::const_iterator it = sft.begin(); it != sft.end(); it++) 00111 res.Add(it->first); 00112 00113 return res; 00114 } 00115 //--------------------------------------------------------------------------- 00116 00117 00118 /** 00119 * Gets the number of available identifers of checksums' file types. 00120 * 00121 * @return The number of available identifers of checksums' file types. 00122 */ 00123 int SumFileFactory::getSumFilesCount() 00124 { 00125 return sumFilesTypes.size(); 00126 } 00127 //--------------------------------------------------------------------------- 00128 00129 00130 /** 00131 * Returns <CODE>true</CODE> if the given identifer of checksums' file type 00132 * exists. 00133 * 00134 * @return <CODE>true</CODE> if the given identifer of checksums' file type 00135 * exists, <CODE>false</CODE> otherwise. 00136 */ 00137 bool SumFileFactory::exists(const int sumFileType) 00138 { 00139 const SumFileEntries& sft = sumFilesTypes; 00140 SumFileEntries::const_iterator it = sft.find(sumFileType); 00141 00142 return (it != sft.end()); 00143 } 00144 //--------------------------------------------------------------------------- 00145 00146 00147 /** 00148 * Gives a pointer on a new instance of the specified checksums' file type. 00149 * 00150 * The caller is responsible of the deletion of the instance with the 00151 * <CODE>delete</CODE> operator. 00152 * 00153 * @param sumFileType Type of the checksums' file of which the caller want a 00154 * new instance. 00155 * @return A pointer on a new instance of the specified checksums' file type or 00156 * <CODE>NULL</CODE> if the specified checksums' file type is invalid. 00157 */ 00158 SumFile* SumFileFactory::getSumFileNewInstance(int sumFileType) 00159 { 00160 if (exists(sumFileType)) 00161 return sumFilesTypes[sumFileType].fnctGetSumFile(); 00162 else 00163 return NULL; 00164 } 00165 //--------------------------------------------------------------------------- 00166 00167 00168 /** 00169 * Gives the name of the specified checksums' file type. 00170 * 00171 * @param sumFileType Type of the checksums' file of which the caller want the 00172 * name. 00173 * @return The name of the specified checksums' file type or an empty string 00174 * if the specified checksums' file type is invalid. 00175 */ 00176 wxString SumFileFactory::getSumFileName(const int sumFileType) 00177 { 00178 if (exists(sumFileType)) 00179 return sumFilesTypes[sumFileType].name; 00180 else 00181 return wxEmptyString; 00182 } 00183 //--------------------------------------------------------------------------- 00184 00185 00186 /** 00187 * Gives the description of the specified checksums' file type. 00188 * 00189 * @param sumFileType Type of the checksums' file of which the caller want the 00190 * description. 00191 * @return The description of the specified checksums' file type or an empty 00192 * string if the specified checksums' file type is invalid. 00193 */ 00194 wxString SumFileFactory::getSumFileDescription(const int sumFileType) 00195 { 00196 if (exists(sumFileType)) 00197 return sumFilesTypes[sumFileType].descr; 00198 else 00199 return wxEmptyString; 00200 } 00201 //--------------------------------------------------------------------------- 00202 00203 00204 /** 00205 * Gives the file's extension of the specified checksums' file type. 00206 * 00207 * @param sumFileType Type of the checksums' file of which the caller want the 00208 * file's extension. 00209 * @return The file's extension of the specified checksums' file type or an 00210 * empty string if the specified checksums' file type is invalid. 00211 */ 00212 wxString SumFileFactory::getSumFileExtension(const int sumFileType) 00213 { 00214 if (exists(sumFileType)) 00215 return sumFilesTypes[sumFileType].fileExt; 00216 else 00217 return wxEmptyString; 00218 } 00219 //--------------------------------------------------------------------------- 00220

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