Changed to stdint.h, add functions return void.

This commit is contained in:
jwellbelove 2014-12-08 20:11:14 +00:00
parent 5e11ee1c46
commit 813fa87c45
12 changed files with 55 additions and 108 deletions

View File

@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include <cstdint>
#include <stdint.h>
namespace etl
{

22
crc16.h
View File

@ -29,13 +29,13 @@ SOFTWARE.
#ifndef __ETL_CRC16__
#define __ETL_CRC16__
#include <cstdint>
#include <stdint.h>
#include "static_assert.h"
#include "type_traits.h"
#include "endian.h"
///\defgroup crc16 Sixteen bit CRC calculation
///\defgroup crc16 16 bit CRC calculation
///\ingroup crc
namespace etl
@ -48,6 +48,7 @@ namespace etl
//***************************************************************************
/// Calculates CRC16 using polynomial 0x8005.
///\tparam ENDIANNESS The endianness of the calculation for input types larger than uint8_t. Default = endian::little.
/// \ingroup crc16
//***************************************************************************
template <const int ENDIANNESS = endian::little>
@ -69,7 +70,6 @@ namespace etl
/// Constructor from range.
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
crc16(TIterator begin, const TIterator end)
@ -88,12 +88,11 @@ namespace etl
//*************************************************************************
/// \param value The value to add to the CRC.
/// \return The CRC result.
//*************************************************************************
template<typename TValue>
value_type add(TValue value)
void add(TValue value)
{
static_assert(is_integral<TValue>::value, "Non-integral parameter");
STATIC_ASSERT(is_integral<TValue>::value, "Non-integral parameter");
if (ENDIANNESS == endian::little)
{
@ -109,36 +108,29 @@ namespace etl
add(uint8_t((value >> (i * 8)) & 0xFF));
}
}
return crc;
}
//*************************************************************************
/// \param value The uint8_t to add to the CRC.
/// \return The CRC result.
//*************************************************************************
value_type add(uint8_t value)
void add(uint8_t value)
{
crc = (crc >> 8) ^ CRC16[(crc ^ value) & 0xFF];
return crc;
}
//*************************************************************************
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
value_type add(TIterator begin, const TIterator end)
void add(TIterator begin, const TIterator end)
{
while (begin != end)
{
add(*begin);
++begin;
}
return crc;
}
//*************************************************************************

View File

@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include <cstdint>
#include <stdint.h>
namespace etl
{

View File

@ -29,13 +29,13 @@ SOFTWARE.
#ifndef __ETL_CRC16_CCITT__
#define __ETL_CRC16_CCITT__
#include <cstdint>
#include <stdint.h>
#include "static_assert.h"
#include "type_traits.h"
#include "endian.h"
///\defgroup crc16_ccitt Sixteen bit CRC CCITT calculation
///\defgroup crc16_ccitt 16 bit CRC CCITT calculation
///\ingroup crc
namespace etl
@ -48,6 +48,7 @@ namespace etl
//***************************************************************************
/// Calculates CRC-CCITT using polynomial 0x1021
///\tparam ENDIANNESS The endianness of the calculation for input types larger than uint8_t. Default = endian::little.
/// \ingroup crc16_ccitt
//***************************************************************************
template <const int ENDIANNESS = endian::little>
@ -69,7 +70,6 @@ namespace etl
/// Constructor from range.
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
crc16_ccitt(TIterator begin, const TIterator end)
@ -88,12 +88,11 @@ namespace etl
//*************************************************************************
/// \param value The value to add to the CRC.
/// \return The CRC result.
//*************************************************************************
template<typename TValue>
value_type add(TValue value)
void add(TValue value)
{
static_assert(is_integral<TValue>::value, "Non-integral parameter");
STATIC_ASSERT(is_integral<TValue>::value, "Non-integral parameter");
if (ENDIANNESS == endian::little)
{
@ -109,36 +108,28 @@ namespace etl
add(uint8_t((value >> (i * 8)) & 0xFF));
}
}
return crc;
}
//*************************************************************************
/// \param value The uint8_t to add to the CRC.
/// \return The CRC result.
//*************************************************************************
value_type add(uint8_t value)
void add(uint8_t value)
{
crc = (crc << 8) ^ CRC_CCITT[((crc >> 8) ^ value) & 0xFF];
return crc;
}
//*************************************************************************
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
value_type add(TIterator begin, const TIterator end)
void add(TIterator begin, const TIterator end)
{
while (begin != end)
{
add(*begin);
++begin;
}
return crc;
}
//*************************************************************************

