summaryrefslogtreecommitdiffstats
path: root/crc32.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-03-05 17:39:48 +0100
committermanuel <manuel@mausz.at>2013-03-05 17:39:48 +0100
commit310a2c101b32a5e71a616027b6a1b788a341bc02 (patch)
treea871e1dda8b1de141ae1400ba666fe3b1de96361 /crc32.h
downloadtsclient-master.tar.gz
tsclient-master.tar.bz2
tsclient-master.zip
initial GPLv2 releaseHEADmaster
Diffstat (limited to 'crc32.h')
-rw-r--r--crc32.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/crc32.h b/crc32.h
new file mode 100644
index 0000000..6114d96
--- /dev/null
+++ b/crc32.h
@@ -0,0 +1,108 @@
1/*
2 * CRC32
3 * Written by Julien Couot.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20/**
21 * \file crc32.h
22 * Compute crc32.
23 */
24
25#ifndef CRC32_H
26#define CRC32_H
27
28//---------------------------------------------------------------------------
29// For compilers that support precompilation, includes "wx.h".
30#include <wx/wxprec.h>
31
32#ifdef __BORLANDC__
33#pragma hdrstop
34#endif
35
36#ifndef WX_PRECOMP
37// Include your minimal set of headers here, or wx.h
38#include <wx/wx.h>
39#endif
40
41//---------------------------------------------------------------------------
42
43
44/**
45 * Computes the CRC-32 from a byte stream.
46 *
47 * This class is writen with the code found in
48 * <A HREF="http://www.fodder.org/cksfv/">cksfv</A> and
49 * <A HREF="http://www.gzip.org/zlib/">zlib</A> code.
50 *
51 * Using this class in very simple:<BR>
52 * Use the @link update(const wxByte* buf, unsigned int len) update @endlink
53 * method to provide to the class the bytes for computing the checksum.
54 *
55 * The CRC-32 checksum value can be gotten by the @link getValue(const bool) const
56 * getValue @endlink method which puts the CRC32 checksum value in a
57 * unsigned 32 bits integer.
58 *
59 * The CRC32 checksum computing can be reseted by the @link reset() reset
60 * @endlink method.
61 */
62class CRC32
63{
64 protected:
65 /// Table used to compute the CRC32 value.
66 static const wxUint32 crc_table[256];
67
68 /// The current CRC32 value.
69 wxUint32 crc32;
70
71 public:
72 /**
73 * Default constructor.
74 */
75 CRC32();
76
77 /**
78 * Resets the CRC32 to initial value.
79 */
80 void reset();
81
82 /**
83 * Returns the CRC32 value.
84 *
85 * @return The current checksum value.
86 */
87 wxUint32 getUint32Value() const;
88
89 /**
90 * Returns the CRC32 value in a string.
91 *
92 * @param hexInUpperCase If <CODE>true</CODE> the hexadecimal letters will
93 * be in uppercase.
94 * @return The current CRC32 value.
95 */
96 wxString getValue(const bool hexInUpperCase = false) const;
97
98 /**
99 * Updates the CRC32 with specified array of bytes.
100 *
101 * @param buf The byte array to update the CRC32 with.
102 * @param len The number of bytes to use for the update.
103 */
104 void update(const wxByte *buf, unsigned int len);
105};
106//---------------------------------------------------------------------------
107
108#endif