source: orange/source/include/crc.h @ 10591:1a543c7924ef

Revision 10591:1a543c7924ef, 1.6 KB checked in by Janez Demšar <janez.demsar@…>, 2 years ago (diff)

Added add_CRC(const int) to remove casting when computing a checksum for TExample

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 int data, unsigned long &crc)
35{ ADD_CRC }
36
37inline void add_CRC(const unsigned long data, unsigned long &crc)
38{ ADD_CRC }
39
40inline void add_CRC(const float data, unsigned long &crc)
41{ ADD_CRC }
42
43inline void add_CRC(const unsigned char c, unsigned long &crc)
44{ crc = (crc >> 8) ^ crc_table[(crc & 0xFF) ^ c]; }
45
46inline void add_CRC(const char *c, unsigned long &crc)
47{
48  for(; *c; add_CRC((unsigned char)*c++, crc));
49  add_CRC((unsigned char)0, crc);
50}
51
52#endif
Note: See TracBrowser for help on using the repository browser.