PixelLightAPI  .
ChecksumCRC32.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: ChecksumCRC32.h                                *
00003  *
00004  *  Copyright (C) 2002-2012 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         *  @brief
00076         *    Returns the current CRC32 checksum
00077         *
00078         *  @return
00079         *    Current CRC32 checksum
00080         */
00081         PLCORE_API uint32 GetChecksum() const;
00082 
00083         /**
00084         *  @brief
00085         *    Returns the checksum of a given buffer
00086         *
00087         *  @param[in] pnBuffer
00088         *    Buffer to create the checksum from (MUST be valid!)
00089         *  @param[in] nNumOfBytes
00090         *    Number of bytes of the given buffer (MUST be valid!)
00091         *
00092         *  @return
00093         *    The checksum of the given buffer
00094         */
00095         PLCORE_API uint32 GetChecksum(const uint8 *pnBuffer, uint32 nNumOfBytes);
00096 
00097 
00098     //[-------------------------------------------------------]
00099     //[ Private functions                                     ]
00100     //[-------------------------------------------------------]
00101     private:
00102         /**
00103         *  @brief
00104         *    Initializes the CRC32 table
00105         */
00106         void Init();
00107 
00108         /**
00109         *  @brief
00110         *    Reflection part of the the CRC32 table initialization
00111         *
00112         *  @param[in] nReflection
00113         *    Reflection value
00114         *  @param[in] nCharacter
00115         *    Character to reflect
00116         *
00117         *  @return
00118         *    The reflected character
00119         *
00120         *  @remarks
00121         *    Reflection is a requirement for the official CRC-32 standard.
00122         */
00123         uint32 Reflect(uint32 nReflection, char nCharacter) const;
00124 
00125 
00126     //[-------------------------------------------------------]
00127     //[ Private data                                          ]
00128     //[-------------------------------------------------------]
00129     private:
00130         static Array<uint32> m_lstCRC32Table;   /**< Static CRC32 table */
00131         uint32               m_nCRC32;          /**< Current CRC32 checksum */
00132 
00133 
00134     //[-------------------------------------------------------]
00135     //[ Private virtual Checksum functions                    ]
00136     //[-------------------------------------------------------]
00137     private:
00138         virtual void Update(const uint8 nInput[], uint32 nInputLen) override;
00139         virtual String Final() override;
00140 
00141 
00142 };
00143 
00144 
00145 //[-------------------------------------------------------]
00146 //[ Namespace                                             ]
00147 //[-------------------------------------------------------]
00148 } // PLCore
00149 
00150 
00151 #endif // __PLCORE_CHECKSUMCRC32_H__
00152 


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:52
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported