Implement uniform map interface

Coverage, ClassDef, hb_set_t, and hb_map_t implement.
This commit is contained in:
Behdad Esfahbod 2019-01-09 08:39:25 -08:00
parent 7987095e64
commit a7de144df3
3 changed files with 31 additions and 13 deletions

View File

@ -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));

View File

@ -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) {

View File

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