diff --git a/libuavcan/include/uavcan/internal/marshalling/cast_mode.hpp b/libuavcan/include/uavcan/internal/marshalling/cast_mode.hpp new file mode 100644 index 0000000000..dc70a31249 --- /dev/null +++ b/libuavcan/include/uavcan/internal/marshalling/cast_mode.hpp @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2014 Pavel Kirienko + */ + +#pragma once + +namespace uavcan +{ + +enum CastMode { CastModeSaturate, CastModeTruncate }; + +} diff --git a/libuavcan/include/uavcan/internal/marshalling/integer.hpp b/libuavcan/include/uavcan/internal/marshalling/integer_spec.hpp similarity index 93% rename from libuavcan/include/uavcan/internal/marshalling/integer.hpp rename to libuavcan/include/uavcan/internal/marshalling/integer_spec.hpp index fe168ab2a8..b0121ded64 100644 --- a/libuavcan/include/uavcan/internal/marshalling/integer.hpp +++ b/libuavcan/include/uavcan/internal/marshalling/integer_spec.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace uavcan { @@ -16,7 +16,7 @@ namespace uavcan enum Signedness { SignednessUnsigned, SignednessSigned }; template -class IntegerInfo +class IntegerSpec { enum { IsSigned = Signedness == SignednessSigned }; @@ -32,9 +32,9 @@ public: ErrorNoSuchInteger>::Result>::Result>::Result>::Result StorageType; private: - typedef typename IntegerInfo::StorageType UnsignedStorageType; + typedef typename IntegerSpec::StorageType UnsignedStorageType; - IntegerInfo() { } + IntegerSpec() { } struct ExactSizeLimits { @@ -98,6 +98,6 @@ public: }; template -class IntegerInfo<1, SignednessSigned, CastMode>; // Invalid instantiation +class IntegerSpec<1, SignednessSigned, CastMode>; // Invalid instantiation } diff --git a/libuavcan/include/uavcan/internal/marshalling/types.hpp b/libuavcan/include/uavcan/internal/marshalling/types.hpp index 0d172f8a14..cb9e42dc31 100644 --- a/libuavcan/include/uavcan/internal/marshalling/types.hpp +++ b/libuavcan/include/uavcan/internal/marshalling/types.hpp @@ -5,20 +5,24 @@ #pragma once #include -#include +#include namespace uavcan { -enum CastMode { CastModeSaturate, CastModeTruncate }; - template -struct AddStorageTypeImpl { typedef T StorageType; }; +struct StorageTypeImpl { typedef T StorageType; }; template -struct AddStorageTypeImpl::Type> { }; +struct StorageTypeImpl::Type> +{ + typedef typename T::StorageType Type; +}; template -struct AddStorageType : public T, public AddStorageTypeImpl { }; +struct StorageType : public T +{ + typedef typename StorageTypeImpl::Type Type; +}; } diff --git a/libuavcan/test/marshalling/integer.cpp b/libuavcan/test/marshalling/integer_spec.cpp similarity index 60% rename from libuavcan/test/marshalling/integer.cpp rename to libuavcan/test/marshalling/integer_spec.cpp index 9cf9133a61..26a7273155 100644 --- a/libuavcan/test/marshalling/integer.cpp +++ b/libuavcan/test/marshalling/integer_spec.cpp @@ -3,24 +3,25 @@ */ #include -#include +#include +#include TEST(Integer, Limits) { - using uavcan::IntegerInfo; + using uavcan::IntegerSpec; using uavcan::SignednessSigned; using uavcan::SignednessUnsigned; using uavcan::CastModeSaturate; using uavcan::CastModeTruncate; - typedef IntegerInfo<8, SignednessUnsigned, CastModeSaturate> UInt8; - typedef IntegerInfo<4, SignednessSigned, CastModeTruncate> SInt4; - typedef IntegerInfo<32, SignednessUnsigned, CastModeTruncate> UInt32; - typedef IntegerInfo<40, SignednessUnsigned, CastModeSaturate> UInt40; - typedef IntegerInfo<64, SignednessUnsigned, CastModeTruncate> UInt64; - typedef IntegerInfo<64, SignednessSigned, CastModeSaturate> SInt64; - typedef IntegerInfo<63, SignednessUnsigned, CastModeSaturate> UInt63; + typedef IntegerSpec<8, SignednessUnsigned, CastModeSaturate> UInt8; + typedef IntegerSpec<4, SignednessSigned, CastModeTruncate> SInt4; + typedef IntegerSpec<32, SignednessUnsigned, CastModeTruncate> UInt32; + typedef IntegerSpec<40, SignednessUnsigned, CastModeSaturate> UInt40; + typedef IntegerSpec<64, SignednessUnsigned, CastModeTruncate> UInt64; + typedef IntegerSpec<64, SignednessSigned, CastModeSaturate> SInt64; + typedef IntegerSpec<63, SignednessUnsigned, CastModeSaturate> UInt63; ASSERT_EQ(255, UInt8::max()); ASSERT_EQ(0, UInt8::min()); @@ -49,26 +50,26 @@ TEST(Integer, Limits) TEST(Integer, Basic) { - using uavcan::IntegerInfo; + using uavcan::IntegerSpec; using uavcan::SignednessSigned; using uavcan::SignednessUnsigned; using uavcan::CastModeSaturate; using uavcan::CastModeTruncate; - using uavcan::AddStorageType; + using uavcan::StorageType; uavcan::StaticTransferBuffer<100> buf; uavcan::BitStream bs_wr(buf); uavcan::ScalarCodec sc_wr(bs_wr); - typedef AddStorageType > UInt8S; - typedef AddStorageType > SInt4T; - typedef AddStorageType > UInt32T; - typedef AddStorageType > UInt40S; - typedef AddStorageType > UInt64T; - typedef AddStorageType > SInt58S; - typedef AddStorageType > UInt63S; - typedef AddStorageType > SInt10S; - typedef AddStorageType > UInt1S; + typedef IntegerSpec<8, SignednessUnsigned, CastModeSaturate> UInt8S; + typedef IntegerSpec<4, SignednessSigned, CastModeTruncate> SInt4T; + typedef IntegerSpec<32, SignednessUnsigned, CastModeTruncate> UInt32T; + typedef IntegerSpec<40, SignednessUnsigned, CastModeSaturate> UInt40S; + typedef IntegerSpec<64, SignednessUnsigned, CastModeTruncate> UInt64T; + typedef IntegerSpec<58, SignednessSigned, CastModeSaturate> SInt58S; + typedef IntegerSpec<63, SignednessUnsigned, CastModeSaturate> UInt63S; + typedef IntegerSpec<10, SignednessSigned, CastModeSaturate> SInt10S; + typedef IntegerSpec<1, SignednessUnsigned, CastModeSaturate> UInt1S; ASSERT_EQ(1, UInt8S::encode(UInt8S::StorageType(123), sc_wr)); ASSERT_EQ(1, SInt4T::encode(SInt4T::StorageType(-0x44), sc_wr)); @@ -85,10 +86,10 @@ TEST(Integer, Basic) uavcan::BitStream bs_rd(buf); uavcan::ScalarCodec sc_rd(bs_rd); -#define CHECK(Type, expected_value) \ +#define CHECK(IntType, expected_value) \ do { \ - Type::StorageType var(Type::init()); \ - ASSERT_EQ(1, Type::decode(var, sc_rd)); \ + StorageType::Type var(IntType::init()); \ + ASSERT_EQ(1, IntType::decode(var, sc_rd)); \ ASSERT_EQ(expected_value, var); \ } while (0) @@ -104,6 +105,6 @@ TEST(Integer, Basic) #undef CHECK - UInt1S::StorageType var; + StorageType::Type var; ASSERT_EQ(0, UInt1S::decode(var, sc_rd)); }