diff options
author | Daniel Wilhelm <daniel@wili.li> | 2016-07-25 20:46:59 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2016-07-25 20:46:59 +0200 |
commit | 37dab163d3ee934a56f7d4ef2423c973f20cd27a (patch) | |
tree | 050c0b1c35de989fa397faa34f7ed2a1df543e51 /zen/crc.h | |
parent | 8.2 (diff) | |
download | FreeFileSync-37dab163d3ee934a56f7d4ef2423c973f20cd27a.tar.gz FreeFileSync-37dab163d3ee934a56f7d4ef2423c973f20cd27a.tar.bz2 FreeFileSync-37dab163d3ee934a56f7d4ef2423c973f20cd27a.zip |
8.3
Diffstat (limited to 'zen/crc.h')
-rw-r--r-- | zen/crc.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/zen/crc.h b/zen/crc.h new file mode 100644 index 00000000..0b22c7c3 --- /dev/null +++ b/zen/crc.h @@ -0,0 +1,48 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * +// ************************************************************************** + +#ifndef CRC_H_23489275827847235 +#define CRC_H_23489275827847235 + +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable: 4245) //'conversion' : conversion from 'int' to 'const boost::detail::mask_uint_t<0x08>::least', signed/unsigned mismatch +#endif +#include <boost/crc.hpp> +#ifdef _MSC_VER + #pragma warning(pop) +#endif + + +namespace zen +{ +template <class ByteIterator> inline +uint16_t getCrc16(ByteIterator first, ByteIterator last) +{ + static_assert(sizeof(typename std::iterator_traits<ByteIterator>::value_type) == 1, ""); + boost::crc_16_type result; + if (first != last) + result.process_bytes(&*first, last - first); + auto rv = result.checksum(); + static_assert(sizeof(rv) == sizeof(uint16_t), ""); + return rv; +} + + +template <class ByteIterator> inline +uint32_t getCrc32(ByteIterator first, ByteIterator last) +{ + static_assert(sizeof(typename std::iterator_traits<ByteIterator>::value_type) == 1, ""); + boost::crc_32_type result; + if (first != last) + result.process_bytes(&*first, last - first); + auto rv = result.checksum(); + static_assert(sizeof(rv) == sizeof(uint32_t), ""); + return rv; +} +} + +#endif //CRC_H_23489275827847235 |