parent
8b2f9adf29
commit
cc16b26ef4
|
@ -83,7 +83,8 @@ static inline constexpr uint16_t hb_uint16_swap (uint16_t v)
|
||||||
static inline constexpr uint32_t hb_uint32_swap (uint32_t v)
|
static inline constexpr uint32_t hb_uint32_swap (uint32_t v)
|
||||||
{ return (hb_uint16_swap (v) << 16) | hb_uint16_swap (v >> 16); }
|
{ return (hb_uint16_swap (v) << 16) | hb_uint16_swap (v >> 16); }
|
||||||
|
|
||||||
template <typename Type, int Bytes = sizeof (Type)> struct BEInt;
|
template <typename Type, int Bytes = sizeof (Type)>
|
||||||
|
struct BEInt;
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
struct BEInt<Type, 1>
|
struct BEInt<Type, 1>
|
||||||
{
|
{
|
||||||
|
@ -124,14 +125,16 @@ struct BEInt<Type, 2>
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
struct BEInt<Type, 3>
|
struct BEInt<Type, 3>
|
||||||
{
|
{
|
||||||
|
static_assert (!hb_is_signed (Type), "");
|
||||||
public:
|
public:
|
||||||
BEInt () = default;
|
BEInt () = default;
|
||||||
constexpr BEInt (Type V) : v {uint8_t ((V >> 16) & 0xFF),
|
constexpr BEInt (Type V) : v {uint8_t ((V >> 16) & 0xFF),
|
||||||
uint8_t ((V >> 8) & 0xFF),
|
uint8_t ((V >> 8) & 0xFF),
|
||||||
uint8_t ((V ) & 0xFF)} {}
|
uint8_t ((V ) & 0xFF)} {}
|
||||||
|
|
||||||
constexpr operator Type () const { return (v[0] << 16)
|
constexpr operator Type () const { return (v[0] << 16)
|
||||||
+ (v[1] << 8)
|
+ (v[1] << 8)
|
||||||
+ (v[2] ); }
|
+ (v[2] ); }
|
||||||
private: uint8_t v[3];
|
private: uint8_t v[3];
|
||||||
};
|
};
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
|
|
|
@ -53,14 +53,18 @@ namespace OT {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Integer types in big-endian order and no alignment requirement */
|
/* Integer types in big-endian order and no alignment requirement */
|
||||||
template <typename Type, unsigned int Size = sizeof (Type)>
|
template <typename Type,
|
||||||
|
unsigned int Size = sizeof (Type),
|
||||||
|
typename Wide = hb_conditional<hb_is_signed (Type), signed, unsigned>>
|
||||||
struct IntType
|
struct IntType
|
||||||
{
|
{
|
||||||
typedef Type type;
|
typedef Type type;
|
||||||
typedef hb_conditional<hb_is_signed (Type), signed, unsigned> wide_type;
|
|
||||||
|
|
||||||
IntType& operator = (wide_type i) { v = i; return *this; }
|
IntType () = default;
|
||||||
operator wide_type () const { return v; }
|
explicit constexpr IntType (Wide V) : v {V} {}
|
||||||
|
IntType& operator = (Wide i) { v = i; return *this; }
|
||||||
|
operator Wide () const { return v; }
|
||||||
|
|
||||||
bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; }
|
bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; }
|
||||||
bool operator != (const IntType &o) const { return !(*this == o); }
|
bool operator != (const IntType &o) const { return !(*this == o); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue