Most enums were replaced with constants, according to MISRA

This commit is contained in:
Pavel Kirienko
2014-04-19 15:13:10 +04:00
parent ace2cf9d0e
commit dfe3b4511e
21 changed files with 95 additions and 55 deletions
+4 -4
View File
@@ -29,7 +29,7 @@ class UAVCAN_EXPORT DataTypeID
uint16_t value_;
public:
enum { Max = 1023 };
static const uint16_t Max = 1023;
DataTypeID() : value_(0xFFFF) { }
@@ -69,13 +69,13 @@ class UAVCAN_EXPORT DataTypeSignatureCRC
public:
static DataTypeSignatureCRC extend(uint64_t crc);
DataTypeSignatureCRC() : crc_(0xFFFFFFFFFFFFFFFF) { }
DataTypeSignatureCRC() : crc_(0xFFFFFFFFFFFFFFFFULL) { }
void add(uint8_t byte);
void add(const uint8_t* bytes, unsigned len);
uint64_t get() const { return crc_ ^ 0xFFFFFFFFFFFFFFFF; }
uint64_t get() const { return crc_ ^ 0xFFFFFFFFFFFFFFFFULL; }
};
@@ -108,7 +108,7 @@ class UAVCAN_EXPORT DataTypeDescriptor
const char* full_name_;
public:
enum { MaxFullNameLen = 80 };
static const unsigned MaxFullNameLen = 80;
DataTypeDescriptor()
: kind_(DataTypeKind(0))
+1 -4
View File
@@ -95,11 +95,8 @@ struct UAVCAN_EXPORT CanSelectMasks
{ }
};
enum
{
CanIOFlagLoopback = 1 ///< Send the frame back to RX with true TX timestamps
};
typedef uint16_t CanIOFlags;
static const CanIOFlags CanIOFlagLoopback = 1; ///< Send the frame back to RX with true TX timestamps
/**
* Single non-blocking CAN interface.
+2 -3
View File
@@ -9,14 +9,13 @@
namespace uavcan
{
namespace
{
/**
* Common error codes.
* Functions that return signed integers may also return inverted error codes,
* i.e. returned value should be inverted back to get the actual error code.
*/
namespace
{
const int16_t ErrOk = 0;
const int16_t ErrFailure = 1;
const int16_t ErrInvalidParam = 2;
+4 -4
View File
@@ -91,15 +91,15 @@ namespace uavcan
* fit this size; otherwise compilation fails.
*/
#if UAVCAN_MEM_POOL_BLOCK_SIZE
enum { MemPoolBlockSize = UAVCAN_MEM_POOL_BLOCK_SIZE };
static const unsigned MemPoolBlockSize = UAVCAN_MEM_POOL_BLOCK_SIZE;
#else
enum { MemPoolBlockSize = 64 };
static const unsigned MemPoolBlockSize = 64;
#endif
#ifdef __BIGGEST_ALIGNMENT__
enum { MemPoolAlignment = __BIGGEST_ALIGNMENT__ };
static const unsigned MemPoolAlignment = __BIGGEST_ALIGNMENT__;
#else
enum { MemPoolAlignment = 16 };
static const unsigned MemPoolAlignment = 16;
#endif
typedef char _alignment_check_for_MEM_POOL_BLOCK_SIZE[((MemPoolBlockSize & (MemPoolAlignment - 1)) == 0) ? 1 : -1];
+2 -2
View File
@@ -46,7 +46,7 @@ class UAVCAN_EXPORT MapBase : Noncopyable
KVGroup()
{
StaticAssert<(NumKV > 0)>::check();
StaticAssert<(static_cast<unsigned>(NumKV) > 0)>::check();
IsDynamicallyAllocatable<KVGroup>::check();
}
@@ -72,7 +72,7 @@ class UAVCAN_EXPORT MapBase : Noncopyable
KVPair* find(const Key& key)
{
for (int i = 0; i < NumKV; i++)
for (unsigned i = 0; i < static_cast<unsigned>(NumKV); i++)
{
if (kvs[i].match(key))
{
+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;
@@ -36,7 +36,7 @@ public:
};
private:
enum { TimerPeriodMs100 = 5 };
static const unsigned TimerPeriodMs100 = 5;
typedef MethodBinder<NodeStatusMonitor*,
void (NodeStatusMonitor::*)(const ReceivedDataStructure<protocol::NodeStatus>&)>
+8 -2
View File
@@ -83,7 +83,7 @@ public:
return *static_cast<D*>(this);
}
enum { StringBufSize = 32 };
static const unsigned StringBufSize = 32;
void toString(char buf[StringBufSize]) const;
#if UAVCAN_TOSTRING
std::string toString() const;
@@ -169,7 +169,7 @@ public:
return *static_cast<T*>(this);
}
enum { StringBufSize = 32 };
static const unsigned StringBufSize = 32;
void toString(char buf[StringBufSize]) const;
#if UAVCAN_TOSTRING
std::string toString() const;
@@ -214,6 +214,12 @@ public:
// ----------------------------------------------------------------------------
template <typename D>
const unsigned DurationBase<D>::StringBufSize;
template <typename T, typename D>
const unsigned TimeBase<T, D>::StringBufSize;
template <typename D>
void DurationBase<D>::toString(char buf[StringBufSize]) const
{
@@ -56,7 +56,7 @@ public:
, qos(uint8_t(qos))
, flags(flags)
{
assert(qos == Volatile || qos == Persistent);
assert((qos == Volatile) || (qos == Persistent));
IsDynamicallyAllocatable<Entry>::check();
}
@@ -11,9 +11,9 @@
namespace uavcan
{
enum { MaxTransferPayloadLen = 439 }; ///< According to the standard
static const unsigned MaxTransferPayloadLen = 439; ///< According to the RFC
enum { MaxSingleFrameTransferPayloadLen = 7 };
static const unsigned MaxSingleFrameTransferPayloadLen = 7;
enum TransferType
{
@@ -30,8 +30,8 @@ class UAVCAN_EXPORT TransferID
uint8_t value_;
public:
enum { BitLen = 3 };
enum { Max = (1 << BitLen) - 1 };
static const uint8_t BitLen = 3U;
static const uint8_t Max = (1U << BitLen) - 1U;
TransferID()
: value_(0)
@@ -67,17 +67,13 @@ public:
class UAVCAN_EXPORT NodeID
{
enum
{
ValueBroadcast = 0,
ValueInvalid = 0xFF
};
static const uint8_t ValueBroadcast = 0;
static const uint8_t ValueInvalid = 0xFF;
uint8_t value_;
public:
enum { BitLen = 7 };
enum { Max = (1 << BitLen) - 1 };
static const uint8_t BitLen = 7U;
static const uint8_t Max = (1U << BitLen) - 1U;
static const NodeID Broadcast;
NodeID() : value_(ValueInvalid) { }
@@ -94,7 +94,7 @@ class UAVCAN_EXPORT DynamicTransferBufferManagerEntry
struct Block : LinkedListNode<Block>
{
enum { Size = MemPoolBlockSize - sizeof(LinkedListNode<Block>) };
uint8_t data[Size];
uint8_t data[static_cast<unsigned>(Size)];
static Block* instantiate(IPoolAllocator& allocator);
static void destroy(Block*& obj, IPoolAllocator& allocator);
@@ -31,7 +31,7 @@ public:
private:
enum TidRelation { TidSame, TidRepeat, TidFuture };
enum { IfaceIndexNotSet = 0xFF };
static const uint8_t IfaceIndexNotSet = 0xFF;
MonotonicTime prev_transfer_ts_;
MonotonicTime this_transfer_ts_;