Generalize flags types

This commit is contained in:
Behdad Esfahbod 2015-11-04 16:25:57 -08:00
parent 7793aad946
commit aa7044de0c
6 changed files with 29 additions and 19 deletions

View File

@ -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<hb_buffer_flags_t> {};
template <> class hb_mark_as_flags_t<hb_buffer_serialize_flags_t> {};
/*
* hb_buffer_t

View File

@ -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<OT::LookupFlag::Flags> {};
namespace OT {
struct Lookup
{
inline unsigned int get_subtable_count (void) const { return subTable.len; }

View File

@ -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<hb_ot_layout_glyph_props_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<hb_unicode_props_flags_t> {};
static inline void
_hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode)

View File

@ -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<hb_ot_map_feature_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

View File

@ -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,

View File

@ -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 T> class hb_mark_as_flags_t;
template <class T> static inline T operator | (T l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; return T ((unsigned int) l | (unsigned int) r); }
template <class T> static inline T operator & (T l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; return T ((unsigned int) l & (unsigned int) r); }
template <class T> static inline T operator ~ (T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; return T (~(unsigned int) r); }
template <class T> static inline T& operator |= (T &l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; l = l | r; return l; }
template <class T> static inline T& operator &= (T& l, T r)
{ hb_mark_as_flags_t<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)))