...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::crc_basic — Bitwise CRC computer.
// In header: <boost/crc.hpp> template<std::size_t Bits> class crc_basic { public: // types typedef boost::uint_t< Bits >::fast value_type; // construct/copy/destruct explicit crc_basic(value_type, value_type = 0, value_type = 0, bool = false, bool = false); // public member functions BOOST_STATIC_CONSTANT(std::size_t, bit_count = Bits); value_type get_truncated_polynominal() const; value_type get_initial_remainder() const; value_type get_final_xor_value() const; bool get_reflect_input() const; bool get_reflect_remainder() const; value_type get_interim_remainder() const; void reset(value_type); void reset(); void process_bit(bool); void process_bits(unsigned char, std::size_t); void process_byte(unsigned char); void process_block(void const *, void const *); void process_bytes(void const *, std::size_t); value_type checksum() const; };
Objects of this type compute the CRC checksum of submitted data, where said data can be entered piecemeal through several different kinds of groupings. Modulo2 polynomial division steps are always performed bitwise, without the use of precomputation tables. Said division uses the altered algorithm, so any data has to be unaugmented.
std::size_t Bits
The order of the modulo2 polynomial divisor. (Width from the RMCA)
crc_basic
public
construct/copy/destructexplicit crc_basic(value_type truncated_polynomial, value_type initial_remainder = 0, value_type final_xor_value = 0, bool reflect_input = false, bool reflect_remainder = false);Create a computer, separately listing each needed parameter.
Constructs a
object with at least the required parameters to a particular CRC formula to be processed upon receiving input.crc_basic
Parameters: 


Postconditions: 


Postconditions: 


Postconditions: 


Postconditions: 


Postconditions: 


Postconditions: 


Postconditions: 

crc_basic
public member functionsBOOST_STATIC_CONSTANT(std::size_t, bit_count = Bits);A copy of Bits provided for metaprogramming purposes.
value_type get_truncated_polynominal() const;Return the (truncated) polynomial divisor.
Returns a representation of the polynomial divisor. The value of the 2^{i} bit is the value of the coefficient of the polynomial's x^{i} term. The omitted bit for x^{(#bit_count)} term is always 1.
Returns: 
The bitpacked list of coefficients. If the bitlength of value_type exceeds #bit_count, the values of higherplaced bits should be ignored (even any for x^{(#bit_count)}) since they're unregulated. 
value_type get_initial_remainder() const;Return what the polynomial remainder was set to during construction.
Returns a representation of the polynomial remainder before any input has been submitted. The value of the 2^{i} bit is the value of the coefficient of the polynomial's x^{i} term.
Returns: 
The bitpacked list of coefficients. If the bitlength of value_type exceeds #bit_count, the values of higherplaced bits should be ignored since they're unregulated. 
value_type get_final_xor_value() const;Return the XORmask used during output processing.
Returns the mask to be used during creation of a checksum. The mask is used for an exclusiveor (XOR) operation applied bitwise to the interim remainder representation (after any reflection, if get_reflect_remainder() returns true
).
Returns: 
The bitmask. If the bitlength of value_type exceeds #bit_count, the values of higherplaced bits should be ignored since they're unregulated. 
bool get_reflect_input() const;Check if inputbytes will be reflected before processing.
Returns a whether or not a submitted byte will be "reflected" before it is used to update the interim remainder. Only the bytewise operations process_byte, process_block, and process_bytes are affected.
bool get_reflect_remainder() const;Check if the remainder will be reflected during output processing.
Indicates if the interim remainder will be "reflected" before it is passed to the XORmask stage when returning a checksum.
value_type get_interim_remainder() const;Return the remainder based from alreadyprocessed bits.
Returns a representation of the polynomial remainder after all the input submissions since construction or the last reset call. The value of the 2^{i} bit is the value of the coefficient of the polynomial's x^{i} term. If CRC processing gets interrupted here, retain the value returned, and use it to start up the next CRC computer where you left off (with reset(value_type) or construction). The next computer has to have its other parameters compatible with this computer.
Returns: 
The bitpacked list of coefficients. If the bitlength of value_type exceeds #bit_count, the values of higherplaced bits should be ignored since they're unregulated. No output processing (reflection or XOR mask) has been applied to the value. 
void reset(value_type new_rem);Change the interim remainder to a new value.
Changes the interim polynomial remainder to new_rem, purging any influence previously submitted input has had. The value of the 2^{i} bit is the value of the coefficient of the polynomial's x^{i} term.
Parameters: 


