PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: ChecksumCRC32.h * 00003 * 00004 * Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLCORE_CHECKSUMCRC32_H__ 00024 #define __PLCORE_CHECKSUMCRC32_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Container/Array.h" 00032 #include "PLCore/Tools/Checksum.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLCore { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Classes ] 00043 //[-------------------------------------------------------] 00044 /** 00045 * @brief 00046 * CRC32 (cyclic redundancy check) checksum 00047 * 00048 * @remarks 00049 * This implementation is using the official polynomial (0x04C11DB7) used by CRC32 in 00050 * PKZip, WinZip and Ethernet. Often times the polynomial shown reversed as 0xEDB88320. 00051 * 00052 * @note 00053 * - CRC32 produces a 32-bit/4-byte hash 00054 */ 00055 class ChecksumCRC32 : public Checksum { 00056 00057 00058 //[-------------------------------------------------------] 00059 //[ Public functions ] 00060 //[-------------------------------------------------------] 00061 public: 00062 /** 00063 * @brief 00064 * Constructor 00065 */ 00066 PLCORE_API ChecksumCRC32(); 00067 00068 /** 00069 * @brief 00070 * Destructor 00071 */ 00072 PLCORE_API virtual ~ChecksumCRC32(); 00073 00074 00075 //[-------------------------------------------------------] 00076 //[ Private functions ] 00077 //[-------------------------------------------------------] 00078 private: 00079 /** 00080 * @brief 00081 * Initializes the CRC32 table 00082 */ 00083 void Init(); 00084 00085 /** 00086 * @brief 00087 * Reflection part of the the CRC32 table initialization 00088 * 00089 * @param[in] nReflection 00090 * Reflection value 00091 * @param[in] nCharacter 00092 * Character to reflect 00093 * 00094 * @return 00095 * The reflected character 00096 * 00097 * @remarks 00098 * Reflection is a requirement for the official CRC-32 standard. 00099 */ 00100 uint32 Reflect(uint32 nReflection, char nCharacter) const; 00101 00102 00103 //[-------------------------------------------------------] 00104 //[ Private data ] 00105 //[-------------------------------------------------------] 00106 private: 00107 static Array<uint32> m_lstCRC32Table; /**< Static CRC32 table */ 00108 uint32 m_nCRC32; /**< Current CRC32 checksum */ 00109 00110 00111 //[-------------------------------------------------------] 00112 //[ Private virtual Checksum functions ] 00113 //[-------------------------------------------------------] 00114 private: 00115 virtual void Update(const uint8 nInput[], uint32 nInputLen) override; 00116 virtual String Final() override; 00117 00118 00119 }; 00120 00121 00122 //[-------------------------------------------------------] 00123 //[ Namespace ] 00124 //[-------------------------------------------------------] 00125 } // PLCore 00126 00127 00128 #endif // __PLCORE_CHECKSUMCRC32_H__ 00129
|