source: orange/source/include/crc.h @ 6531:57bdc92cd8e9

Revision 6531:57bdc92cd8e9, 1.5 KB checked in by janezd <janez.demsar@…>, 4 years ago (diff)
  • changed licenses to GPL 3.0
Line 
1/*
2    This file is part of Orange.
3   
4    Copyright 1996-2010 Faculty of Computer and Information Science, University of Ljubljana
5    Contact: janez.demsar@fri.uni-lj.si
6
7    Orange is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11
12    Orange 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    You should have received a copy of the GNU General Public License
18    along with Orange.  If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef __CRC_H
22#define __CRC_H
23
24extern unsigned long crc_table[256];
25
26#define INIT_CRC(x) (x) = 0xffffffff
27#define FINISH_CRC(x) (x) = (x) ^ 0xffffffff
28
29#define ADD_CRC \
30  for(unsigned char const *b = (unsigned char const *)(&data), *e = b + sizeof(data); \
31      b != e; \
32      crc = (crc >> 8) ^ crc_table[(crc & 0xFF) ^ *(b++)]); \
33
34inline void add_CRC(const unsigned long data, unsigned long &crc)
35{ ADD_CRC }
36
37inline void add_CRC(const float data, unsigned long &crc)
38{ ADD_CRC }
39
40inline void add_CRC(const unsigned char c, unsigned long &crc)
41{ crc = (crc >> 8) ^ crc_table[(crc & 0xFF) ^ c]; }
42
43inline void add_CRC(const char *c, unsigned long &crc)
44{
45  for(; *c; add_CRC((unsigned char)*c++, crc));
46  add_CRC((unsigned char)0, crc);
47}
48
49#endif
Note: See TracBrowser for help on using the repository browser.