From aa7044de0ceacd71cab19212d266c3a66c03b41e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 4 Nov 2015 16:25:57 -0800 Subject: [PATCH] Generalize flags types --- src/hb-buffer-private.hh | 3 +++ src/hb-ot-layout-common-private.hh | 5 +++++ src/hb-ot-layout-private.hh | 8 +++++--- src/hb-ot-map-private.hh | 16 +--------------- src/hb-ot-shape.cc | 2 +- src/hb-private.hh | 14 ++++++++++++++ 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 521214d..8e33fc8 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -38,6 +38,9 @@ ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); +template <> class hb_mark_as_flags_t {}; +template <> class hb_mark_as_flags_t {}; + /* * hb_buffer_t diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 84a1635..04958a8 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -579,6 +579,11 @@ struct LookupFlag : USHORT DEFINE_SIZE_STATIC (2); }; +} /* namespace OT */ +/* This has to be outside the namespace. */ +template <> class hb_mark_as_flags_t {}; +namespace OT { + struct Lookup { inline unsigned int get_subtable_count (void) const { return subTable.len; } diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index 1759520..242d5cc 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -49,7 +49,7 @@ hb_ot_layout_table_find_feature (hb_face_t *face, * GDEF */ -typedef enum +enum hb_ot_layout_glyph_props_flags_t { /* The following three match LookupFlags::Ignore* numbers. */ HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x02u, @@ -64,7 +64,8 @@ typedef enum HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE = HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED | HB_OT_LAYOUT_GLYPH_PROPS_LIGATED | HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED -} hb_ot_layout_glyph_class_mask_t; +}; +template <> class hb_mark_as_flags_t {}; /* @@ -230,12 +231,13 @@ _next_syllable (hb_buffer_t *buffer, unsigned int start) * freeing two more bits. */ -enum { +enum hb_unicode_props_flags_t { UPROPS_MASK_ZWJ = 0x20u, UPROPS_MASK_ZWNJ = 0x40u, UPROPS_MASK_IGNORABLE = 0x80u, UPROPS_MASK_GEN_CAT = 0x1Fu }; +template <> class hb_mark_as_flags_t {}; static inline void _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode) diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh index f9538af..1e3ff67 100644 --- a/src/hb-ot-map-private.hh +++ b/src/hb-ot-map-private.hh @@ -159,23 +159,9 @@ enum hb_ot_map_feature_flags_t { F_MANUAL_ZWJ = 0x0004u, /* Don't skip over ZWJ when matching. */ F_GLOBAL_SEARCH = 0x0008u /* If feature not found in LangSys, look for it in global feature list and pick one. */ }; +template <> class hb_mark_as_flags_t {}; /* Macro version for where const is desired. */ #define F_COMBINE(l,r) (hb_ot_map_feature_flags_t ((unsigned int) (l) | (unsigned int) (r))) -static inline hb_ot_map_feature_flags_t -operator | (hb_ot_map_feature_flags_t l, hb_ot_map_feature_flags_t r) -{ return hb_ot_map_feature_flags_t ((unsigned int) l | (unsigned int) r); } -static inline hb_ot_map_feature_flags_t -operator & (hb_ot_map_feature_flags_t l, hb_ot_map_feature_flags_t r) -{ return hb_ot_map_feature_flags_t ((unsigned int) l & (unsigned int) r); } -static inline hb_ot_map_feature_flags_t -operator ~ (hb_ot_map_feature_flags_t r) -{ return hb_ot_map_feature_flags_t (~(unsigned int) r); } -static inline hb_ot_map_feature_flags_t& -operator |= (hb_ot_map_feature_flags_t &l, hb_ot_map_feature_flags_t r) -{ l = l | r; return l; } -static inline hb_ot_map_feature_flags_t& -operator &= (hb_ot_map_feature_flags_t& l, hb_ot_map_feature_flags_t r) -{ l = l & r; return l; } struct hb_ot_map_builder_t diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 40332d6..205be0a 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -525,7 +525,7 @@ hb_synthesize_glyph_classes (hb_ot_shape_context_t *c) hb_glyph_info_t *info = c->buffer->info; for (unsigned int i = 0; i < count; i++) { - hb_ot_layout_glyph_class_mask_t klass; + hb_ot_layout_glyph_props_flags_t klass; /* Never mark default-ignorables as marks. * They won't get in the way of lookups anyway, diff --git a/src/hb-private.hh b/src/hb-private.hh index 53e0510..c65a8bf 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -891,6 +891,20 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) } +/* Enable bitwise ops on enums marked as flags_t */ +template class hb_mark_as_flags_t; +template static inline T operator | (T l, T r) +{ hb_mark_as_flags_t unused HB_UNUSED; return T ((unsigned int) l | (unsigned int) r); } +template static inline T operator & (T l, T r) +{ hb_mark_as_flags_t unused HB_UNUSED; return T ((unsigned int) l & (unsigned int) r); } +template static inline T operator ~ (T r) +{ hb_mark_as_flags_t unused HB_UNUSED; return T (~(unsigned int) r); } +template static inline T& operator |= (T &l, T r) +{ hb_mark_as_flags_t unused HB_UNUSED; l = l | r; return l; } +template static inline T& operator &= (T& l, T r) +{ hb_mark_as_flags_t unused HB_UNUSED; l = l & r; return l; } + + /* Useful for set-operations on small enums. * For example, for testing "x ∈ {x1, x2, x3}" use: * (FLAG_SAFE(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) -- 2.7.4