View File

@ -26,13 +26,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include <cstdint>
#include <stdint.h>
namespace etl
{
//***************************************************************************
/// CRC Kermit table
/// \ingroup crc
/// \ingroup crc16_kermit
//***************************************************************************
extern const uint16_t CRC_KERMIT[] =
{

View File

@ -29,13 +29,13 @@ SOFTWARE.
#ifndef __etl_crc16_kermit__
#define __etl_crc16_kermit__
#include <cstdint>
#include <stdint.h>
#include "static_assert.h"
#include "type_traits.h"
#include "endian.h"
///\defgroup crc16_kermit Sixteen bit CRC Kermit calculation
///\defgroup crc16_kermit 16 bit CRC Kermit calculation
///\ingroup crc
namespace etl
@ -48,6 +48,7 @@ namespace etl
//***************************************************************************
/// Calculates CRC-Kermit using polynomial 0x1021
///\tparam ENDIANNESS The endianness of the calculation for input types larger than uint8_t. Default = endian::little.
/// \ingroup crc16_kermit
//***************************************************************************
template <const int ENDIANNESS = endian::little>
@ -69,7 +70,6 @@ namespace etl
/// Constructor from range.
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
crc16_kermit(TIterator begin, const TIterator end)
@ -88,12 +88,11 @@ namespace etl
//*************************************************************************
/// \param value The value to add to the CRC.
/// \return The CRC result.
//*************************************************************************
template<typename TValue>
value_type add(TValue value)
void add(TValue value)
{
static_assert(is_integral<TValue>::value, "Non-integral parameter");
STATIC_ASSERT(is_integral<TValue>::value, "Non-integral parameter");
if (ENDIANNESS == endian::little)
{
@ -109,36 +108,28 @@ namespace etl
add(uint8_t((value >> (i * 8)) & 0xFF));
}
}
return crc;
}
//*************************************************************************
/// \param value The uint8_t to add to the CRC.
/// \return The CRC result.
//*************************************************************************
value_type add(uint8_t value)
void add(uint8_t value)
{
crc = (crc >> 8) ^ CRC_KERMIT[(crc ^ value) & 0xFF];
return crc;
}
//*************************************************************************
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
value_type add(TIterator begin, const TIterator end)
void add(TIterator begin, const TIterator end)
{
while (begin != end)
{
add(*begin);
++begin;
}
return crc;
}
//*************************************************************************

View File

@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include <cstdint>
#include <stdint.h>
namespace etl
{

23
crc32.h
View File

@ -29,13 +29,13 @@ SOFTWARE.
#ifndef __ETL_CRC32__
#define __ETL_CRC32__
#include <cstdint>
#include <stdint.h>
#include "static_assert.h"
#include "type_traits.h"
#include "endian.h"
///\defgroup crc32 Thirty two bit CRC calculation
///\defgroup crc32 32 bit CRC calculation
///\ingroup crc
namespace etl
@ -48,6 +48,7 @@ namespace etl
//***************************************************************************
/// Calculates CRC32 using polynomial 0x04C11DB7.
///\tparam ENDIANNESS The endianness of the calculation for input types larger than uint8_t. Default = endian::little.
/// \ingroup crc32
//***************************************************************************
template <const int ENDIANNESS = endian::little>
@ -69,7 +70,6 @@ namespace etl
/// Constructor from range.
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
crc32(TIterator begin, const TIterator end)
@ -88,12 +88,11 @@ namespace etl
//*************************************************************************
/// \param value The value to add to the CRC.
/// \return The CRC result.
//*************************************************************************
template<typename TValue>
value_type add(TValue value)
void add(TValue value)
{
static_assert(is_integral<TValue>::value, "Non-integral parameter");
STATIC_ASSERT(is_integral<TValue>::value, "Non-integral parameter");
if (ENDIANNESS == endian::little)
{
@ -109,36 +108,28 @@ namespace etl
add(uint8_t((value >> (i * 8)) & 0xFF));
}
}
return crc;
}
//*************************************************************************
/// \param value The uint8_t to add to the CRC.
/// \return The CRC result.
//*************************************************************************
value_type add(uint8_t value)
void add(uint8_t value)
{
crc = (crc >> 8) ^ CRC32[(crc ^ value) & 0xFF];
return crc;
}
//*************************************************************************
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
value_type add(TIterator begin, const TIterator end)
void add(TIterator begin, const TIterator end)
{
while (begin != end)
{
add(*begin);
++begin;
}
return crc;
}
//*************************************************************************

View File

@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include <cstdint>
#include <stdint.h>
namespace etl
{

View File

@ -29,13 +29,13 @@ SOFTWARE.
#ifndef __ETL_CRC64_ECMA__
#define __ETL_CRC64_ECMA__
#include <cstdint>
#include <stdint.h>
#include "static_assert.h"
#include "type_traits.h"
#include "endian.h"
///\defgroup crc64_ecma Sixty four bit CRC ECMA calculation
///\defgroup crc64_ecma 64 bit CRC ECMA calculation
///\ingroup crc
namespace etl
@ -48,6 +48,7 @@ namespace etl
//***************************************************************************
/// Calculates CRC64-ECMA using polynomial 0x42F0E1EBA9EA3693.
///\tparam ENDIANNESS The endianness of the calculation for input types larger than uint8_t. Default = endian::little.
/// \ingroup crc64_ecma
//***************************************************************************
template <const int ENDIANNESS = endian::little>
@ -69,7 +70,6 @@ namespace etl
/// Constructor from range.
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
crc64_ecma(TIterator begin, const TIterator end)
@ -88,12 +88,11 @@ namespace etl
//*************************************************************************
/// \param value The value to add to the CRC.
/// \return The CRC result.
//*************************************************************************
template<typename TValue>
value_type add(TValue value)
void add(TValue value)
{
static_assert(is_integral<TValue>::value, "Non-integral parameter");
STATIC_ASSERT(is_integral<TValue>::value, "Non-integral parameter");
if (ENDIANNESS == endian::little)
{
@ -109,36 +108,28 @@ namespace etl
add(uint8_t((value >> (i * 8)) & 0xFF));
}
}
return crc;
}
//*************************************************************************
/// \param value The value to add to the CRC.
/// \return The CRC result.
//*************************************************************************
value_type add(uint8_t value)
void add(uint8_t value)
{
crc = (crc << 8) ^ CRC64_ECMA[((crc >> 56) ^ value) & 0xFF];
return crc;
}
//*************************************************************************
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
value_type add(TIterator begin, const TIterator end)
void add(TIterator begin, const TIterator end)
{
while (begin != end)
{
add(*begin);
++begin;
}
return crc;
}
//*************************************************************************

View File

@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include <cstdint>
#include <stdint.h>
namespace etl
{

View File

@ -29,13 +29,13 @@ SOFTWARE.
#ifndef __ETL_CRC8_CCITT__
#define __ETL_CRC8_CCITT__
#include <cstdint>
#include <stdint.h>
#include "static_assert.h"
#include "type_traits.h"
#include "endian.h"
///\defgroup crc8_ccitt Eight bit CRC calculation
///\defgroup crc8_ccitt 8 bit CRC calculation
///\ingroup crc
namespace etl
@ -48,6 +48,7 @@ namespace etl
//***************************************************************************
/// Calculates CRC8 CCITT using polynomial 0x07.
///\tparam ENDIANNESS The endianness of the calculation for input types larger than uint8_t. Default = endian::little.
/// \ingroup crc8_ccitt
//***************************************************************************
template <const int ENDIANNESS = endian::little>
@ -69,7 +70,6 @@ namespace etl
/// Constructor from range.
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
crc8_ccitt(TIterator begin, const TIterator end)
@ -88,12 +88,11 @@ namespace etl
//*************************************************************************
/// \param value The value to add to the CRC.
/// \return The CRC result.
//*************************************************************************
template<typename TValue>
value_type add(TValue value)
void add(TValue value)
{
static_assert(is_integral<TValue>::value, "Non-integral parameter");
STATIC_ASSERT(is_integral<TValue>::value, "Non-integral parameter");
if (ENDIANNESS == endian::little)
{
@ -109,35 +108,27 @@ namespace etl
add(uint8_t((value >> (i * 8)) & 0xFF));
}
}
return crc;
}
//*************************************************************************
/// \param value The char to add to the CRC.
/// \return The CRC result.
//*************************************************************************
value_type add(uint8_t value)
void add(uint8_t value)
{
crc = CRC8_CCITT[crc ^ value];
return crc;
}
//*************************************************************************
/// \param begin Start of the range.
/// \param end End of the range.
/// \return The CRC result.
//*************************************************************************
template<typename TIterator>
value_type add(TIterator begin, const TIterator end)
void add(TIterator begin, const TIterator end)
{
while (begin != end)
{
add(*begin++);
}
return crc;
}
//*************************************************************************