Removed enable_tail_array_optimization and init()

This commit is contained in:
Pavel Kirienko 2014-02-22 17:08:38 +04:00
parent a58e8842e2
commit fb32aabb54
6 changed files with 22 additions and 16 deletions

View File

@ -9,6 +9,15 @@
namespace uavcan
{
/**
* UAVCAN can be explicitly told to ignore exceptions, or it can be detected automatically.
*/
#ifndef UAVCAN_EXCEPTIONS
# if defined(__EXCEPTIONS) || defined(_HAS_EXCEPTIONS)
# define UAVCAN_EXCEPTIONS 1
# endif
#endif
/**
* Should be OK for any target arch up to AMD64 and any compiler.
* The library leverages compile-time checks to ensure that all types that are subject to dynamic allocation

View File

@ -107,12 +107,10 @@ public:
using IEEE754Limits<BitLen>::max;
using IEEE754Limits<BitLen>::epsilon;
static StorageType init() { return 0.0; }
static std::float_round_style roundstyle() { return IEEE754Converter::roundstyle(); }
static int encode(StorageType value, ScalarCodec& codec, bool enable_tail_array_optimization = false)
static int encode(StorageType value, ScalarCodec& codec)
{
(void)enable_tail_array_optimization;
// cppcheck-suppress duplicateExpression
if (CastMode == CastModeSaturate)
saturate(value);
@ -121,9 +119,8 @@ public:
return codec.encode<BitLen>(IEEE754Converter::toIeee<BitLen>(value));
}
static int decode(StorageType& out_value, ScalarCodec& codec, bool enable_tail_array_optimization = false)
static int decode(StorageType& out_value, ScalarCodec& codec)
{
(void)enable_tail_array_optimization;
typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType ieee = 0;
const int res = codec.decode<BitLen>(ieee);
if (res <= 0)

View File

@ -77,11 +77,8 @@ public:
// cppcheck-suppress duplicateExpression
static StorageType min() { return Limits::min(); }
static StorageType init() { return 0; }
static int encode(StorageType value, ScalarCodec& codec, bool enable_tail_array_optimization = false)
static int encode(StorageType value, ScalarCodec& codec)
{
(void)enable_tail_array_optimization;
// cppcheck-suppress duplicateExpression
if (CastMode == CastModeSaturate)
saturate(value);
@ -90,9 +87,8 @@ public:
return codec.encode<BitLen>(value);
}
static int decode(StorageType& out_value, ScalarCodec& codec, bool enable_tail_array_optimization = false)
static int decode(StorageType& out_value, ScalarCodec& codec)
{
(void)enable_tail_array_optimization;
return codec.decode<BitLen>(out_value);
}
};

View File

@ -64,4 +64,11 @@ struct StaticIf<false, TrueType, FalseType>
};
template<bool> struct BooleanType { };
typedef BooleanType<true> TrueType;
typedef BooleanType<false> FalseType;
}
/// Ensure that conditional comilation macros are present
#include <uavcan/internal/impl_constants.hpp>

View File

@ -21,17 +21,14 @@ TEST(FloatSpec, Limits)
typedef FloatSpec<64, CastModeTruncate> F64T;
ASSERT_FALSE(F16S::IsExactRepresentation);
ASSERT_EQ(0, F16S::init());
ASSERT_FLOAT_EQ(65504.0, F16S::max());
ASSERT_FLOAT_EQ(9.77e-04, F16S::epsilon());
ASSERT_TRUE(F32T::IsExactRepresentation);
ASSERT_EQ(0, F32T::init());
ASSERT_FLOAT_EQ(std::numeric_limits<float>::max(), F32T::max());
ASSERT_FLOAT_EQ(std::numeric_limits<float>::epsilon(), F32T::epsilon());
ASSERT_TRUE(F64S::IsExactRepresentation);
ASSERT_EQ(0, F64S::init());
ASSERT_FLOAT_EQ(std::numeric_limits<double>::max(), F64S::max());
ASSERT_FLOAT_EQ(std::numeric_limits<double>::epsilon(), F64S::epsilon());
}
@ -125,7 +122,7 @@ TEST(FloatSpec, Basic)
#define CHECK(FloatType, expected_value) \
do { \
StorageType<FloatType>::Type var(FloatType::init()); \
StorageType<FloatType>::Type var = StorageType<FloatType>::Type(); \
ASSERT_EQ(1, FloatType::decode(var, sc_rd)); \
if (!isnan(expected_value)) \
ASSERT_FLOAT_EQ(expected_value, var); \

View File

@ -88,7 +88,7 @@ TEST(IntegerSpec, Basic)
#define CHECK(IntType, expected_value) \
do { \
StorageType<IntType>::Type var(IntType::init()); \
StorageType<IntType>::Type var = StorageType<IntType>::Type(); \
ASSERT_EQ(1, IntType::decode(var, sc_rd)); \
ASSERT_EQ(expected_value, var); \
} while (0)