ShlubluLib  v0.5
ShlubluLib is a lightweight, modular, general purpose, open-source C++ library for Linux and Windows.
Public Member Functions | List of all members
shlublu::CRC< T > Class Template Reference

CRC accumulator. More...

#include <CRC.h>

Public Member Functions

 CRC ()
 Constructor. More...
 
template<typename P >
 CRC (P param)
 Constructor. More...
 
CRC< T > & accumulate (std::string const &str)
 Accumulates a string as a series of bytes. More...
 
CRC< T > & accumulate (char const *sz)
 Accumulates a C-string as a series of bytes. More...
 
template<typename P >
CRC< T > & accumulate (std::vector< P > const &v)
 Accumulates a vector as a series of contained objects. More...
 
template<typename P >
CRC< T > & accumulate (P value)
 Accumulates an arithmetic value. More...
 
CRC< T > & accumulate (char const *data, size_t offset, size_t length)
 Accumulates arbitraty bytes. More...
 
template<typename Iter >
CRC< T > & accumulate (const Iter first, const Iter last)
 Accumulates a range of elements. More...
 
get () const
 Returns the CRC value resulting from the accumulation. More...
 

Detailed Description

template<typename T>
class shlublu::CRC< T >

CRC accumulator.

Handled types are shlublu::crc32_t and shlublu::crc64_t, which are both unsigned integers. Shorthands for these types are shlublu::CRC32 and shlublu::CRC64.

Constructor & Destructor Documentation

◆ CRC() [1/2]

template<typename T >
shlublu::CRC< T >::CRC ( )
inline

Constructor.

Initializes to zero.

◆ CRC() [2/2]

template<typename T >
template<typename P >
shlublu::CRC< T >::CRC ( param)
inline

Constructor.

Accumulates the passed object.

Parameters
paraminitial object to accumulate.

Member Function Documentation

◆ accumulate() [1/6]

template<typename T >
CRC<T>& shlublu::CRC< T >::accumulate ( std::string const &  str)
inline

Accumulates a string as a series of bytes.

Parameters
strthe string to accumulate
Returns
a reference to this CRC object

◆ accumulate() [2/6]

template<typename T >
CRC<T>& shlublu::CRC< T >::accumulate ( char const *  sz)
inline

Accumulates a C-string as a series of bytes.

Parameters
szthe C-string to accumulate
Returns
a reference to this CRC object

◆ accumulate() [3/6]

template<typename T >
template<typename P >
CRC<T>& shlublu::CRC< T >::accumulate ( std::vector< P > const &  v)
inline

Accumulates a vector as a series of contained objects.

Parameters
vthe vector to accumulate
Returns
a reference to this CRC object

◆ accumulate() [4/6]

template<typename T >
template<typename P >
CRC<T>& shlublu::CRC< T >::accumulate ( value)
inline

Accumulates an arithmetic value.

Eligibility of the parameter is evaluated at compile-time by std::is_arithmetic<P>.

Parameters
valuethe value to accumulate
Returns
a reference to this CRC object
See also
std::is_arithmetic

◆ accumulate() [5/6]

template<typename T >
CRC<T>& shlublu::CRC< T >::accumulate ( char const *  data,
size_t  offset,
size_t  length 
)
inline

Accumulates arbitraty bytes.

This method can be used to accumulate an arbitrary object for which no other method applies. It is up to the developper to ensure such an accumulation is valid, consistent and repeatable.

Parameters
datadata as an array of char
offsetthe offset to start accumulation from
lengththe number of bytes to accumulate
Returns
a reference to this CRC object

Example

class X
{
public:
X(int a, double b) : mA(a), mB(b) {}
private:
int mA;
double mB;
};
const X x(42, 42.0);
CRC32 crc;
crc.accumulate(reinterpret_cast<char const*>(&x), 0, sizeof(int)); // accumulates x.mA

◆ accumulate() [6/6]

template<typename T >
template<typename Iter >
CRC<T>& shlublu::CRC< T >::accumulate ( const Iter  first,
const Iter  last 
)
inline

Accumulates a range of elements.

The range is delimited by [first,last).

Parameters
firstiterator that begins the range
lastiterator that ends the range
Returns
a reference to this CRC object

Example

const std::vector<int> v{ { 1, 2, 3, 4 } };
CRC64 crc;
crc.accumulate(v.begin(), v.end());

◆ get()

template<typename T >
T shlublu::CRC< T >::get ( ) const
inline

Returns the CRC value resulting from the accumulation.

Returns
the CRC value

The documentation for this class was generated from the following file:
shlublu::CRC64
CRC< crc64_t > CRC64
The 64 bits CRC value type.
Definition: CRC.h:246
shlublu::CRC32
CRC< crc32_t > CRC32
The 32 bits CRC accumulator.
Definition: CRC.h:241