From 4cc8282e155a856f487438d043926b68d812d9d8 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Fri, 10 Jul 2015 18:33:30 +0300 Subject: [PATCH] IntegerSpec - boolean specialization --- .../include/uavcan/marshal/integer_spec.hpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/libuavcan/include/uavcan/marshal/integer_spec.hpp b/libuavcan/include/uavcan/marshal/integer_spec.hpp index b7424310db..e5a87d7cb6 100644 --- a/libuavcan/include/uavcan/marshal/integer_spec.hpp +++ b/libuavcan/include/uavcan/marshal/integer_spec.hpp @@ -16,6 +16,10 @@ namespace uavcan enum Signedness { SignednessUnsigned, SignednessSigned }; +/** + * This template will be used for signed and unsigned integers more than 1 bit long. + * There are explicit specializations for booleans below. + */ template class UAVCAN_EXPORT IntegerSpec { @@ -127,6 +131,43 @@ public: static void extendDataTypeSignature(DataTypeSignature&) { } }; +/** + * Boolean specialization + */ +template +class UAVCAN_EXPORT IntegerSpec<1, SignednessUnsigned, CastMode> +{ +public: + enum { IsSigned = 0 }; + enum { BitLen = 1 }; + enum { MinBitLen = 1 }; + enum { MaxBitLen = 1 }; + enum { IsPrimitive = 1 }; + + typedef bool StorageType; + typedef bool UnsignedStorageType; + +private: + IntegerSpec(); + +public: + static StorageType max() { return true; } + static StorageType min() { return false; } + static UnsignedStorageType mask() { return true; } + + static int encode(StorageType value, ScalarCodec& codec, TailArrayOptimizationMode) + { + return codec.encode(value); + } + + static int decode(StorageType& out_value, ScalarCodec& codec, TailArrayOptimizationMode) + { + return codec.decode(out_value); + } + + static void extendDataTypeSignature(DataTypeSignature&) { } +}; + template class IntegerSpec<1, SignednessSigned, CastMode>; // Invalid instantiation