...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/cstdint.hpp> // for boost::uintmax_t #include <cstddef> // for std::size_t namespace boost { template < std::size_t Bits, uintmax_t TruncPoly, uintmax_t InitRem, uintmax_t FinalXor, bool ReflectIn, bool ReflectRem > class crc_optimal; }
The boost::crc_optimal
class template acts as an unaugmented-CRC processor that can accept input at
the byte-level. It takes all the Rocksoft™ Model CRC Algorithm parameters
as template parameters. Like in crc_basic
,
the WIDTH stays as the first parameter and determines
the built-in unsigned integer type used for division registers. The other Rocksoft™
Model CRC Algorithm parameters move up to the template parameter field in the
same relative order they were in the crc_basic
constructor. (Some parameters have defaults.) Objects based from crc_optimal
can either be default-constructed,
giving it the same behavior as a crc_basic
object with the equivalent settings, or use one parameter, which overrides
the initial remainder value[3] without permanently affecting the initial-remainder attribute.
Besides template parameters and construction, crc_optimal
differs from crc_basic
interface-wise
by:
Adding five class-static immutable data members corresponding to the new template parameters.
Table 12.3. Additional RMCA Expressions in boost::crc_optimal
New Member |
Equivalent |
---|---|
|
|
|
|
|
|
|
|
|
|
process_bit
and process_bits
member
functions.
operator
()
member function. The single-argument
version forwards to process_byte
,
making it suitable to STL algorithms that take (and possibly return) function
objects[4]. The argument-less version forwards to checksum
,
making it suitable for STL algorithms that expect generator objects[5].
reset
member
functions into one. (It uses a single parameter that can have a default
argument).
The major difference between crc_basic
and crc_optimal
is the internals.
Objects from crc_basic
run
their CRC algorithm one bit at a time, no matter which unit is used as input.
Objects from crc_optimal
, when
WIDTH is at least CHAR_BIT
[6], use a byte-indexed table-driven CRC algorithm which is a lot faster than processing individual bits.
Since all of the parameters are specified at compile-time, you cannot reuse a single computer object for separate runs with differing parameters. The type uses the automatically-defined copy/move/assign and destruction routines.