Further cleanup of DEFINE_SIZE

This commit is contained in:
Behdad Esfahbod 2010-05-10 17:28:16 -04:00
parent 0abcc3b48c
commit bea34c7cbb
7 changed files with 37 additions and 43 deletions

View File

@ -140,7 +140,7 @@ struct TTCHeaderVersion1
table; /* Array of offsets to the OffsetTable for each font table; /* Array of offsets to the OffsetTable for each font
* from the beginning of the file */ * from the beginning of the file */
public: public:
DEFINE_SIZE_STATIC (12); DEFINE_SIZE_VAR (12, LongOffset);
}; };
struct TTCHeader struct TTCHeader

View File

@ -105,8 +105,7 @@ inline Type& StructAfter(TObject &X)
#define VAR 1 #define VAR 1
#define VAR0 (VAR+0) #define VAR0 (VAR+0)
#define DEFINE_SIZE_VAR0(size) \ #define DEFINE_SIZE_MIN(size) \
_DEFINE_SIZE_ASSERTION (size); \
static const unsigned int min_size = (size) static const unsigned int min_size = (size)
#define DEFINE_SIZE_VAR(size, _var_type) \ #define DEFINE_SIZE_VAR(size, _var_type) \
@ -140,7 +139,7 @@ template <> \
inline const Type& Null<Type> () { \ inline const Type& Null<Type> () { \
return *CastP<Type> (_Null##Type); \ return *CastP<Type> (_Null##Type); \
} /* The following line really exists such that we end in a place needing semicolon */ \ } /* The following line really exists such that we end in a place needing semicolon */ \
ASSERT_STATIC (sizeof (Type) + 1 <= sizeof (_Null##Type)) ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type))
/* Accessor macro. */ /* Accessor macro. */
#define Null(Type) Null<Type>() #define Null(Type) Null<Type>()
@ -590,9 +589,10 @@ struct GenericArrayOf
public: public:
LenType len; LenType len;
/*Type array[VAR];*/ private:
Type arrayX[VAR];
public: public:
DEFINE_SIZE_VAR0 (sizeof (LenType)); DEFINE_SIZE_VAR (sizeof (LenType), Type);
}; };
/* An array with a USHORT number of elements. */ /* An array with a USHORT number of elements. */

View File

@ -177,7 +177,7 @@ struct LangSys
* = 0xFFFF */ * = 0xFFFF */
IndexArray featureIndex; /* Array of indices into the FeatureList */ IndexArray featureIndex; /* Array of indices into the FeatureList */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, USHORT);
}; };
DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF");
@ -217,7 +217,7 @@ struct Script
langSys; /* Array of LangSysRecords--listed langSys; /* Array of LangSysRecords--listed
* alphabetically by LangSysTag */ * alphabetically by LangSysTag */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_VAR (4, Record<LangSys>);
}; };
typedef RecordListOf<Script> ScriptList; typedef RecordListOf<Script> ScriptList;
@ -248,7 +248,7 @@ struct Feature
* if not required */ * if not required */
IndexArray lookupIndex; /* Array of LookupList indices */ IndexArray lookupIndex; /* Array of LookupList indices */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_VAR (4, USHORT);
}; };
typedef RecordListOf<Feature> FeatureList; typedef RecordListOf<Feature> FeatureList;
@ -307,7 +307,7 @@ struct Lookup
* structure. This field is only present if bit * structure. This field is only present if bit
* UseMarkFilteringSet of lookup flags is set. */ * UseMarkFilteringSet of lookup flags is set. */
public: public:
DEFINE_SIZE_VAR (6, USHORT); DEFINE_SIZE_VAR2 (6, Offset, USHORT);
}; };
typedef OffsetListOf<Lookup> LookupList; typedef OffsetListOf<Lookup> LookupList;
@ -346,7 +346,7 @@ struct CoverageFormat1
ArrayOf<GlyphID> ArrayOf<GlyphID>
glyphArray; /* Array of GlyphIDs--in numerical order */ glyphArray; /* Array of GlyphIDs--in numerical order */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_VAR (4, GlyphID);
}; };
struct CoverageRangeRecord struct CoverageRangeRecord
@ -407,7 +407,7 @@ struct CoverageFormat2
* Start GlyphID. rangeCount entries * Start GlyphID. rangeCount entries
* long */ * long */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_VAR (4, CoverageRangeRecord);
}; };
struct Coverage struct Coverage
@ -469,7 +469,7 @@ struct ClassDefFormat1
ArrayOf<USHORT> ArrayOf<USHORT>
classValue; /* Array of Class Values--one per GlyphID */ classValue; /* Array of Class Values--one per GlyphID */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, USHORT);
}; };
struct ClassRangeRecord struct ClassRangeRecord
@ -527,7 +527,7 @@ struct ClassDefFormat2
rangeRecord; /* Array of glyph ranges--ordered by rangeRecord; /* Array of glyph ranges--ordered by
* Start GlyphID */ * Start GlyphID */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_VAR (4, ClassRangeRecord);
}; };
struct ClassDef struct ClassDef

