00001 #ifndef FWCore_Utilities_CRC32Calculator_h 00002 #define FWCore_Utilities_CRC32Calculator_h 00003 00004 /* 00005 Code to calculate a CRC32 checksum on a string. This code is based 00006 on code copied from the web in the public domain. The code was modified 00007 quite a bit to provide the interface we need, remove extraneous code 00008 related to NAACR records, convert from C to C++, and use a 00009 boost type for the 32 unsigned integers, but the essential features 00010 of the CRC calculation are the same. The array values, constants, 00011 and algorithmic steps are identical. The comments in the header 00012 from the original code follow below to attribute the source. 00013 */ 00014 00015 /* crc32.c 00016 00017 C implementation of CRC-32 checksums for NAACCR records. Code is based 00018 upon and utilizes algorithm published by Ross Williams. 00019 00020 This file contains: 00021 CRC lookup table 00022 function CalcCRC32 for calculating CRC-32 checksum 00023 function AssignCRC32 for assigning CRC-32 in NAACCR record 00024 function CheckCRC32 for checking CRC-32 in NAACCR record 00025 00026 Provided by: 00027 Eric Durbin 00028 Kentucky Cancer Registry 00029 University of Kentucky 00030 October 14, 1998 00031 00032 Status: 00033 Public Domain 00034 */ 00035 00036 /*****************************************************************/ 00037 /* */ 00038 /* CRC LOOKUP TABLE */ 00039 /* ================ */ 00040 /* The following CRC lookup table was generated automagically */ 00041 /* by the Rocksoft^tm Model CRC Algorithm Table Generation */ 00042 /* Program V1.0 using the following model parameters: */ 00043 /* */ 00044 /* Width : 4 bytes. */ 00045 /* Poly : 0x04C11DB7L */ 00046 /* Reverse : TRUE. */ 00047 /* */ 00048 /* For more information on the Rocksoft^tm Model CRC Algorithm, */ 00049 /* see the document titled "A Painless Guide to CRC Error */ 00050 /* Detection Algorithms" by Ross Williams */ 00051 /* (ross@guest.adelaide.edu.au.). This document is likely to be */ 00052 /* in the FTP archive "ftp.adelaide.edu.au/pub/rocksoft". */ 00053 /* */ 00054 /*****************************************************************/ 00055 00056 #include "boost/cstdint.hpp" 00057 00058 #include <string> 00059 00060 namespace cms { 00061 00062 class CRC32Calculator { 00063 00064 public: 00065 00066 CRC32Calculator(std::string const& message); 00067 00068 boost::uint32_t checksum() { return checksum_; } 00069 00070 private: 00071 00072 boost::uint32_t checksum_; 00073 }; 00074 } 00075 #endif