Postconditions: 


Postconditions: 

void reset();Change the interim remainder back to the initial value.
Changes the interim polynomial remainder to the initial remainder given during construction, purging any influence previously submitted input has had. The value of the 2^{i} bit is the value of the coefficient of the polynomial's x^{i} term.
Postconditions: 

Postconditions: 

void process_bit(bool bit);Submit a single bit for input processing.
Updates the interim remainder with a single alteredCRCdivision step.
Parameters: 


Postconditions: 
The interim remainder is updated though a modulo2 polynomial division, where the division steps are altered for unaugmented CRCs. 
void process_bits(unsigned char bits, std::size_t bit_length);Submit the lowest bit_length bits of a byte for input processing.
Updates the interim remainder with several alteredCRCdivision steps. Each bit is processed separately, starting from the one at the 2^{bit_length  1} place, then proceeding down to the lowestplaced bit. Any order imposed by this>get_reflect_input()
is ignored.
Parameters: 


Requires: 
0 < bit_length <= 

Postconditions: 
The interim remainder is updated though bit_length modulo2 polynomial divisions, where the division steps are altered for unaugmented CRCs. 
void process_byte(unsigned char byte);Submit a single byte for input processing.
Updates the interim remainder with a byte's worth of alteredCRCdivision steps. The bits within the byte are processed from the highest place down if this>get_reflect_input()
is false
, and lowest place up otherwise.
Parameters: 


Postconditions: 
The interim remainder is updated though 
void process_block(void const * bytes_begin, void const * bytes_end);Submit a memory block for input processing, iteratorpair style.
Updates the interim remainder with several bytes' worth of alteredCRCdivision steps. The bits within each byte are processed from the highest place down if this>get_reflect_input()
is false
, and lowest place up otherwise. The bytes themselves are processed starting from the one pointed by bytes_begin until bytes_end is reached through forward iteration, treating the two pointers as if they point to unsigned char
objects.
Parameters: 


Requires: 
bytes_end has to equal bytes_begin if the latter is 

Requires: 
bytes_end, if not equal to bytes_begin, has to point within or onebytepast the same buffer bytes_begin points into. 

Requires: 
bytes_end has to be reachable from bytes_begin through a finite number of forward bytepointer increments. 

Postconditions: 
The interim remainder is updated though 
void process_bytes(void const * buffer, std::size_t byte_count);Submit a memory block for input processing, pointerandsize style.
Updates the interim remainder with several bytes' worth of alteredCRCdivision steps. The bits within each byte are processed from the highest place down if this>get_reflect_input()
is false
, and lowest place up otherwise. The bytes themselves are processed starting from the one pointed by buffer, forwarditerated (as if the pointedto objects were of unsigned char
) until byte_count bytes are read.
Parameters: 


Requires: 
byte_count has to equal 0 if buffer is 

Requires: 
If buffer points within valid memory, then that block has to have at least byte_count more valid bytes allocated from that point. 

Postconditions: 
The interim remainder is updated though 
value_type checksum() const;Return the checksum of the alreadyprocessed bits.
Computes the checksum of all the submitted bits since construction or the last call to reset. The checksum will be the raw checksum, i.e. the (interim) remainder after all the modulo2 polynomial division, plus any output processing.
Note  

Since checksums are meant to be compared, any higherplaced bits (when the bitlength of value_type exceeds #bit_count) will be set to 0. 
Returns: 
