Most enums were replaced with constants, according to MISRA

This commit is contained in:
Pavel Kirienko
2014-04-19 15:16:10 +04:00
parent ace2cf9d0e
commit dfe3b4511e
21 changed files with 95 additions and 55 deletions
+13 -4
View File
@@ -344,7 +344,7 @@ class UAVCAN_EXPORT Array : public ArrayImpl<T, ArrayMode, MaxSize_>
void packSquareMatrixImpl(const InputIter src_row_major)
{
StaticAssert<IsDynamic>::check();
enum { Width = CompileTimeIntSqrt<MaxSize>::Result };
const unsigned Width = CompileTimeIntSqrt<MaxSize>::Result;
bool all_nans = true;
bool scalar_matrix = true;
@@ -409,7 +409,7 @@ class UAVCAN_EXPORT Array : public ArrayImpl<T, ArrayMode, MaxSize_>
void unpackSquareMatrixImpl(OutputIter it) const
{
StaticAssert<IsDynamic>::check();
enum { Width = CompileTimeIntSqrt<MaxSize>::Result };
const unsigned Width = CompileTimeIntSqrt<MaxSize>::Result;
/*
* Unpacking as follows:
* - Array of length 1 will be unpacked to scalar matrix
@@ -453,8 +453,17 @@ public:
enum { IsDynamic = ArrayMode == ArrayModeDynamic };
enum { MaxSize = MaxSize_ };
enum { MinBitLen = IsDynamic ? 0 : (RawValueType::MinBitLen * MaxSize) };
enum { MaxBitLen = Base::SizeBitLen + RawValueType::MaxBitLen * MaxSize };
enum
{
MinBitLen = (IsDynamic == 0)
? (static_cast<unsigned>(RawValueType::MinBitLen) * static_cast<unsigned>(MaxSize))
: 0
};
enum
{
MaxBitLen = static_cast<unsigned>(Base::SizeBitLen) +
static_cast<unsigned>(RawValueType::MaxBitLen) * static_cast<unsigned>(MaxSize)
};
static int encode(const SelfType& array, ScalarCodec& codec, const TailArrayOptimizationMode tao_mode)
{
@@ -17,7 +17,7 @@ void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, uns
class UAVCAN_EXPORT BitStream
{
enum { MaxBytesPerRW = 16 };
static const unsigned MaxBytesPerRW = 16;
ITransferBuffer& buf_;
int bit_offset_;
@@ -33,7 +33,7 @@ class UAVCAN_EXPORT BitStream
}
public:
enum { MaxBitsPerRW = MaxBytesPerRW * 8 };
static const unsigned MaxBitsPerRW = MaxBytesPerRW * 8;
enum
{
@@ -152,7 +152,7 @@ private:
static inline void saturate(StorageType& value)
{
using namespace std;
if (!IsExactRepresentation && isfinite(value))
if ((IsExactRepresentation == 0) && isfinite(value))
{
if (value > max())
{
@@ -172,7 +172,7 @@ private:
static inline void truncate(StorageType& value)
{
using namespace std;
if (!IsExactRepresentation && isfinite(value))
if ((IsExactRepresentation == 0) && isfinite(value))
{
if (value > max())
{
@@ -44,19 +44,29 @@ private:
static StorageType max()
{
StaticAssert<(sizeof(uintmax_t) >= 8)>::check();
return StorageType(IsSigned ? ((uintmax_t(1) << (BitLen - 1)) - 1) : ((uintmax_t(1) << BitLen) - 1));
if (IsSigned == 0)
{
return StorageType((uintmax_t(1) << static_cast<unsigned>(BitLen)) - 1U);
}
else
{
return StorageType((uintmax_t(1) << (static_cast<unsigned>(BitLen) - 1U)) - 1);
}
}
static UnsignedStorageType mask()
{
StaticAssert<(sizeof(uintmax_t) >= 8)>::check();
return UnsignedStorageType((uintmax_t(1) << BitLen) - 1);
StaticAssert<(sizeof(uintmax_t) >= 8U)>::check();
return UnsignedStorageType((uintmax_t(1) << static_cast<unsigned>(BitLen)) - 1U);
}
};
struct LimitsImpl64
{
static StorageType max() { return StorageType(IsSigned ? 0x7FFFFFFFFFFFFFFF : 0xFFFFFFFFFFFFFFFF); }
static UnsignedStorageType mask() { return 0xFFFFFFFFFFFFFFFF; }
static StorageType max()
{
return StorageType((IsSigned != 0) ? 0x7FFFFFFFFFFFFFFFLL : 0xFFFFFFFFFFFFFFFFULL);
}
static UnsignedStorageType mask() { return 0xFFFFFFFFFFFFFFFFULL; }
};
typedef typename Select<(BitLen == 64), LimitsImpl64, LimitsImplGeneric>::Result Limits;