Convert NEXT() and ARRAY_AFTER() macros to templates
This commit is contained in:
parent
198facdc55
commit
e961c86c57
|
@ -39,19 +39,37 @@
|
|||
* Casts
|
||||
*/
|
||||
|
||||
template <typename Type> const char * ConstCharP (const Type X) { return reinterpret_cast<const char *>(X); }
|
||||
template <typename Type> char * CharP (Type X) { return reinterpret_cast<char *>(X); }
|
||||
template <typename Type> char * DeConstCharP (const Type X) { return (char *) reinterpret_cast<const char *>(X); }
|
||||
template <typename Type> inline const char * ConstCharP (const Type X) { return reinterpret_cast<const char *>(X); }
|
||||
template <typename Type> inline char * CharP (Type X) { return reinterpret_cast<char *>(X); }
|
||||
template <typename Type> inline char * DeConstCharP (const Type X) { return (char *) reinterpret_cast<const char *>(X); }
|
||||
|
||||
#define CONST_CAST(T,X,Ofs) (*(reinterpret_cast<const T *>(ConstCharP(&(X)) + Ofs)))
|
||||
#define DECONST_CAST(T,X,Ofs) (*(reinterpret_cast<T *>((char *)ConstCharP(&(X)) + Ofs)))
|
||||
#define CAST(T,X,Ofs) (*(reinterpret_cast<T *>(CharP(&(X)) + Ofs)))
|
||||
|
||||
#define CONST_NEXT(T,X) (*(reinterpret_cast<const T *>(ConstCharP(&(X)) + (X).get_size ())))
|
||||
#define NEXT(T,X) (*(reinterpret_cast<T *>(CharP(&(X)) + (X).get_size ())))
|
||||
|
||||
#define CONST_ARRAY_AFTER(T,X) ((reinterpret_cast<const T *>(ConstCharP(&(X)) + X.get_size ())))
|
||||
#define ARRAY_AFTER(T,X) ((reinterpret_cast<T *>(CharP(&(X)) + X.get_size ())))
|
||||
template<typename Type, typename TObject>
|
||||
inline const Type& StructAfter(const TObject &X)
|
||||
{
|
||||
return * reinterpret_cast<const Type*> (ConstCharP (&X) + X.get_size());
|
||||
}
|
||||
template<typename Type, typename TObject>
|
||||
inline Type& StructAfter(TObject &X)
|
||||
{
|
||||
return * reinterpret_cast<Type*> (CharP (&X) + X.get_size());
|
||||
}
|
||||
|
||||
template<typename Type, typename TObject>
|
||||
inline const Type* ArrayAfter(const TObject &X)
|
||||
{
|
||||
return reinterpret_cast<const Type*> (ConstCharP (&X) + X.get_size());
|
||||
}
|
||||
template<typename Type, typename TObject>
|
||||
inline Type* ArrayAfter(TObject &X)
|
||||
{
|
||||
return reinterpret_cast<Type*> (CharP (&X) + X.get_size());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class features
|
||||
|
@ -504,8 +522,8 @@ struct LongOffsetTo : GenericOffsetTo<LongOffset, Type> {};
|
|||
template <typename LenType, typename Type>
|
||||
struct GenericArrayOf
|
||||
{
|
||||
const Type *const_array(void) const { return CONST_ARRAY_AFTER (Type, len); }
|
||||
Type *array(void) { return ARRAY_AFTER (Type, len); }
|
||||
const Type *const_array(void) const { return ArrayAfter<Type> (len); }
|
||||
Type *array(void) { return ArrayAfter<Type> (len); }
|
||||
|
||||
const Type *const_sub_array (unsigned int start_offset, unsigned int *pcount /* IN/OUT */) const
|
||||
{
|
||||
|
@ -622,8 +640,8 @@ struct OffsetListOf : OffsetArrayOf<Type>
|
|||
template <typename Type>
|
||||
struct HeadlessArrayOf
|
||||
{
|
||||
const Type *const_array(void) const { return CONST_ARRAY_AFTER (Type, len); }
|
||||
Type *array(void) { return ARRAY_AFTER (Type, len); }
|
||||
const Type *const_array(void) const { return ArrayAfter<Type> (len); }
|
||||
Type *array(void) { return ArrayAfter<Type> (len); }
|
||||
|
||||
inline const Type& operator [] (unsigned int i) const
|
||||
{
|
||||
|
|
|
@ -287,7 +287,7 @@ struct Lookup
|
|||
unsigned int flag = lookupFlag;
|
||||
if (HB_UNLIKELY (flag & LookupFlag::UseMarkFilteringSet))
|
||||
{
|
||||
const USHORT &markFilteringSet = CONST_NEXT (USHORT, subTable);
|
||||
const USHORT &markFilteringSet = StructAfter<USHORT> (subTable);
|
||||
flag += (markFilteringSet << 16);
|
||||
}
|
||||
return flag;
|
||||
|
@ -298,7 +298,7 @@ struct Lookup
|
|||
if (!(SANITIZE (lookupType) && SANITIZE (lookupFlag) && SANITIZE_THIS (subTable))) return false;
|
||||
if (HB_UNLIKELY (lookupFlag & LookupFlag::UseMarkFilteringSet))
|
||||
{
|
||||
USHORT &markFilteringSet = NEXT (USHORT, subTable);
|
||||
USHORT &markFilteringSet = StructAfter<USHORT> (subTable);
|
||||
if (!SANITIZE (markFilteringSet)) return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -586,8 +586,8 @@ struct ReverseChainSingleSubstFormat1
|
|||
if (HB_LIKELY (index == NOT_COVERED))
|
||||
return false;
|
||||
|
||||
const OffsetArrayOf<Coverage> &lookahead = CONST_NEXT (OffsetArrayOf<Coverage>, backtrack);
|
||||
const ArrayOf<GlyphID> &substitute = CONST_NEXT (ArrayOf<GlyphID>, lookahead);
|
||||
const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
|
||||
const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
|
||||
|
||||
if (match_backtrack (APPLY_ARG,
|
||||
backtrack.len, (USHORT *) backtrack.const_array(),
|
||||
|
@ -609,10 +609,10 @@ struct ReverseChainSingleSubstFormat1
|
|||
TRACE_SANITIZE ();
|
||||
if (!SANITIZE_THIS2 (coverage, backtrack))
|
||||
return false;
|
||||
OffsetArrayOf<Coverage> &lookahead = NEXT (OffsetArrayOf<Coverage>, backtrack);
|
||||
OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
|
||||
if (!SANITIZE_THIS (lookahead))
|
||||
return false;
|
||||
ArrayOf<GlyphID> &substitute = NEXT (ArrayOf<GlyphID>, lookahead);
|
||||
ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
|
||||
return SANITIZE (substitute);
|
||||
}
|
||||
|
||||
|
|
|
@ -569,9 +569,9 @@ struct ChainRule
|
|||
inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &lookup_context) const
|
||||
{
|
||||
TRACE_APPLY ();
|
||||
const HeadlessArrayOf<USHORT> &input = CONST_NEXT (HeadlessArrayOf<USHORT>, backtrack);
|
||||
const ArrayOf<USHORT> &lookahead = CONST_NEXT (ArrayOf<USHORT>, input);
|
||||
const ArrayOf<LookupRecord> &lookup = CONST_NEXT (ArrayOf<LookupRecord>, lookahead);
|
||||
const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
|
||||
const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
|
||||
const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
|
||||
return chain_context_lookup (APPLY_ARG,
|
||||
backtrack.len, backtrack.const_array(),
|
||||
input.len, input.const_array(),
|
||||
|
@ -585,11 +585,11 @@ struct ChainRule
|
|||
inline bool sanitize (SANITIZE_ARG_DEF) {
|
||||
TRACE_SANITIZE ();
|
||||
if (!SANITIZE (backtrack)) return false;
|
||||
HeadlessArrayOf<USHORT> &input = NEXT (HeadlessArrayOf<USHORT>, backtrack);
|
||||
HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
|
||||
if (!SANITIZE (input)) return false;
|
||||
ArrayOf<USHORT> &lookahead = NEXT (ArrayOf<USHORT>, input);
|
||||
ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
|
||||
if (!SANITIZE (lookahead)) return false;
|
||||
ArrayOf<LookupRecord> &lookup = NEXT (ArrayOf<LookupRecord>, lookahead);
|
||||
ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
|
||||
return SANITIZE (lookup);
|
||||
}
|
||||
|
||||
|
@ -742,14 +742,14 @@ struct ChainContextFormat3
|
|||
inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
|
||||
{
|
||||
TRACE_APPLY ();
|
||||
const OffsetArrayOf<Coverage> &input = CONST_NEXT (OffsetArrayOf<Coverage>, backtrack);
|
||||
const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
|
||||
|
||||
unsigned int index = (this+input[0]) (IN_CURGLYPH ());
|
||||
if (HB_LIKELY (index == NOT_COVERED))
|
||||
return false;
|
||||
|
||||
const OffsetArrayOf<Coverage> &lookahead = CONST_NEXT (OffsetArrayOf<Coverage>, input);
|
||||
const ArrayOf<LookupRecord> &lookup = CONST_NEXT (ArrayOf<LookupRecord>, lookahead);
|
||||
const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
|
||||
const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
|
||||
struct ChainContextLookupContext lookup_context = {
|
||||
{match_coverage, apply_func},
|
||||
{ConstCharP(this), ConstCharP(this), ConstCharP(this)}
|
||||
|
@ -766,11 +766,11 @@ struct ChainContextFormat3
|
|||
inline bool sanitize (SANITIZE_ARG_DEF) {
|
||||
TRACE_SANITIZE ();
|
||||
if (!SANITIZE_THIS (backtrack)) return false;
|
||||
OffsetArrayOf<Coverage> &input = NEXT (OffsetArrayOf<Coverage>, backtrack);
|
||||
OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
|
||||
if (!SANITIZE_THIS (input)) return false;
|
||||
OffsetArrayOf<Coverage> &lookahead = NEXT (OffsetArrayOf<Coverage>, input);
|
||||
OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
|
||||
if (!SANITIZE_THIS (lookahead)) return false;
|
||||
ArrayOf<LookupRecord> &lookup = NEXT (ArrayOf<LookupRecord>, lookahead);
|
||||
ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
|
||||
return SANITIZE (lookup);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue