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.hpp 00022 * Classes for enumerate and create all the checksums' files types that the 00023 * application knows. 00024 */ 00025 00026 #ifndef INC_CHECKSUMFACTORY_HPP 00027 #define INC_CHECKSUMFACTORY_HPP 00028 00029 //--------------------------------------------------------------------------- 00030 // For compilers that support precompilation, includes "wx.h". 00031 #include <wx/wxprec.h> 00032 00033 #ifdef __BORLANDC__ 00034 #pragma hdrstop 00035 #endif 00036 00037 #ifndef WX_PRECOMP 00038 // Include your minimal set of headers here, or wx.h 00039 #include <wx/wx.h> 00040 #endif 00041 00042 #include <wx/hashmap.h> 00043 00044 #include "checksum.hpp" 00045 #include "sumfile.hpp" 00046 //--------------------------------------------------------------------------- 00047 00048 00049 /// Pointer to a function which returns a pointer on a new instance of the <CODE>SumFile</CODE> class. 00050 typedef SumFile* (FnctGetSumFile)(); 00051 00052 00053 /** 00054 * Generates new instances of the subclasses of the <CODE>SumFile</CODE> class 00055 * that the application knows. 00056 * 00057 * Known classes are registered in the <CODE>Initialize</CODE> static member. 00058 * Call it at the start of the program. 00059 * 00060 * The enumeration of known checksums' file types begin from <CODE>0</CODE> to 00061 * <CODE>getSumFilesCount() - 1</CODE>. 00062 */ 00063 class SumFileFactory 00064 { 00065 private: 00066 /** 00067 * Represents an entry of the checksums' files that the application knows. 00068 */ 00069 class SumFileEntry 00070 { 00071 public: 00072 FnctGetSumFile* fnctGetSumFile; ///< Pointer on a function that gives a pointer on a new instance of the <CODE>SumFile</CODE> class. 00073 wxString name; ///< Name of the checksums' file type. 00074 wxString descr; ///< Description of the checksums' file type. 00075 wxString fileExt; ///< Extension of the checksums' file type. 00076 00077 protected: 00078 // Clones the source instance in this instance. 00079 void clone(const SumFileEntry& source); 00080 00081 public: 00082 /// Default constructor 00083 SumFileEntry() { fnctGetSumFile = NULL; } 00084 00085 /** 00086 * Constructor. 00087 * 00088 * @param getSumFile Pointer on a function that gives a pointer on 00089 * a new instance of the <CODE>SumFile</CODE> class. 00090 * @param name Name of the checksums' file type. 00091 * @param description Description of the checksums' file type. 00092 * @param sumFileExtension Standard extension of the checksums' file type. 00093 */ 00094 SumFileEntry(FnctGetSumFile* getSumFile, const wxString& name, 00095 const wxString& description, const wxString& sumFileExtension) : 00096 fnctGetSumFile(getSumFile), name(name), descr(description), 00097 fileExt(sumFileExtension) {} 00098 00099 /** 00100 * Copy constructor. 00101 * 00102 * @param source Source instance. 00103 */ 00104 SumFileEntry(const SumFileEntry& source) { clone(source); }; 00105 00106 /** 00107 * Assignment operator. 00108 * 00109 * @param source Source instance. 00110 * @return A reference on the instance. 00111 */ 00112 SumFileEntry& operator=(const SumFileEntry& source) { clone(source); return *this; }; 00113 }; 00114 00115 /// A hashmap of string keys and SumFileEntry values. 00116 // WX_DECLARE_STRING_HASH_MAP(SumFileEntry, ); 00117 WX_DECLARE_HASH_MAP(int, SumFileEntry, wxIntegerHash, wxIntegerEqual, SumFileEntries); 00118 00119 static SumFileEntries sumFilesTypes; ///< All the checksums' file types that the application knows. 00120 00121 /// Default constructor. Don't use it. 00122 SumFileFactory() {} 00123 00124 public: 00125 // Initializes the static members of the class. 00126 static void initialize(); 00127 00128 // Gets all the identifers of the available checksums' file types. 00129 static wxArrayInt getAvailableSumFiles(); 00130 00131 // Gets the number of available identifers of checksums' file types. 00132 static int getSumFilesCount(); 00133 00134 // Returns true if the given identifer of checksums' file type exists. 00135 static bool exists(const int sumFileType); 00136 00137 // Gives a pointer on a new instance of the specified checksums' file type. 00138 static SumFile* getSumFileNewInstance(const int sumFileType); 00139 00140 // Gives the name of the specified checksums' file type. 00141 static wxString getSumFileName(const int sumFileType); 00142 00143 // Gives the description of the specified checksums' file type. 00144 static wxString getSumFileDescription(const int sumFileType); 00145 00146 // Gives the file's extension of the specified checksums' file type. 00147 static wxString getSumFileExtension(const int sumFileType); 00148 00149 00150 /// Enumeration of the types of the checksums' files. 00151 enum SumFileType 00152 { 00153 ftSFV = 0, 00154 ftMD5 00155 }; 00156 }; 00157 //--------------------------------------------------------------------------- 00158 00159 00160 #endif // INC_CHECKSUMFACTORY_HPP