Implement uniform map interface
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 9 Jan 2019 16:39:25 +0000 (08:39 -0800)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 21 Jan 2019 01:12:12 +0000 (20:12 -0500)
Coverage, ClassDef, hb_set_t, and hb_map_t implement.

src/hb-map.hh
src/hb-ot-layout-common.hh
src/hb-set.hh

index 02d5406..a825de4 100644 (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));
index 0a33449..2c9728a 100644 (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) {
index c452a59..c3c981b 100644 (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;