View File

@ -80,7 +80,7 @@ struct AttachList
attachPoint; /* Array of AttachPoint tables attachPoint; /* Array of AttachPoint tables
* in Coverage Index order */ * in Coverage Index order */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_VAR (4, OffsetTo<AttachPoint>);
}; };
/* /*
@ -226,7 +226,7 @@ struct LigGlyph
* --from beginning of LigGlyph table * --from beginning of LigGlyph table
* --in increasing coordinate order */ * --in increasing coordinate order */
public: public:
DEFINE_SIZE_STATIC (2); DEFINE_SIZE_VAR (2, OffsetTo<CaretValue>);
}; };
struct LigCaretList struct LigCaretList
@ -262,7 +262,7 @@ struct LigCaretList
ligGlyph; /* Array of LigGlyph tables ligGlyph; /* Array of LigGlyph tables
* in Coverage Index order */ * in Coverage Index order */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_VAR (4, OffsetTo<LigGlyph>);
}; };
@ -282,7 +282,7 @@ struct MarkGlyphSetsFormat1
coverage; /* Array of long offsets to mark set coverage; /* Array of long offsets to mark set
* coverage tables */ * coverage tables */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_VAR (4, LongOffsetTo<Coverage>);
}; };
struct MarkGlyphSets struct MarkGlyphSets

View File

@ -385,7 +385,7 @@ struct MarkRecord
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_STATIC (4);
}; };
struct MarkArray struct MarkArray : ArrayOf<MarkRecord> /* Array of MarkRecords--in Coverage order */
{ {
inline bool apply (hb_apply_context_t *context, inline bool apply (hb_apply_context_t *context,
unsigned int mark_index, unsigned int glyph_index, unsigned int mark_index, unsigned int glyph_index,
@ -393,7 +393,7 @@ struct MarkArray
unsigned int glyph_pos) const unsigned int glyph_pos) const
{ {
TRACE_APPLY (); TRACE_APPLY ();
const MarkRecord &record = markRecord[mark_index]; const MarkRecord &record = ArrayOf<MarkRecord>::operator[](mark_index);
unsigned int mark_class = record.klass; unsigned int mark_class = record.klass;
const Anchor& mark_anchor = this + record.markAnchor; const Anchor& mark_anchor = this + record.markAnchor;
@ -417,14 +417,8 @@ struct MarkArray
inline bool sanitize (hb_sanitize_context_t *context) { inline bool sanitize (hb_sanitize_context_t *context) {
TRACE_SANITIZE (); TRACE_SANITIZE ();
return markRecord.sanitize (context, this); return ArrayOf<MarkRecord>::sanitize (context, this);
} }
private:
ArrayOf<MarkRecord>
markRecord; /* Array of MarkRecords--in Coverage order */
public:
DEFINE_SIZE_STATIC (2);
}; };
@ -673,7 +667,7 @@ struct PairPosFormat1
pairSet; /* Array of PairSet tables pairSet; /* Array of PairSet tables
* ordered by Coverage Index */ * ordered by Coverage Index */
public: public:
DEFINE_SIZE_STATIC (10); DEFINE_SIZE_VAR (10, OffsetTo<PairSet>);
}; };
struct PairPosFormat2 struct PairPosFormat2
@ -1019,7 +1013,7 @@ struct CursivePosFormat1
entryExitRecord; /* Array of EntryExit records--in entryExitRecord; /* Array of EntryExit records--in
* Coverage Index order */ * Coverage Index order */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, EntryExitRecord);
}; };
struct CursivePos struct CursivePos

View File

