Created by Scott Robert Ladd at Coyote Gulch Productions.
00001 //--------------------------------------------------------------------- 00002 // Algorithmic Conjurings @ http://www.coyotegulch.com 00003 // 00004 // crccalc.h (libcoyotl) 00005 // 00006 // Defines tools for calculating 32-bit cyclic-redundancy (CRC) 00007 // values from arrays of 8-bit byte data. 00008 //--------------------------------------------------------------------- 00009 // 00010 // Copyright 1990-2005 Scott Robert Ladd 00011 // 00012 // This program is free software; you can redistribute it and/or modify 00013 // it under the terms of the GNU General Public License as published by 00014 // the Free Software Foundation; either version 2 of the License, or 00015 // (at your option) any later version. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU General Public License 00023 // along with this program; if not, write to the 00024 // Free Software Foundation, Inc. 00025 // 59 Temple Place - Suite 330 00026 // Boston, MA 02111-1307, USA. 00027 // 00028 //----------------------------------------------------------------------- 00029 // 00030 // For more information on this software package, please visit 00031 // Scott's web site, Coyote Gulch Productions, at: 00032 // 00033 // http://www.coyotegulch.com 00034 // 00035 //----------------------------------------------------------------------- 00036 00037 #if !defined(LIBCOYOTL_CRCCALC_H) 00038 #define LIBCOYOTL_CRCCALC_H 00039 00040 namespace libcoyotl 00041 { 00043 typedef unsigned long crc32_t; 00044 00046 00052 class crc_calculator 00053 { 00054 // internal class for preclaculated table 00055 private: 00056 class crc_precalc 00057 { 00058 public: 00059 // constructor 00060 crc_precalc(); 00061 00062 // return element of table 00063 crc32_t operator [] (int n) const 00064 { 00065 return m_table[n]; 00066 } 00067 00068 protected: 00069 // table of precalculated values 00070 crc32_t m_table[256]; 00071 }; 00072 00073 public: 00075 00078 crc_calculator(); 00079 00081 00088 void update(const unsigned char * a_data, size_t a_length); 00089 00091 00096 crc32_t get_crc32() 00097 { 00098 return m_crc ^ 0xFFFFFFFFL; 00099 } 00100 00101 private: 00102 // precacluated table 00103 static crc_precalc s_table; 00104 00105 // computed CRC value 00106 crc32_t m_crc; 00107 }; 00108 00109 } // end namespace libcoyotl 00110 00111 #endif
© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.