CrystalSpace

Public API Reference

csutil/checksum.h
00001 /*
00002   Copyright (C) 2009-2011 by Frank Richter
00003 
00004   This library is free software; you can redistribute it and/or
00005   modify it under the terms of the GNU Library General Public
00006   License as published by the Free Software Foundation; either
00007   version 2 of the License, or (at your option) any later version.
00008 
00009   This library is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012   Library General Public License for more details.
00013 
00014   You should have received a copy of the GNU Library General Public
00015   License along with this library; if not, write to the Free
00016   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_CSUTIL_CHECKSUM_H__
00020 #define __CS_CSUTIL_CHECKSUM_H__
00021 
00022 #include "csextern.h"
00023 #include "iutil/databuff.h"
00024 
00025 namespace CS
00026 {
00027   namespace Utility
00028   {
00029     namespace Checksum
00030     {
00052       class Adler32
00053       {
00054         static inline uint32 Initial() { return 1; }
00055         static CS_CRYSTALSPACE_EXPORT uint32 Compute (uint32 prevCheckSum,
00056           const void* data, size_t size);
00057         
00058         uint32 checksum;
00059         
00060       public:
00061         Adler32 () : checksum (Initial()) {}
00062 
00064 
00065         Adler32 (const void* data, size_t size) : checksum (Compute (Initial(), data, size)) {}
00066         Adler32 (iDataBuffer* data) 
00067          : checksum (Compute (Initial(), data->GetData(), data->GetSize())) {}
00069         
00071 
00076         Adler32 (uint32 prevCheckSum, const void* data, size_t size)
00077          : checksum (Compute (prevCheckSum, data, size)) {}
00078         Adler32 (uint32 prevCheckSum, iDataBuffer* data)
00079          : checksum (Compute (prevCheckSum, data->GetData(), data->GetSize())) {}
00081         
00083         void Append (const uint8* data, size_t size)
00084         { checksum = Compute (checksum, data, size); }
00086         uint32 Finish ()
00087         { return checksum; }
00088         
00090         operator uint32() const
00091         { return checksum; }
00092       };
00093 
00115       class CRC32
00116       {
00117         static inline uint32 Initial() { return 0; }
00118         static CS_CRYSTALSPACE_EXPORT uint32 Compute (uint32 prevCheckSum,
00119           const void* data, size_t size);
00120         
00121         uint32 checksum;
00122         
00123       public:
00124         CRC32 () : checksum (Initial()) {}
00125 
00127 
00128         CRC32 (const void* data, size_t size) : checksum (Compute (Initial(), data, size)) {}
00129         CRC32 (iDataBuffer* data) 
00130          : checksum (Compute (Initial(), data->GetData(), data->GetSize())) {}
00132         
00134 
00139         CRC32 (uint32 prevCheckSum, const void* data, size_t size)
00140          : checksum (Compute (prevCheckSum, data, size)) {}
00141         CRC32 (uint32 prevCheckSum, iDataBuffer* data)
00142          : checksum (Compute (prevCheckSum, data->GetData(), data->GetSize())) {}
00144         
00146         void Append (const uint8* data, size_t size)
00147         { checksum = Compute (checksum, data, size); }
00149         uint32 Finish ()
00150         { return checksum; }
00151         
00153         operator uint32() const
00154         { return checksum; }
00155       };
00156 
00157     } // namespace Checksum
00158   } // namespace Utility
00159 } // namespace CS
00160 
00161 #endif // __CS_CSUTIL_CHECKSUM_H__

Generated for Crystal Space 2.0 by doxygen 1.7.6.1