@ -117,7 +117,7 @@ struct SingleSubstFormat2
substitute; /* Array of substitute substitute; /* Array of substitute
* GlyphIDs--ordered by Coverage Index */ * GlyphIDs--ordered by Coverage Index */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, GlyphID);
}; };
struct SingleSubst struct SingleSubst
@ -195,7 +195,7 @@ struct Sequence
ArrayOf<GlyphID> ArrayOf<GlyphID>
substitute; /* String of GlyphIDs to substitute */ substitute; /* String of GlyphIDs to substitute */
public: public:
DEFINE_SIZE_STATIC (2); DEFINE_SIZE_VAR (2, GlyphID);
}; };
struct MultipleSubstFormat1 struct MultipleSubstFormat1
@ -230,7 +230,7 @@ struct MultipleSubstFormat1
sequence; /* Array of Sequence tables sequence; /* Array of Sequence tables
* ordered by Coverage Index */ * ordered by Coverage Index */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, OffsetTo<Sequence>);
}; };
struct MultipleSubst struct MultipleSubst
@ -326,7 +326,7 @@ struct AlternateSubstFormat1
alternateSet; /* Array of AlternateSet tables alternateSet; /* Array of AlternateSet tables
* ordered by Coverage Index */ * ordered by Coverage Index */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, OffsetTo<AlternateSet>);
}; };
struct AlternateSubst struct AlternateSubst
@ -476,7 +476,7 @@ struct LigatureSet
ligature; /* Array LigatureSet tables ligature; /* Array LigatureSet tables
* ordered by preference */ * ordered by preference */
public: public:
DEFINE_SIZE_STATIC (2); DEFINE_SIZE_VAR (2, OffsetTo<Ligature>);
}; };
struct LigatureSubstFormat1 struct LigatureSubstFormat1
@ -514,7 +514,7 @@ struct LigatureSubstFormat1
ligatureSet; /* Array LigatureSet tables ligatureSet; /* Array LigatureSet tables
* ordered by Coverage Index */ * ordered by Coverage Index */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, OffsetTo<LigatureSet>);
}; };
struct LigatureSubst struct LigatureSubst
@ -660,7 +660,7 @@ struct ReverseChainSingleSubstFormat1
substituteX; /* Array of substitute substituteX; /* Array of substitute
* GlyphIDs--ordered by Coverage Index */ * GlyphIDs--ordered by Coverage Index */
public: public:
DEFINE_SIZE_STATIC (10); DEFINE_SIZE_MIN (10);
}; };
struct ReverseChainSingleSubst struct ReverseChainSingleSubst

View File

@ -368,7 +368,7 @@ struct ContextFormat1
ruleSet; /* Array of RuleSet tables ruleSet; /* Array of RuleSet tables
* ordered by Coverage Index */ * ordered by Coverage Index */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, OffsetTo<RuleSet>);
}; };
@ -416,7 +416,7 @@ struct ContextFormat2
ruleSet; /* Array of RuleSet tables ruleSet; /* Array of RuleSet tables
* ordered by class */ * ordered by class */
public: public:
DEFINE_SIZE_STATIC (8); DEFINE_SIZE_VAR (8, OffsetTo<RuleSet>);
}; };
@ -593,7 +593,7 @@ struct ChainRule
lookupX; /* Array of LookupRecords--in lookupX; /* Array of LookupRecords--in
* design order) */ * design order) */
public: public:
DEFINE_SIZE_STATIC (8); DEFINE_SIZE_MIN (8);
}; };
struct ChainRuleSet struct ChainRuleSet
@ -621,7 +621,7 @@ struct ChainRuleSet
rule; /* Array of ChainRule tables rule; /* Array of ChainRule tables
* ordered by preference */ * ordered by preference */
public: public:
DEFINE_SIZE_STATIC (2); DEFINE_SIZE_VAR (2, OffsetTo<ChainRule>);
}; };
struct ChainContextFormat1 struct ChainContextFormat1
@ -659,7 +659,7 @@ struct ChainContextFormat1
ruleSet; /* Array of ChainRuleSet tables ruleSet; /* Array of ChainRuleSet tables
* ordered by Coverage Index */ * ordered by Coverage Index */
public: public:
DEFINE_SIZE_STATIC (6); DEFINE_SIZE_VAR (6, OffsetTo<ChainRuleSet>);
}; };
struct ChainContextFormat2 struct ChainContextFormat2
@ -722,7 +722,7 @@ struct ChainContextFormat2
ruleSet; /* Array of ChainRuleSet tables ruleSet; /* Array of ChainRuleSet tables
* ordered by class */ * ordered by class */
public: public:
DEFINE_SIZE_STATIC (12); DEFINE_SIZE_VAR (12, OffsetTo<ChainRuleSet>);
}; };
struct ChainContextFormat3 struct ChainContextFormat3
@ -784,7 +784,7 @@ struct ChainContextFormat3
lookupX; /* Array of LookupRecords--in lookupX; /* Array of LookupRecords--in
* design order) */ * design order) */
public: public:
DEFINE_SIZE_STATIC (10); DEFINE_SIZE_MIN (10);
}; };
struct ChainContext struct ChainContext