diff --git a/src/hb-map.hh b/src/hb-map.hh index 02d540667..a825de4ab 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -160,14 +160,15 @@ struct hb_map_t void del (hb_codepoint_t key) { set (key, INVALID); } - bool has (hb_codepoint_t key) const - { return get (key) != INVALID; } - - hb_codepoint_t operator [] (unsigned int key) const - { return get (key); } - static constexpr hb_codepoint_t INVALID = HB_MAP_VALUE_INVALID; + /* Map interface. */ + enum { SENTINEL = INVALID }; + typedef hb_codepoint_t value_t; + value_t operator [] (hb_codepoint_t k) const { return get (k); } + bool has (hb_codepoint_t k) const { return (*this)[k] != SENTINEL; } + bool operator () (hb_codepoint_t k) const { return has (k); } + void clear () { memset (items, 0xFF, ((size_t) mask + 1) * sizeof (item_t)); diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 0a33449fb..2c9728a51 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1037,9 +1037,14 @@ struct CoverageFormat2 struct Coverage { + /* Map interface. */ enum { SENTINEL = NOT_COVERED }; - unsigned int operator[] (hb_codepoint_t glyph_id) { return get_coverage (glyph_id); } + typedef unsigned int value_t; + value_t operator [] (hb_codepoint_t k) const { return get (k); } + bool has (hb_codepoint_t k) const { return (*this)[k] != SENTINEL; } + bool operator () (hb_codepoint_t k) const { return has (k); } + unsigned int get (hb_codepoint_t k) const { return get_coverage (k); } unsigned int get_coverage (hb_codepoint_t glyph_id) const { switch (u.format) { @@ -1486,9 +1491,14 @@ struct ClassDefFormat2 struct ClassDef { + /* Map interface. */ enum { SENTINEL = 0 }; - unsigned int operator[] (hb_codepoint_t glyph_id) { return get_class (glyph_id); } + typedef unsigned int value_t; + value_t operator [] (hb_codepoint_t k) const { return get (k); } + bool has (hb_codepoint_t k) const { return (*this)[k] != SENTINEL; } + bool operator () (hb_codepoint_t k) const { return has (k); } + unsigned int get (hb_codepoint_t k) const { return get_class (k); } unsigned int get_class (hb_codepoint_t glyph_id) const { switch (u.format) { diff --git a/src/hb-set.hh b/src/hb-set.hh index c452a5963..c3c981bb2 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -69,7 +69,7 @@ struct hb_set_t void add (hb_codepoint_t g) { elt (g) |= mask (g); } void del (hb_codepoint_t g) { elt (g) &= ~mask (g); } - bool has (hb_codepoint_t g) const { return !!(elt (g) & mask (g)); } + bool get (hb_codepoint_t g) const { return elt (g) & mask (g); } void add_range (hb_codepoint_t a, hb_codepoint_t b) { @@ -357,15 +357,22 @@ struct hb_set_t for (unsigned int i = a; i < b + 1; i++) del (i); } - bool has (hb_codepoint_t g) const + bool get (hb_codepoint_t g) const { const page_t *page = page_for (g); if (!page) return false; - return page->has (g); + return page->get (g); } - bool intersects (hb_codepoint_t first, - hb_codepoint_t last) const + + /* Map interface. */ + enum { SENTINEL = false }; + typedef bool value_t; + value_t operator [] (hb_codepoint_t k) const { return get (k); } + bool has (hb_codepoint_t k) const { return (*this)[k] != SENTINEL; } + bool operator () (hb_codepoint_t k) const { return has (k); } + + bool intersects (hb_codepoint_t first, hb_codepoint_t last) const { hb_codepoint_t c = first - 1; return next (&c) && c <= last;