Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:18

0001 #ifndef FWCore_Utilities_CRC32Calculator_h
0002 #define FWCore_Utilities_CRC32Calculator_h
0003 
0004 /*
0005 Code to calculate a CRC32 checksum on a string.  This code is based
0006 on code copied from the web in the public domain.  The code was modified
0007 quite a bit to provide the interface we need, remove extraneous code
0008 related to NAACR records, convert from C to C++, and use a
0009 boost type for the 32 unsigned integers, but the essential features
0010 of the CRC calculation are the same.  The array values, constants,
0011 and algorithmic steps are identical.  The comments in the header
0012 from the original code follow below to attribute the source.
0013 */
0014 
0015 /* crc32.c
0016 
0017    C implementation of CRC-32 checksums for NAACCR records.  Code is based
0018    upon and utilizes algorithm published by Ross Williams.
0019 
0020    This file contains:
0021       CRC lookup table
0022       function CalcCRC32 for calculating CRC-32 checksum
0023       function AssignCRC32 for assigning CRC-32 in NAACCR record
0024       function CheckCRC32 for checking CRC-32 in NAACCR record
0025 
0026    Provided by:
0027       Eric Durbin
0028       Kentucky Cancer Registry
0029       University of Kentucky
0030       October 14, 1998
0031 
0032    Status:
0033       Public Domain
0034 */
0035 
0036 /*****************************************************************/
0037 /*                                                               */
0038 /* CRC LOOKUP TABLE                                              */
0039 /* ================                                              */
0040 /* The following CRC lookup table was generated automagically    */
0041 /* by the Rocksoft^tm Model CRC Algorithm Table Generation       */
0042 /* Program V1.0 using the following model parameters:            */
0043 /*                                                               */
0044 /*    Width   : 4 bytes.                                         */
0045 /*    Poly    : 0x04C11DB7L                                      */
0046 /*    Reverse : TRUE.                                            */
0047 /*                                                               */
0048 /* For more information on the Rocksoft^tm Model CRC Algorithm,  */
0049 /* see the document titled "A Painless Guide to CRC Error        */
0050 /* Detection Algorithms" by Ross Williams                        */
0051 /* (ross@guest.adelaide.edu.au.). This document is likely to be  */
0052 /* in the FTP archive "ftp.adelaide.edu.au/pub/rocksoft".        */
0053 /*                                                               */
0054 /*****************************************************************/
0055 
0056 #include <cstdint>
0057 
0058 #include <string>
0059 
0060 namespace cms {
0061 
0062   class CRC32Calculator {
0063   public:
0064     CRC32Calculator(std::string const& message);
0065 
0066     std::uint32_t checksum() { return checksum_; }
0067 
0068   private:
0069     std::uint32_t checksum_;
0070   };
0071 }  // namespace cms
0072 #endif