1 //------------------------------------------------------------------------
2 //  EDGE CRC : Cyclic Rendundancy Check
3 //------------------------------------------------------------------------
4 //
5 //  Copyright (c) 2003-2008  The EDGE Team.
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //------------------------------------------------------------------------
18 //
19 //  Based on the Adler-32 algorithm as described in RFC-1950.
20 //
21 //------------------------------------------------------------------------
22 
23 #ifndef __EPI_CRC_H__
24 #define __EPI_CRC_H__
25 
26 namespace epi
27 {
28 	class crc32_c
29 	{
30 		/* sealed */
31 
32 	public:
33 		u32_t crc;
34 
crc32_c()35 		crc32_c()  { Reset(); }
crc32_c(const crc32_c & rhs)36 		crc32_c(const crc32_c &rhs) { crc = rhs.crc; }
~crc32_c()37 		~crc32_c() { }
38 
39 		crc32_c& operator= (const crc32_c &rhs) { crc = rhs.crc; return *this; }
40 
41 		crc32_c& operator+= (byte value);
42 		crc32_c& operator+= (s32_t value);
43 		crc32_c& operator+= (u32_t value);
44 		crc32_c& operator+= (float value);
45 
46 //		bool operator== (const crc32_c &rhs) const { return crc == rhs.crc; }
47 //		bool operator!= (const crc32_c &rhs) const { return crc != rhs.crc; }
48 
49 		crc32_c& AddBlock(const byte *data, int len);
50 		crc32_c& AddCStr(const char *str);
51 
Reset(void)52 		void Reset(void) { crc = 1; }
53 	};
54 };
55 #endif  /* __EPI_CRC_H__ */
56 
57 //--- editor settings ---
58 // vi:ts=4:sw=4:noexpandtab
59