From c8c04266568d23e2efa12b7c073562ac7b5b0b2f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 4 Aug 2009 10:41:32 -0400 Subject: [HB] Merge more templates --- pango/opentype/hb-open-types-private.hh | 167 +++++++++++--------------------- 1 file changed, 55 insertions(+), 112 deletions(-) diff --git a/pango/opentype/hb-open-types-private.hh b/pango/opentype/hb-open-types-private.hh index 198c0ad2..82b4a061 100644 --- a/pango/opentype/hb-open-types-private.hh +++ b/pango/opentype/hb-open-types-private.hh @@ -282,48 +282,6 @@ typedef USHORT Offset; /* LongOffset to a table, same as uint32 (length = 32 bits), Null offset = 0x00000000 */ typedef ULONG LongOffset; -/* Template subclasses of Offset and LongOffset that do the dereferencing. Use: (this+memberName) */ - -template -struct OffsetTo : Offset -{ - inline const Type& operator() (const void *base) const - { - unsigned int offset = *this; - if (HB_UNLIKELY (!offset)) return Null(Type); - return *(const Type*)((const char *) base + offset); - } - - inline bool sanitize (SANITIZE_ARG_DEF, const void *base) { - if (!SANITIZE_OBJ (*this)) return false; - unsigned int offset = *this; - if (HB_UNLIKELY (!offset)) return true; - return SANITIZE (*(Type*)((char *) base + offset)) || NEUTER (*this, 0); - } -}; -template -inline const Type& operator + (const Base &base, OffsetTo offset) { return offset (base); } - -template -struct LongOffsetTo : LongOffset -{ - inline const Type& operator() (const void *base) const - { - unsigned int offset = *this; - if (HB_UNLIKELY (!offset)) return Null(Type); - return *(const Type*)((const char *) base + offset); - } - - inline bool sanitize (SANITIZE_ARG_DEF, const void *base) { - if (!SANITIZE (*this)) return false; - unsigned int offset = *this; - if (HB_UNLIKELY (!offset)) return true; - return SANITIZE (*(Type*)((char *) base + offset)) || NEUTER (*this, 0); - } -}; -template -inline const Type& operator + (const Base &base, LongOffsetTo offset) { return offset (base); } - /* CheckSum */ struct CheckSum : ULONG @@ -358,13 +316,44 @@ struct FixedVersion }; ASSERT_SIZE (FixedVersion, 4); + + /* - * Array Types + * Template subclasses of Offset and LongOffset that do the dereferencing. + * Use: (this+memberName) */ -/* An array with a USHORT number of elements. */ +template +struct GenericOffsetTo : OffsetType +{ + inline const Type& operator() (const void *base) const + { + unsigned int offset = *this; + if (HB_UNLIKELY (!offset)) return Null(Type); + return *(const Type*)((const char *) base + offset); + } + + inline bool sanitize (SANITIZE_ARG_DEF, const void *base) { + if (!SANITIZE_OBJ (*this)) return false; + unsigned int offset = *this; + if (HB_UNLIKELY (!offset)) return true; + return SANITIZE (*(Type*)((char *) base + offset)) || NEUTER (*this, 0); + } +}; +template +inline const Type& operator + (const Base &base, GenericOffsetTo offset) { return offset (base); } + template -struct ArrayOf +struct OffsetTo : GenericOffsetTo {}; + +template +struct LongOffsetTo : GenericOffsetTo {}; +/* + * Array Types + */ + +template +struct GenericArrayOf { inline const Type& operator [] (unsigned int i) const { @@ -391,10 +380,30 @@ struct ArrayOf return false; } - USHORT len; + LenType len; Type array[]; }; +/* An array with a USHORT number of elements. */ +template +struct ArrayOf : GenericArrayOf {}; + +/* An array with a ULONG number of elements. */ +template +struct LongArrayOf : GenericArrayOf {}; + +/* Array of Offset's */ +template +struct OffsetArrayOf : ArrayOf > {}; + +/* Array of LongOffset's */ +template +struct LongOffsetArrayOf : ArrayOf > {}; + +/* LongArray of LongOffset's */ +template +struct LongOffsetLongArrayOf : LongArrayOf > {}; + /* An array with a USHORT number of elements, * starting at second element. */ template @@ -417,76 +426,10 @@ struct HeadlessArrayOf return false; */ } - inline bool sanitize (SANITIZE_ARG_DEF, const char *base) { - if (!(SANITIZE (len) && SANITIZE_GET_SIZE())) return false; - unsigned int count = len; - for (unsigned int i = 0; i < count; i++) - if (!SANITIZE_THIS (array[i])) - return false; - } USHORT len; Type array[]; }; -/* An array with a ULONG number of elements. */ -template -struct LongArrayOf -{ - inline const Type& operator [] (unsigned int i) const - { - if (HB_UNLIKELY (i >= len)) return Null(Type); - return array[i]; - } - inline unsigned int get_size () const - { return sizeof (len) + len * sizeof (array[0]); } - - inline bool sanitize (SANITIZE_ARG_DEF) { - if (!(SANITIZE_SELF () && SANITIZE_GET_SIZE())) return false; - unsigned int count = len; - /* Note; for non-recursive types, this is not much needed - for (unsigned int i = 0; i < count; i++) - if (!SANITIZE (array[i])) - return false; - */ - } - inline bool sanitize (SANITIZE_ARG_DEF, const char *base) { - if (!(SANITIZE (len) && SANITIZE_GET_SIZE())) return false; - unsigned int count = len; - for (unsigned int i = 0; i < count; i++) - if (!SANITIZE_THIS (array[i])) - return false; - } - - ULONG len; - Type array[]; -}; - -/* Array of Offset's */ -template -struct OffsetArrayOf : ArrayOf > {}; - -/* Array of LongOffset's */ -template -struct LongOffsetArrayOf : ArrayOf > {}; - -/* LongArray of LongOffset's */ -template -struct LongOffsetLongArrayOf : LongArrayOf > {}; - - -/* An array type is one that contains a variable number of objects - * as its last item. An array object is extended with get_len() - * methods, as well as overloaded [] operator. */ -#define DEFINE_ARRAY_TYPE(Type, array, num) \ - DEFINE_INDEX_OPERATOR(Type, array, num) \ - DEFINE_LEN(Type, array, num) -#define DEFINE_INDEX_OPERATOR(Type, array, num) \ - inline const Type& operator[] (unsigned int i) const \ - { \ - if (HB_UNLIKELY (i >= num)) return Null(Type); \ - return array[i]; \ - } - #endif /* HB_OPEN_TYPES_PRIVATE_HH */ -- cgit v1.2.1