* 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
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
{
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
{
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;
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;
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(),
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);
}
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(),
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);
}
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)}
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);
}