libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


crccalc.h
1//---------------------------------------------------------------------
2// Algorithmic Conjurings @ http://www.coyotegulch.com
3//
4// crccalc.h (libcoyotl)
5//
6// Defines tools for calculating 32-bit cyclic-redundancy (CRC)
7// values from arrays of 8-bit byte data.
8//---------------------------------------------------------------------
9//
10// Copyright 1990-2005 Scott Robert Ladd
11//
12// This program is free software; you can redistribute it and/or modify
13// it under the terms of the GNU General Public License as published by
14// the Free Software Foundation; either version 2 of the License, or
15// (at your option) any later version.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the
24// Free Software Foundation, Inc.
25// 59 Temple Place - Suite 330
26// Boston, MA 02111-1307, USA.
27//
28//-----------------------------------------------------------------------
29//
30// For more information on this software package, please visit
31// Scott's web site, Coyote Gulch Productions, at:
32//
33// http://www.coyotegulch.com
34//
35//-----------------------------------------------------------------------
36
37#if !defined(LIBCOYOTL_CRCCALC_H)
38#define LIBCOYOTL_CRCCALC_H
39
40namespace libcoyotl
41{
43 typedef unsigned long crc32_t;
44
46
53 {
54 // internal class for preclaculated table
55 private:
56 class crc_precalc
57 {
58 public:
59 // constructor
60 crc_precalc();
61
62 // return element of table
63 crc32_t operator [] (int n) const
64 {
65 return m_table[n];
66 }
67
68 protected:
69 // table of precalculated values
70 crc32_t m_table[256];
71 };
72
73 public:
75
79
81
88 void update(const unsigned char * a_data, size_t a_length);
89
91
97 {
98 return m_crc ^ 0xFFFFFFFFL;
99 }
100
101 private:
102 // precacluated table
103 static crc_precalc s_table;
104
105 // computed CRC value
106 crc32_t m_crc;
107 };
108
109} // end namespace libcoyotl
110
111#endif
A STL-compatible array class.
Definition array.h:73
Calculate 32-bit CRC values from byte data.
Definition crccalc.h:53
void update(const unsigned char *a_data, size_t a_length)
Update CRC for a given data set.
crc32_t get_crc32()
Get CRC value.
Definition crccalc.h:96

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.