mirror of
https://github.com/TomHarte/CLK.git
synced 2024-09-29 16:55:59 +00:00
Better templates the CRC generator.
This commit is contained in:
parent
5975fc8e63
commit
561e149058
@ -66,9 +66,23 @@ template <typename T, T reset_value, T xor_output, bool reflect_input, bool refl
|
|||||||
[add all data from @c data]
|
[add all data from @c data]
|
||||||
get_value()
|
get_value()
|
||||||
*/
|
*/
|
||||||
T compute_crc(const std::vector<uint8_t> &data) {
|
template <typename Collection> T compute_crc(const Collection &data) {
|
||||||
|
return compute_crc(data.begin(), data.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
A compound for:
|
||||||
|
|
||||||
|
reset()
|
||||||
|
[add all data from @c begin to @c end]
|
||||||
|
get_value()
|
||||||
|
*/
|
||||||
|
template <typename Iterator> T compute_crc(Iterator begin, Iterator end) {
|
||||||
reset();
|
reset();
|
||||||
for(const auto &byte: data) add(byte);
|
while(begin != end) {
|
||||||
|
add(*begin);
|
||||||
|
++begin;
|
||||||
|
}
|
||||||
return get_value();
|
return get_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user