mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-20 08:29:05 +08:00
IntegerSpec - boolean specialization
This commit is contained in:
parent
6f1ef63f56
commit
4cc8282e15
@ -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 <unsigned BitLen_, Signedness Signedness, CastMode CastMode>
|
||||
class UAVCAN_EXPORT IntegerSpec
|
||||
{
|
||||
@ -127,6 +131,43 @@ public:
|
||||
static void extendDataTypeSignature(DataTypeSignature&) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* Boolean specialization
|
||||
*/
|
||||
template <CastMode CastMode>
|
||||
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<BitLen>(value);
|
||||
}
|
||||
|
||||
static int decode(StorageType& out_value, ScalarCodec& codec, TailArrayOptimizationMode)
|
||||
{
|
||||
return codec.decode<BitLen>(out_value);
|
||||
}
|
||||
|
||||
static void extendDataTypeSignature(DataTypeSignature&) { }
|
||||
};
|
||||
|
||||
template <CastMode CastMode>
|
||||
class IntegerSpec<1, SignednessSigned, CastMode>; // Invalid instantiation
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user