m Add default value to BEInt<> Size template parameter

This commit is contained in:
Behdad Esfahbod 2020-06-29 01:24:02 -07:00
parent 2caae4a59a
commit e5b7bc424d
3 changed files with 10 additions and 10 deletions

View File

@ -53,7 +53,7 @@ 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> template <typename Type, unsigned int Size = sizeof (Type)>
struct IntType struct IntType
{ {
typedef Type type; typedef Type type;
@ -107,12 +107,12 @@ struct IntType
DEFINE_SIZE_STATIC (Size); DEFINE_SIZE_STATIC (Size);
}; };
typedef IntType<uint8_t, 1> HBUINT8; /* 8-bit unsigned integer. */ typedef IntType<uint8_t> HBUINT8; /* 8-bit unsigned integer. */
typedef IntType<int8_t, 1> HBINT8; /* 8-bit signed integer. */ typedef IntType<int8_t> HBINT8; /* 8-bit signed integer. */
typedef IntType<uint16_t, 2> HBUINT16; /* 16-bit unsigned integer. */ typedef IntType<uint16_t> HBUINT16; /* 16-bit unsigned integer. */
typedef IntType<int16_t, 2> HBINT16; /* 16-bit signed integer. */ typedef IntType<int16_t> HBINT16; /* 16-bit signed integer. */
typedef IntType<uint32_t, 4> HBUINT32; /* 32-bit unsigned integer. */ typedef IntType<uint32_t> HBUINT32; /* 32-bit unsigned integer. */
typedef IntType<int32_t, 4> HBINT32; /* 32-bit signed integer. */ typedef IntType<int32_t> HBINT32; /* 32-bit signed integer. */
/* Note: we cannot defined a signed HBINT24 because there's no corresponding C type. /* Note: we cannot defined a signed HBINT24 because there's no corresponding C type.
* Works for unsigned, but not signed, since we rely on compiler for sign-extension. */ * Works for unsigned, but not signed, since we rely on compiler for sign-extension. */
typedef IntType<uint32_t, 3> HBUINT24; /* 24-bit unsigned integer. */ typedef IntType<uint32_t, 3> HBUINT24; /* 24-bit unsigned integer. */

View File

@ -524,7 +524,7 @@ struct hb_serialize_context_t
template <typename T> template <typename T>
void assign_offset (const object_t* parent, const object_t::link_t &link, unsigned offset) void assign_offset (const object_t* parent, const object_t::link_t &link, unsigned offset)
{ {
auto &off = * ((BEInt<T, sizeof (T)> *) (parent->head + link.position)); auto &off = * ((BEInt<T> *) (parent->head + link.position));
assert (0 == off); assert (0 == off);
check_assign (off, offset); check_assign (off, offset);
} }

View File

@ -464,10 +464,10 @@ 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); }
/* /*
* Big-endian integers. Here because fundamental. * Big-endian integers.
*/ */
template <typename Type, int Bytes> 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>